Sha256: 2d4b609d6bb46d4d2016431c1856626451b4389caa3a4c833020fe1e2f2b3983

Contents?: true

Size: 1.19 KB

Versions: 39

Compression:

Stored size: 1.19 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

      def origin
        hdr = @carrier[HTTP_HEADER_ORIGIN]
        # 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::Span::MAX_ID
        value < 0 ? value + 0x1_0000_0000_0000_0000 : value
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
ls-trace-0.2.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.40.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.39.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.38.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.37.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.36.0 lib/ddtrace/opentracer/distributed_headers.rb
ls-trace-0.1.2 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.35.2 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.35.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.35.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.34.2 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.34.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.34.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.33.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.33.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.32.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.31.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.31.0 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.30.1 lib/ddtrace/opentracer/distributed_headers.rb
ddtrace-0.30.0 lib/ddtrace/opentracer/distributed_headers.rb