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

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

Instance Method Summary collapse

Instance Method Details

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



40
41
42
# File 'lib/traces/backend/datadog/interface.rb', line 40

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

#trace_context(span = ::Datadog.tracer.active_span) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/traces/backend/datadog/interface.rb', line 55

def trace_context(span = ::Datadog.tracer.active_span)
  return nil unless span
  
  flags = 0
  
  if span.sampled
    flags |= Context::SAMPLED
  end
  
  return Context.new(
    span.trace_id,
    span.span_id,
    flags,
    nil,
    remote: false,
  )
end

#trace_context=(context) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/traces/backend/datadog/interface.rb', line 44

def trace_context=(context)
  if context
    ::Datadog.tracer.provider.context = ::Datadog::Context.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,
      sampled: context.sampled?,
    )
  end
end