Class: Datadog::Tracing::Transport::SerializableTrace

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

Overview

Adds serialization functions to a Datadog::TraceSegment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace, native_events_supported = false) ⇒ SerializableTrace

Returns a new instance of SerializableTrace.

Parameters:

  • trace (Datadog::Trace)

    the trace to serialize

  • native_events_supported (Boolean) (defaults to: false)

    whether the agent supports span events as a top-level field



17
18
19
20
# File 'lib/datadog/tracing/transport/serializable_trace.rb', line 17

def initialize(trace, native_events_supported = false)
  @trace = trace
  @native_events_supported = native_events_supported
end

Instance Attribute Details

#traceObject (readonly)

Returns the value of attribute trace.



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

def trace
  @trace
end

Instance Method Details

#to_json(*args) ⇒ Object

JSON serializer interface. Used by older version of the transport.



37
38
39
# File 'lib/datadog/tracing/transport/serializable_trace.rb', line 37

def to_json(*args)
  trace.spans.map { |s| SerializableSpan.new(s, @native_events_supported).to_hash }.to_json(*args)
end

#to_msgpack(packer = nil) ⇒ Object

MessagePack serializer interface. Making this object respond to ‘#to_msgpack` allows it to be automatically serialized by MessagePack.

This is more efficient than doing MessagePack.pack(span.to_hash) as we don’t have to create an intermediate Hash.

Parameters:

  • packer (MessagePack::Packer) (defaults to: nil)

    serialization buffer, can be nil with JRuby



30
31
32
33
# File 'lib/datadog/tracing/transport/serializable_trace.rb', line 30

def to_msgpack(packer = nil)
  # As of 1.3.3, JRuby implementation doesn't pass an existing packer
  trace.spans.map { |s| SerializableSpan.new(s, @native_events_supported) }.to_msgpack(packer)
end