Module: Traces::Backend::Datadog::Interface

Defined in:
lib/traces/backend/datadog/interface.rb

Instance Method Summary collapse

Instance Method Details

#active?Boolean



50
51
52
# File 'lib/traces/backend/datadog/interface.rb', line 50

def active?
  !!::Datadog::Tracing.active_trace
end

#trace(name, attributes: {}, &block) ⇒ Object



15
16
17
# File 'lib/traces/backend/datadog/interface.rb', line 15

def trace(name, attributes: {}, &block)
  ::Datadog::Tracing.trace(name, tags: attributes, &block)
end

#trace_contextObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/traces/backend/datadog/interface.rb', line 32

def trace_context
  return nil unless trace = ::Datadog::Tracing.active_trace
  
  flags = 0
  
  if trace.sampled?
    flags |= Context::SAMPLED
  end
  
  return Context.new(
    trace.id,
    trace.active_span.id,
    flags,
    nil,
    remote: false,
  )
end

#trace_context=(context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/traces/backend/datadog/interface.rb', line 19

def trace_context=(context)
  if context
    trace_digest = ::Datadog::Tracing::TraceDigest.new(
      # We force these to be integers otherwise Datadog can fail internally:
      trace_id: context.trace_id.to_i,
      span_id: context.parent_id.to_i,
      trace_sampling_priority: context.sampled? ? 1 : 0,
    )
    
    ::Datadog::Tracing.continue_trace!(trace_digest)
  end
end