Class: Chronos::Core::TelemetryEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/chronos/core/telemetry_event.rb

Overview

Immutable framework telemetry event normalized to the Chronos v1 envelope.

Examples:

event = Chronos::Core::TelemetryEvent.new("request", {"duration_ms" => 12.0})

Constant Summary collapse

TYPES =
%w(request query job cache metric_batch).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type, payload = {}, context = {}, options = {}) ⇒ TelemetryEvent

Returns a new instance of TelemetryEvent.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chronos/core/telemetry_event.rb', line 23

def initialize(event_type, payload = {}, context = {}, options = {})
  type = event_type.to_s
  raise ArgumentError, "unsupported telemetry event type" unless TYPES.include?(type)

  clock = options[:clock] || proc { Time.now }
  @event_id = (options[:event_id] || SecureRandom.uuid).to_s.freeze
  @event_type = type.freeze
  @timestamp = clock.call.utc.iso8601(6).freeze
  @context = deep_freeze(context.is_a?(Hash) ? context : {})
  @payload = deep_freeze(payload.is_a?(Hash) ? payload : {})
  freeze
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



21
22
23
# File 'lib/chronos/core/telemetry_event.rb', line 21

def context
  @context
end

#event_idObject (readonly)

Returns the value of attribute event_id.



21
22
23
# File 'lib/chronos/core/telemetry_event.rb', line 21

def event_id
  @event_id
end

#event_typeObject (readonly)

Returns the value of attribute event_type.



21
22
23
# File 'lib/chronos/core/telemetry_event.rb', line 21

def event_type
  @event_type
end

#payloadObject (readonly)

Returns the value of attribute payload.



21
22
23
# File 'lib/chronos/core/telemetry_event.rb', line 21

def payload
  @payload
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



21
22
23
# File 'lib/chronos/core/telemetry_event.rb', line 21

def timestamp
  @timestamp
end