Class: Datadog::Tracing::Correlation::Identifier
- Inherits:
-
Object
- Object
- Datadog::Tracing::Correlation::Identifier
- Defined in:
- lib/datadog/tracing/correlation.rb
Overview
Represents current trace state with key identifiers
Constant Summary collapse
- LOG_ATTR_ENV =
'dd.env'.freeze
- LOG_ATTR_SERVICE =
'dd.service'.freeze
- LOG_ATTR_SPAN_ID =
'dd.span_id'.freeze
- LOG_ATTR_TRACE_ID =
'dd.trace_id'.freeze
- LOG_ATTR_VERSION =
'dd.version'.freeze
- LOG_ATTR_SOURCE =
'ddsource'.freeze
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#span_name ⇒ Object
readonly
Returns the value of attribute span_name.
-
#span_resource ⇒ Object
readonly
Returns the value of attribute span_resource.
-
#span_service ⇒ Object
readonly
Returns the value of attribute span_service.
-
#span_type ⇒ Object
readonly
Returns the value of attribute span_type.
-
#trace_name ⇒ Object
readonly
Returns the value of attribute trace_name.
-
#trace_resource ⇒ Object
readonly
Returns the value of attribute trace_resource.
-
#trace_service ⇒ Object
readonly
Returns the value of attribute trace_service.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #to_h ⇒ Object
-
#to_log_format ⇒ Object
This method (#to_log_format) implements an algorithm by prefixing keys for nested values but the algorithm makes the constants implicit.
-
#trace_id ⇒ Object
DEV-2.0: This public method was returning an Integer, but with 128 bit trace id it would return a String.
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def env @env end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def service @service end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def span_id @span_id end |
#span_name ⇒ Object (readonly)
Returns the value of attribute span_name.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def span_name @span_name end |
#span_resource ⇒ Object (readonly)
Returns the value of attribute span_resource.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def span_resource @span_resource end |
#span_service ⇒ Object (readonly)
Returns the value of attribute span_service.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def span_service @span_service end |
#span_type ⇒ Object (readonly)
Returns the value of attribute span_type.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def span_type @span_type end |
#trace_name ⇒ Object (readonly)
Returns the value of attribute trace_name.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def trace_name @trace_name end |
#trace_resource ⇒ Object (readonly)
Returns the value of attribute trace_resource.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def trace_resource @trace_resource end |
#trace_service ⇒ Object (readonly)
Returns the value of attribute trace_service.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def trace_service @trace_service end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
20 21 22 |
# File 'lib/datadog/tracing/correlation.rb', line 20 def version @version end |
Instance Method Details
#to_h ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/datadog/tracing/correlation.rb', line 63 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 |
#to_log_format ⇒ Object
This method (#to_log_format) implements an algorithm by prefixing keys for nested values but the algorithm makes the constants implicit. Hence, we use it for validation during test.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/datadog/tracing/correlation.rb', line 80 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 |
#trace_id ⇒ Object
DEV-2.0: This public method was returning an Integer, but with 128 bit trace id it would return a String.
94 95 96 97 98 99 100 101 |
# File 'lib/datadog/tracing/correlation.rb', line 94 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 |