Class: Datadog::Profiling::TraceIdentifiers::Ddtrace

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/profiling/trace_identifiers/ddtrace.rb

Overview

Used by Datadog::Profiling::TraceIdentifiers::Helper to get the trace identifiers (root span id and span id) for a given thread, if there is an active trace for that thread in the supplied tracer object.

Instance Method Summary collapse

Constructor Details

#initialize(tracer:) ⇒ Ddtrace



12
13
14
# File 'lib/datadog/profiling/trace_identifiers/ddtrace.rb', line 12

def initialize(tracer:)
  @tracer = (tracer if tracer.respond_to?(:active_trace))
end

Instance Method Details

#trace_identifiers_for(thread) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/datadog/profiling/trace_identifiers/ddtrace.rb', line 16

def trace_identifiers_for(thread)
  return unless @tracer

  trace = @tracer.active_trace(thread)
  return unless trace

  root_span = trace.send(:root_span)
  span = trace.active_span
  return unless span && root_span

  root_span_id = root_span.id || 0
  span_id = span.id || 0

  [root_span_id, span_id, maybe_extract_resource(trace, root_span)] if root_span_id != 0 && span_id != 0
end