Class: Datadog::Tracing::SpanEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/span_event.rb

Overview

Represents a timestamped annotation on a span. It is analogous to structured log message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes: nil, time_unix_nano: nil) ⇒ SpanEvent

Returns a new instance of SpanEvent.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datadog/tracing/span_event.rb', line 22

def initialize(
  name,
  attributes: nil,
  time_unix_nano: nil
)
  @name = name
  @attributes = attributes || {}
  # OpenTelemetry SDK stores span event timestamps in nanoseconds (not seconds).
  # We will do the same here to avoid unnecessary conversions and inconsistencies.
  @time_unix_nano = time_unix_nano || (Time.now.to_r * 1_000_000_000).to_i
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



16
17
18
# File 'lib/datadog/tracing/span_event.rb', line 16

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/datadog/tracing/span_event.rb', line 12

def name
  @name
end

#time_unix_nanoObject (readonly)

Returns the value of attribute time_unix_nano.



20
21
22
# File 'lib/datadog/tracing/span_event.rb', line 20

def time_unix_nano
  @time_unix_nano
end

Instance Method Details

#to_hashObject



34
35
36
37
38
# File 'lib/datadog/tracing/span_event.rb', line 34

def to_hash
  h = { name: @name, time_unix_nano: @time_unix_nano }
  h[:attributes] = attributes unless @attributes.empty?
  h
end