Class: Datadog::Transport::TraceFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/transport/trace_formatter.rb

Overview

Prepares traces for transport

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace) ⇒ TraceFormatter

Returns a new instance of TraceFormatter.



21
22
23
24
# File 'lib/ddtrace/transport/trace_formatter.rb', line 21

def initialize(trace)
  @trace = trace
  @root_span = find_root_span(trace)
end

Instance Attribute Details

#root_spanObject (readonly)

Returns the value of attribute root_span.



13
14
15
# File 'lib/ddtrace/transport/trace_formatter.rb', line 13

def root_span
  @root_span
end

#traceObject (readonly)

Returns the value of attribute trace.



13
14
15
# File 'lib/ddtrace/transport/trace_formatter.rb', line 13

def trace
  @trace
end

Class Method Details

.format!(trace) ⇒ Object



17
18
19
# File 'lib/ddtrace/transport/trace_formatter.rb', line 17

def self.format!(trace)
  new(trace).format!
end

Instance Method Details

#format!Object

Modifies a trace so suitable for transport



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ddtrace/transport/trace_formatter.rb', line 27

def format!
  return unless trace
  return trace unless root_span

  # Because the trace API does not support
  # trace metadata, we must put our trace
  # metadata on the root span. This "root span"
  # is needed by the agent/API to ingest the trace.

  # Apply generic trace tags. Any more specific value will be overridden
  # by the subsequent calls below.
  set_trace_tags!

  set_resource!

  tag_agent_sample_rate!
  tag_hostname!
  tag_lang!
  tag_origin!
  tag_process_id!
  tag_rule_sample_rate!
  tag_runtime_id!
  tag_rate_limiter_rate!
  tag_sample_rate!
  tag_sampling_decision_maker!
  tag_high_order_trace_id!
  tag_sampling_priority!

  trace
end