Class: Datadog::Transport::SerializableTrace

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/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



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

def initialize(trace)
  @trace = trace
end

Instance Attribute Details

#traceObject (readonly)

Returns the value of attribute trace.



9
10
11
# File 'lib/ddtrace/transport/serializable_trace.rb', line 9

def trace
  @trace
end

Instance Method Details

#to_json(*args) ⇒ Object

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



31
32
33
# File 'lib/ddtrace/transport/serializable_trace.rb', line 31

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.



24
25
26
27
# File 'lib/ddtrace/transport/serializable_trace.rb', line 24

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