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

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

Returns a new instance of Ddtrace.



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

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

Instance Method Details

#trace_identifiers_for(thread) ⇒ Object



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

def trace_identifiers_for(thread)
  return unless @tracer

  context = @tracer.call_context(thread)
  return unless context

  span, root_span = context.current_span_and_root_span
  return unless span && root_span

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

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