Class: Datadog::OpenTracer::DistributedHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/opentracer/distributed_headers.rb

Overview

DistributedHeaders provides easy access and validation to headers

Instance Method Summary collapse

Constructor Details

#initialize(carrier) ⇒ DistributedHeaders

Returns a new instance of DistributedHeaders.



11
12
13
# File 'lib/datadog/opentracer/distributed_headers.rb', line 11

def initialize(carrier)
  @carrier = carrier
end

Instance Method Details

#originObject



40
41
42
43
44
# File 'lib/datadog/opentracer/distributed_headers.rb', line 40

def origin
  hdr = @carrier[Tracing::Distributed::Datadog::ORIGIN_KEY]
  # Only return the value if it is not an empty string
  hdr if hdr != ''
end

#parent_idObject



24
25
26
# File 'lib/datadog/opentracer/distributed_headers.rb', line 24

def parent_id
  id Tracing::Distributed::Datadog::PARENT_ID_KEY
end

#sampling_priorityObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datadog/opentracer/distributed_headers.rb', line 28

def sampling_priority
  hdr = @carrier[Tracing::Distributed::Datadog::SAMPLING_PRIORITY_KEY]
  # It's important to make a difference between no header,
  # and a header defined to zero.
  return unless hdr

  value = hdr.to_i
  return if value < 0

  value
end

#trace_idObject



20
21
22
# File 'lib/datadog/opentracer/distributed_headers.rb', line 20

def trace_id
  id Tracing::Distributed::Datadog::TRACE_ID_KEY
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/datadog/opentracer/distributed_headers.rb', line 15

def valid?
  # Sampling priority is optional.
  !trace_id.nil? && !parent_id.nil?
end