Class: Datadog::OpenTracer::DistributedHeaders

Inherits:
Object
  • Object
show all
Includes:
Ext::DistributedTracing
Defined in:
lib/ddtrace/opentracer/distributed_headers.rb

Overview

DistributedHeaders provides easy access and validation to headers

Constant Summary

Constants included from Ext::DistributedTracing

Ext::DistributedTracing::B3_HEADER_SAMPLED, Ext::DistributedTracing::B3_HEADER_SINGLE, Ext::DistributedTracing::B3_HEADER_SPAN_ID, Ext::DistributedTracing::B3_HEADER_TRACE_ID, Ext::DistributedTracing::GRPC_METADATA_ORIGIN, Ext::DistributedTracing::GRPC_METADATA_PARENT_ID, Ext::DistributedTracing::GRPC_METADATA_SAMPLING_PRIORITY, Ext::DistributedTracing::GRPC_METADATA_TRACE_ID, Ext::DistributedTracing::HTTP_HEADER_ORIGIN, Ext::DistributedTracing::HTTP_HEADER_PARENT_ID, Ext::DistributedTracing::HTTP_HEADER_SAMPLING_PRIORITY, Ext::DistributedTracing::HTTP_HEADER_TRACE_ID, Ext::DistributedTracing::ORIGIN_KEY, Ext::DistributedTracing::PROPAGATION_EXTRACT_STYLE_ENV, Ext::DistributedTracing::PROPAGATION_INJECT_STYLE_ENV, Ext::DistributedTracing::PROPAGATION_STYLE_B3, Ext::DistributedTracing::PROPAGATION_STYLE_B3_SINGLE_HEADER, Ext::DistributedTracing::PROPAGATION_STYLE_DATADOG, Ext::DistributedTracing::SAMPLING_PRIORITY_KEY

Instance Method Summary collapse

Constructor Details

#initialize(carrier) ⇒ DistributedHeaders

Returns a new instance of DistributedHeaders.



10
11
12
# File 'lib/ddtrace/opentracer/distributed_headers.rb', line 10

def initialize(carrier)
  @carrier = carrier
end

Instance Method Details

#originObject



37
38
39
40
41
# File 'lib/ddtrace/opentracer/distributed_headers.rb', line 37

def origin
  hdr = @carrier[HTTP_HEADER_ORIGIN]
  # Only return the value if it is not an empty string
  hdr if hdr != ''
end

#parent_idObject



23
24
25
# File 'lib/ddtrace/opentracer/distributed_headers.rb', line 23

def parent_id
  id HTTP_HEADER_PARENT_ID
end

#sampling_priorityObject



27
28
29
30
31
32
33
34
35
# File 'lib/ddtrace/opentracer/distributed_headers.rb', line 27

def sampling_priority
  hdr = @carrier[HTTP_HEADER_SAMPLING_PRIORITY]
  # 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



19
20
21
# File 'lib/ddtrace/opentracer/distributed_headers.rb', line 19

def trace_id
  id HTTP_HEADER_TRACE_ID
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/ddtrace/opentracer/distributed_headers.rb', line 14

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