Class: Datadog::Tracing::Correlation::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/correlation.rb

Overview

Represents current trace state with key identifiers

Constant Summary collapse

LOG_ATTR_ENV =
'dd.env'
LOG_ATTR_SERVICE =
'dd.service'
LOG_ATTR_SPAN_ID =
'dd.span_id'
LOG_ATTR_TRACE_ID =
'dd.trace_id'
LOG_ATTR_VERSION =
'dd.version'
LOG_ATTR_SOURCE =
'ddsource'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.


23
24
25
# File 'lib/datadog/tracing/correlation.rb', line 23

def env
  @env
end

#serviceObject (readonly)

Returns the value of attribute service.


23
24
25
# File 'lib/datadog/tracing/correlation.rb', line 23

def service
  @service
end

#span_idObject (readonly)

Returns the value of attribute span_id.


23
24
25
# File 'lib/datadog/tracing/correlation.rb', line 23

def span_id
  @span_id
end

#versionObject (readonly)

Returns the value of attribute version.


23
24
25
# File 'lib/datadog/tracing/correlation.rb', line 23

def version
  @version
end

Instance Method Details

#to_hObject

[View source]

45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/datadog/tracing/correlation.rb', line 45

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_formatObject

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.

[View source]

62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/datadog/tracing/correlation.rb', line 62

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_idObject

[View source]

75
76
77
# File 'lib/datadog/tracing/correlation.rb', line 75

def trace_id
  Correlation.format_trace_id(@trace_id)
end