class Datadog::Tracing::Correlation::Identifier
@public_api
Represents current trace state with key identifiers
def initialize(
def initialize( env: nil, service: nil, span_id: nil, span_name: nil, span_resource: nil, span_service: nil, span_type: nil, trace_id: nil, trace_name: nil, trace_resource: nil, trace_service: nil, version: nil ) # Dup and freeze strings so they aren't modified by reference. @env = Core::Utils::SafeDup.frozen_dup(env || Datadog.configuration.env) @service = Core::Utils::SafeDup.frozen_dup(service || Datadog.configuration.service) @span_id = span_id || 0 @span_name = Core::Utils::SafeDup.frozen_dup(span_name) @span_resource = Core::Utils::SafeDup.frozen_dup(span_resource) @span_service = Core::Utils::SafeDup.frozen_dup(span_service) @span_type = Core::Utils::SafeDup.frozen_dup(span_type) @trace_id = trace_id || 0 @trace_name = Core::Utils::SafeDup.frozen_dup(trace_name) @trace_resource = Core::Utils::SafeDup.frozen_dup(trace_resource) @trace_service = Core::Utils::SafeDup.frozen_dup(trace_service) @version = Core::Utils::SafeDup.frozen_dup(version || Datadog.configuration.version) end
def to_h
def to_h @to_h ||= { # Adds IDs as tags to log output dd: { # To preserve precision during JSON serialization, use strings for large numbers env: env.to_s, service: service.to_s, version: version.to_s, trace_id: trace_id.to_s, span_id: span_id.to_s }, ddsource: Core::Logging::Ext::DD_SOURCE } end
def to_log_format
This method (#to_log_format) implements an algorithm by prefixing keys for nested values
def to_log_format @log_format ||= begin attributes = [] attributes << "#{LOG_ATTR_ENV}=#{env}" unless env.nil? attributes << "#{LOG_ATTR_SERVICE}=#{service}" attributes << "#{LOG_ATTR_VERSION}=#{version}" unless version.nil? attributes << "#{LOG_ATTR_TRACE_ID}=#{trace_id}" attributes << "#{LOG_ATTR_SPAN_ID}=#{span_id}" attributes << "#{LOG_ATTR_SOURCE}=#{Core::Logging::Ext::DD_SOURCE}" attributes.join(' ') end end
def trace_id
def trace_id if Datadog.configuration.tracing.trace_id_128_bit_logging_enabled && !Tracing::Utils::TraceId.to_high_order(@trace_id).zero? Kernel.format('%032x', @trace_id) else Tracing::Utils::TraceId.to_low_order(@trace_id) end end