Class: Datadog::Tracing::Transport::TraceFormatter

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



25
26
27
28
29
30
31
# File 'lib/datadog/tracing/transport/trace_formatter.rb', line 25

def initialize(trace)
  @trace = trace
  @root_span = find_root_span(trace)
  # source code integration uses the "first span in trace chunk" concept instead of root span
  # see: https://github.com/DataDog/dd-trace-rb/pull/3424
  @first_span = trace.spans.first
end

Instance Attribute Details

#first_spanObject (readonly)

Returns the value of attribute first_span.



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

def first_span
  @first_span
end

#root_spanObject (readonly)

Returns the value of attribute root_span.



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

def root_span
  @root_span
end

#traceObject (readonly)

Returns the value of attribute trace.



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

def trace
  @trace
end

Class Method Details

.format!(trace) ⇒ Object



21
22
23
# File 'lib/datadog/tracing/transport/trace_formatter.rb', line 21

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

Instance Method Details

#format!Object

Modifies a trace so suitable for transport



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/datadog/tracing/transport/trace_formatter.rb', line 34

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!
  tag_profiling_enabled!

  if first_span
    tag_git_repository_url!
    tag_git_commit_sha!
  end

  trace
end