class Observability::Event
Constants
- FORMAT_VERSION
The event format version to send with all events
Attributes
fields[R]
A Symbol-keyed Hash of values that make up the event data
id[R]
The ID of the event, used to pass context through application boundaries
parent_id[R]
The ID of the containing context event, if there is one
start[R]
The monotonic clock time of when the event was created
timestamp[R]
The Time the event was created
type[R]
The type of the event, which should be a string of the form: 'foo.bar.baz'
Public Class Methods
generate_id()
click to toggle source
Generate a new Event
ID.
# File lib/observability/event.rb, line 33 def self::generate_id return self.id_generator.generate end
id_generator()
click to toggle source
Return a generator that can return a unique ID string for identifying Events across application boundaries.
# File lib/observability/event.rb, line 27 def self::id_generator return @id_generator ||= UUID.new end
new( type, parent=nil, **fields )
click to toggle source
Create a new event
# File lib/observability/event.rb, line 39 def initialize( type, parent=nil, **fields ) @id = self.class.generate_id @parent_id = parent&.id @type = type.freeze @timestamp = Time.now @start = Concurrent.monotonic_time @fields = fields end
Public Instance Methods
merge( fields )
click to toggle source
Merge the specified fields
into the event's data. :TODO: Handle conflicts?
# File lib/observability/event.rb, line 85 def merge( fields ) self.fields.merge!( fields ) rescue FrozenError => err raise "event is already resolved", cause: err end
resolve()
click to toggle source
Finalize all of the event's data and return it as a Hash.
# File lib/observability/event.rb, line 93 def resolve unless @fields.frozen? self.log.debug "Resolving event %#x" % [ self.object_id ] data = self.fields.merge( :@id => self.id, :@parent_id => self.parent_id, :@type => self.type, :@timestamp => self.timestamp, :@version => FORMAT_VERSION ) data = data.transform_values( &self.method(:resolve_value) ) @fields = data.freeze end return @fields end
Also aliased as: to_h
resolve_value( value )
click to toggle source
Resolve the given value
into a serializable object.
# File lib/observability/event.rb, line 113 def resolve_value( value ) case when value.respond_to?( :call ) # Procs, Methods return value.call( self ) when value.respond_to?( :iso8601 ) # Time, Date, DateTime, etc. return value.iso8601( 6 ) else return value end end