Sha256: 23c6239cbeef2416d1adefa427e417fe10fb486fdf0a738bbdb7feb181d6fe5c

Contents?: true

Size: 1.3 KB

Versions: 24

Compression:

Stored size: 1.3 KB

Contents

require_relative '../tracing/distributed/datadog'
require_relative '../tracing/utils'

module Datadog
  module OpenTracer
    # DistributedHeaders provides easy access and validation to headers
    # @public_api
    class DistributedHeaders
      def initialize(carrier)
        @carrier = carrier
      end

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

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

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

      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

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

      private

      def id(header)
        value = @carrier[header].to_i
        return if value.zero? || value >= Datadog::Tracing::Utils::EXTERNAL_MAX_ID

        value < 0 ? value + 0x1_0000_0000_0000_0000 : value
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ddtrace-1.23.3 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.23.2 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.23.1 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.22.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.21.1 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.21.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.20.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.19.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.18.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.17.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.16.2 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.16.1 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.16.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.15.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.14.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.13.1 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.13.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.12.1 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.12.0 lib/datadog/opentracer/distributed_headers.rb
ddtrace-1.11.1 lib/datadog/opentracer/distributed_headers.rb