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) ⇒ SerializableTrace

Returns a new instance of SerializableTrace.



15
16
17
# File 'lib/datadog/tracing/transport/serializable_trace.rb', line 15

def initialize(trace)
  @trace = trace
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.



34
35
36
# File 'lib/datadog/tracing/transport/serializable_trace.rb', line 34

def to_json(*args)
  trace.spans.map { |s| SerializableSpan.new(s).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



27
28
29
30
# File 'lib/datadog/tracing/transport/serializable_trace.rb', line 27

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) }.to_msgpack(packer)
end