Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/datadog/tracing/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def self.extended(base)
# It is not supported by our backend yet. Do not enable it.
option :trace_id_128_bit_logging_enabled do |o|
o.env Tracing::Configuration::Ext::Correlation::ENV_TRACE_ID_128_BIT_LOGGING_ENABLED
o.default false
o.default true
o.type :bool
end

Expand Down
11 changes: 9 additions & 2 deletions lib/datadog/tracing/correlation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ def identifier_from_digest(digest)
end

def format_trace_id(trace_id)
if Datadog.configuration.tracing.trace_id_128_bit_logging_enabled &&
!Tracing::Utils::TraceId.to_high_order(trace_id).zero?
if Datadog.configuration.tracing.trace_id_128_bit_logging_enabled
format_trace_id_128(trace_id)
else
Tracing::Utils::TraceId.to_low_order(trace_id).to_s
end
end

def format_trace_id_128(trace_id)
if !Tracing::Utils::TraceId.to_high_order(trace_id).zero?
Kernel.format('%032x', trace_id)
else
Tracing::Utils::TraceId.to_low_order(trace_id).to_s
Expand Down
8 changes: 4 additions & 4 deletions spec/datadog/tracing/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ def propagation_style_inject
context 'is not defined' do
let(:env_var) { nil }

it { is_expected.to eq(false) }
it { is_expected.to eq(true) }
end

context 'is `true`' do
Expand All @@ -964,10 +964,10 @@ def propagation_style_inject
describe '#trace_id_128_bit_logging_enabled=' do
it 'updates the #trace_id_128_bit_logging_enabled setting' do
expect do
settings.tracing.trace_id_128_bit_logging_enabled = true
settings.tracing.trace_id_128_bit_logging_enabled = false
end.to change { settings.tracing.trace_id_128_bit_logging_enabled }
.from(false)
.to(true)
.from(true)
.to(false)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
env: 'env',
service: 'service',
span_id: span_id.to_s,
trace_id: low_order_trace_id(trace_id).to_s,
trace_id: trace_id_128_log_injection(trace_id),
version: 'version'
},
ddsource: 'ruby' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def perform(test_retry: false, test_discard: false)
it 'injects trace correlation' do
perform_later
expect(output).to include('my-log')
expect(output).to include(low_order_trace_id(span.trace_id).to_s)
expect(output).to include(trace_id_128_log_injection(span.trace_id))
end
end

Expand Down
108 changes: 55 additions & 53 deletions spec/datadog/tracing/contrib/rails/rails_log_auto_injection_spec.rb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def index

if defined?(RailsSemanticLogger::ActionView::LogSubscriber) || Rails.version >= '5'
expect(log_entries).to have(6).items
expect(log_entries).to all include low_order_trace_id(trace.id).to_s
expect(log_entries).to all include trace_id_128_log_injection(trace.id)
expect(log_entries).to all include 'ddsource: ruby'

rack_started_entry,
Expand Down Expand Up @@ -119,7 +119,7 @@ def index
else
expect(log_entries).to have(5).items

expect(log_entries).to all include low_order_trace_id(trace.id).to_s
expect(log_entries).to all include trace_id_128_log_injection(trace.id)
expect(log_entries).to all include 'ddsource: ruby'
end
end
Expand All @@ -138,7 +138,7 @@ def index
if defined?(RailsSemanticLogger::ActionView::LogSubscriber) || Rails.version >= '5'
expect(log_entries).to have(6).items

expect(log_entries).to all include(low_order_trace_id(trace.id).to_s)
expect(log_entries).to all include(trace_id_128_log_injection(trace.id))
expect(log_entries).to all include('ddsource: ruby')
expect(log_entries).to all include('some_tag')
expect(log_entries).to all include('some_value')
Expand Down Expand Up @@ -171,7 +171,7 @@ def index
else
expect(log_entries).to have(5).items

expect(log_entries).to all include(low_order_trace_id(trace.id).to_s)
expect(log_entries).to all include(trace_id_128_log_injection(trace.id))
expect(log_entries).to all include('ddsource: ruby')
expect(log_entries).to all include('some_tag')
expect(log_entries).to all include('some_value')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
expect(log_entry).to include 'Mamamia!'
expect(log_entry).to include 'original: tag'

expect(log_entry).to include low_order_trace_id(trace_id).to_s
expect(log_entry).to include trace_id_128_log_injection(trace_id)
expect(log_entry).to include span_id.to_s
expect(log_entry).to include 'production'
expect(log_entry).to include 'MyService'
Expand All @@ -91,7 +91,7 @@
expect(log_entry).to include 'Mamamia!'
expect(log_entry).to include 'original: tag'

expect(log_entry).not_to include low_order_trace_id(trace_id).to_s
expect(log_entry).not_to include trace_id_128_log_injection(trace_id)
expect(log_entry).not_to include span_id.to_s
expect(log_entry).not_to include 'production'
expect(log_entry).not_to include 'MyService'
Expand All @@ -111,7 +111,7 @@
expect(log_entry).to include 'Mamamia!'
expect(log_entry).to include 'original: tag'

expect(log_entry).not_to include low_order_trace_id(trace_id).to_s
expect(log_entry).not_to include trace_id_128_log_injection(trace_id)
expect(log_entry).not_to include span_id.to_s
expect(log_entry).not_to include 'production'
expect(log_entry).not_to include 'MyService'
Expand All @@ -137,7 +137,7 @@
expect(log_entry).to include 'Mamamia!'
expect(log_entry).not_to include 'original: tag'

expect(log_entry).to include low_order_trace_id(trace_id).to_s
expect(log_entry).to include trace_id_128_log_injection(trace_id)
expect(log_entry).to include span_id.to_s
expect(log_entry).to include 'production'
expect(log_entry).to include 'MyService'
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/tracing/correlation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
env: default_env,
service: default_service,
span_id: span_id.to_s,
trace_id: low_order_trace_id(trace_id).to_s,
trace_id: trace_id_128_log_injection(trace_id),
version: default_version
)
end
Expand Down Expand Up @@ -189,7 +189,7 @@
env: env,
service: service,
span_id: span_id.to_s,
trace_id: low_order_trace_id(trace_id).to_s,
trace_id: trace_id_128_log_injection(trace_id),
version: version
)
end
Expand Down Expand Up @@ -222,7 +222,7 @@
env: 'dev',
service: 'acme-api',
version: '1.0',
trace_id: low_order_trace_id(trace_id).to_s,
trace_id: trace_id_128_log_injection(trace_id),
span_id: span_id.to_s
},
ddsource: 'ruby'
Expand Down
18 changes: 9 additions & 9 deletions spec/datadog/tracing/trace_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ def span
it do
expect(trace_op.to_correlation).to have_attributes(
span_id: '0',
trace_id: low_order_trace_id(trace_op.id).to_s,
trace_id: trace_id_128_log_injection(trace_op.id),
)
end
end
Expand All @@ -2168,7 +2168,7 @@ def span
it do
expect(trace_op.to_correlation).to have_attributes(
span_id: parent_span_id.to_s,
trace_id: low_order_trace_id(trace_op.id).to_s
trace_id: trace_id_128_log_injection(trace_op.id)
)
end
end
Expand All @@ -2187,7 +2187,7 @@ def span

expect(correlation).to have_attributes(
span_id: parent_id.to_s,
trace_id: low_order_trace_id(trace_op.id).to_s
trace_id: trace_id_128_log_injection(trace_op.id)
)
end

Expand All @@ -2208,7 +2208,7 @@ def span

expect(correlation).to have_attributes(
span_id: parent_id.to_s,
trace_id: low_order_trace_id(trace_op.id).to_s
trace_id: trace_id_128_log_injection(trace_op.id)
)
end
end
Expand All @@ -2221,7 +2221,7 @@ def span

expect(trace_op.to_correlation).to have_attributes(
span_id: '0',
trace_id: low_order_trace_id(trace_op.id).to_s,
trace_id: trace_id_128_log_injection(trace_op.id),
)
end
end
Expand All @@ -2232,7 +2232,7 @@ def span

expect(trace_op.to_correlation).to have_attributes(
span_id: span.id.to_s,
trace_id: low_order_trace_id(trace_op.id).to_s,
trace_id: trace_id_128_log_injection(trace_op.id),
)
end
end
Expand All @@ -2243,7 +2243,7 @@ def span

expect(trace_op.to_correlation).to have_attributes(
span_id: '0',
trace_id: low_order_trace_id(trace_op.id).to_s,
trace_id: trace_id_128_log_injection(trace_op.id),
)
end
end
Expand All @@ -2258,7 +2258,7 @@ def span

expect(trace_op.to_correlation).to have_attributes(
span_id: '0',
trace_id: low_order_trace_id(trace_op.id).to_s
trace_id: trace_id_128_log_injection(trace_op.id)
)
end

Expand All @@ -2274,7 +2274,7 @@ def span

expect(trace_op.to_correlation).to have_attributes(
span_id: '0',
trace_id: low_order_trace_id(trace_op.id).to_s
trace_id: trace_id_128_log_injection(trace_op.id)
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@
it 'produces an Identifier with data' do
is_expected.to be_a_kind_of(Datadog::Tracing::Correlation::Identifier)
expect(active_correlation.trace_id)
.to eq(low_order_trace_id(span.trace_id).to_s)
.to eq(trace_id_128_log_injection(span.trace_id))
expect(active_correlation.span_id).to eq(span.id.to_s)
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/support/tracer_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'datadog/tracing/tracer'
require 'datadog/tracing/correlation'
require 'datadog/tracing/trace_operation'
require 'support/faux_writer'
require 'datadog/tracing/utils'

module TracerHelpers
# Return a test tracer instance with a faux writer.
Expand Down Expand Up @@ -123,6 +125,11 @@ def low_order_trace_id(trace_id)
Datadog::Tracing::Utils::TraceId.to_low_order(trace_id)
end

## Wraps call to Datadog::Tracing::Correlation.format_trace_id_128 for better test readability
def trace_id_128_log_injection(trace_id)
Datadog::Tracing::Correlation.format_trace_id_128(trace_id)
end

# Wraps call to Tracing::Utils::TraceId.to_high_order and converts to hex
# for better test readability
def high_order_hex_trace_id(trace_id)
Expand Down
Loading