Sha256: 463a0d8f9f66e2ca999aaf44adb678a0025e7f90bf154af426c9a96d36f34ac7

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

# typed: false
require 'ddtrace/ext/correlation'
require 'datadog/core/environment/variable_helpers'

module Datadog
  # Contains behavior for managing correlations with tracing
  # e.g. Retrieve a correlation to the current trace for logging, etc.
  module Correlation
    # Struct representing correlation
    Identifier = Struct.new(:trace_id, :span_id, :env, :service, :version) do
      def initialize(*args)
        super
        self.trace_id = trace_id || 0
        self.span_id = span_id || 0
        self.env = env || Datadog.configuration.env
        self.service = service || Datadog.configuration.service
        self.version = version || Datadog.configuration.version
      end

      def to_s
        attributes = []
        attributes << "#{Ext::Correlation::ATTR_ENV}=#{env}" unless env.nil?
        attributes << "#{Ext::Correlation::ATTR_SERVICE}=#{service}" unless service.nil?
        attributes << "#{Ext::Correlation::ATTR_VERSION}=#{version}" unless version.nil?
        attributes << "#{Ext::Correlation::ATTR_TRACE_ID}=#{trace_id}"
        attributes << "#{Ext::Correlation::ATTR_SPAN_ID}=#{span_id}"
        attributes.join(' ')
      end
    end.freeze

    module_function

    # Produces a CorrelationIdentifier from the Context provided
    def identifier_from_context(context)
      return Identifier.new.freeze if context.nil?

      Identifier.new(context.trace_id, context.span_id).freeze
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/correlation.rb
ddtrace-0.54.1 lib/ddtrace/correlation.rb
ddtrace-0.54.0 lib/ddtrace/correlation.rb
ddtrace-0.53.0 lib/ddtrace/correlation.rb
ddtrace-0.52.0 lib/ddtrace/correlation.rb