The event format version to send with all events
A Symbol-keyed Hash of values that make up the event data
The monotonic clock time of when the event was created
The Time the event was created
The type of the event, which should be a string of the form: 'foo.bar.baz'
Create a new event
# File lib/observability/event.rb, line 25
def initialize( type, **fields )
@type = type.freeze
@timestamp = Time.now
@start = Concurrent.monotonic_time
@fields = fields
end
Merge the specified fields
into the event's data. :TODO: Handle conflicts?
# File lib/observability/event.rb, line 61
def merge( fields )
self.fields.merge!( fields )
rescue FrozenError => err
raise "event is already resolved", cause: err
end
Finalize all of the event's data and return it as a Hash.
# File lib/observability/event.rb, line 69
def resolve
unless @fields.frozen?
self.log.debug "Resolving event %#x" % [ self.object_id ]
data = self.fields.merge(
:@type => self.type,
:@timestamp => self.timestamp,
:@version => FORMAT_VERSION
)
data = data.transform_values( &self.method(:resolve_value) )
@fields = data.freeze
end
return @fields
end
Resolve the given value
into a serializable object.
# File lib/observability/event.rb, line 87
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