Sha256: 9433b0f6093e264e9c7ea743e994d016610dacb7263274b5ccbccfd4ec148e3f

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

require 'ddtrace/span'
require 'ddtrace/ext/distributed'

module Datadog
  module OpenTracer
    # DistributedHeaders provides easy access and validation to headers
    class DistributedHeaders
      include Datadog::Ext::DistributedTracing

      def initialize(carrier)
        @carrier = carrier
      end

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

      def trace_id
        id HTTP_HEADER_TRACE_ID
      end

      def parent_id
        id HTTP_HEADER_PARENT_ID
      end

      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

      private

      def id(header)
        value = @carrier[header].to_i
        return if value.zero? || value >= Datadog::Span::MAX_ID
        value < 0 ? value + 0x1_0000_0000_0000_0000 : value
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ddtrace-0.19.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.19.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.18.3 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.18.2 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.18.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.18.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.17.3 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.17.2 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.17.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.17.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.16.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.16.0 lib/ddtrace/opentracer/distributed_headers.rb