Event

class
Superclass
Object

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

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

anchor
new( type, **fields )

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

Public Instance Methods

anchor
merge( fields )

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
anchor
resolve()

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
Also aliased as: to_h
anchor
resolve_value( value )

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
anchor
to_h()
Alias for: resolve