Skip to content

Commit

Permalink
set 128-bit trace_id to true by default (#3266)
Browse files Browse the repository at this point in the history
* set 128-bit trace_id to true by default

* update contrib tests for 128-bit default trace_ids

* update opentracer to work with 128-bit trace_ids

* clenaup tests for 128-bit default enabling
  • Loading branch information
ekump authored Nov 21, 2023
1 parent f7c741d commit 3becb40
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 104 deletions.
2 changes: 1 addition & 1 deletion docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ For example, if `tracing.sampling.default_rate` is configured by [Remote Configu
| `tracing.sampling.rate_limit` | `DD_TRACE_RATE_LIMIT` | `100` (per second) | Sets a maximum number of traces per second to sample. Set a rate limit to avoid the ingestion volume overages in the case of traffic spikes. |
| `tracing.sampling.rules` | `DD_TRACE_SAMPLING_RULES` | `nil` | Sets trace-level sampling rules, matching against the local root span. The format is a `String` with JSON, containing an Array of Objects. Each Object must have a float attribute `sample_rate` (between 0.0 and 1.0, inclusive), and optionally `name` and `service` string attributes. `name` and `service` control to which traces this sampling rule applies; if both are absent, then this rule applies to all traces. Rules are evaluted in order of declartion in the array; only the first to match is applied. If none apply, then `tracing.sampling.default_rate` is applied. |
| `tracing.sampling.span_rules` | `DD_SPAN_SAMPLING_RULES`,`ENV_SPAN_SAMPLING_RULES_FILE` | `nil` | Sets [Single Span Sampling](#single-span-sampling) rules. These rules allow you to keep spans even when their respective traces are dropped. |
| `tracing.trace_id_128_bit_generation_enabled` | `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` | `false` | `true` to generate 128 bits trace ID and `false` to generate 64 bits trace ID |
| `tracing.trace_id_128_bit_generation_enabled` | `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` | `true` | `true` to generate 128 bits trace ID and `false` to generate 64 bits trace ID |
| `tracing.report_hostname` | `DD_TRACE_REPORT_HOSTNAME` | `false` | Adds hostname tag to traces. |
| `tracing.test_mode.enabled` | `DD_TRACE_TEST_MODE_ENABLED` | `false` | Enables or disables test mode, for use of tracing in test suites. |
| `tracing.test_mode.trace_flush` | | `nil` | Object that determines trace flushing behavior. |
Expand Down
3 changes: 2 additions & 1 deletion lib/datadog/opentracer/text_map_propagator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def inject(span_context, carrier)
carrier[Tracing::Distributed::Datadog::ORIGIN_KEY] = digest.trace_origin
carrier[Tracing::Distributed::Datadog::PARENT_ID_KEY] = digest.span_id
carrier[Tracing::Distributed::Datadog::SAMPLING_PRIORITY_KEY] = digest.trace_sampling_priority
carrier[Tracing::Distributed::Datadog::TRACE_ID_KEY] = digest.trace_id
carrier[Tracing::Distributed::Datadog::TRACE_ID_KEY] =
Datadog::Tracing::Utils::TraceId.to_low_order(digest.trace_id)

nil
end
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ def self.extended(base)

# Enable 128 bit trace id generation.
#
# @default `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` environment variable, otherwise `false`
# @default `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` environment variable, otherwise `true`
# @return [Boolean]
option :trace_id_128_bit_generation_enabled do |o|
o.env Tracing::Configuration::Ext::ENV_TRACE_ID_128_BIT_GENERATION_ENABLED
o.default false
o.default true
o.type :bool
end

Expand Down
1 change: 0 additions & 1 deletion lib/datadog/tracing/distributed/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def inject!(digest, data)
build_tags(digest).tap do |tags|
inject_tags!(tags, data) unless tags.empty?
end

data
end

Expand Down
23 changes: 11 additions & 12 deletions spec/datadog/opentelemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,22 @@
describe '#inject' do
subject(:inject) { ::OpenTelemetry.propagation.inject(carrier) }
let(:carrier) { {} }
def headers
{
'x-datadog-parent-id' => Datadog::Tracing.active_span.id.to_s,
'x-datadog-sampling-priority' => '1',
'x-datadog-tags' => '_dd.p.dm=-0,_dd.p.tid=' +
high_order_hex_trace_id(Datadog::Tracing.active_trace.id),
'x-datadog-trace-id' => low_order_trace_id(Datadog::Tracing.active_trace.id).to_s,
}
end

context 'with an active span' do
before { otel_tracer.start_span('existing-active-span') }

it 'injects Datadog headers' do
inject
expect(carrier).to eq(
'x-datadog-parent-id' => Datadog::Tracing.active_span.id.to_s,
'x-datadog-sampling-priority' => '1',
'x-datadog-tags' => '_dd.p.dm=-0',
'x-datadog-trace-id' => Datadog::Tracing.active_trace.id.to_s,
)
expect(carrier).to eq(headers)
end
end

Expand All @@ -462,12 +466,7 @@

it 'injects Datadog headers' do
inject
expect(carrier).to eq(
'x-datadog-parent-id' => Datadog::Tracing.active_span.id.to_s,
'x-datadog-sampling-priority' => '1',
'x-datadog-tags' => '_dd.p.dm=-0',
'x-datadog-trace-id' => Datadog::Tracing.active_trace.id.to_s,
)
expect(carrier).to eq(headers)
end
end
end
Expand Down
13 changes: 9 additions & 4 deletions spec/datadog/opentracer/propagation_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ def baggage_to_carrier_format(baggage)
it { expect(intermediate_datadog_trace.sampling_priority).to eq(1) }
it { expect(intermediate_datadog_trace.origin).to eq('synthetics') }
it { expect(intermediate_datadog_span.finished?).to be(true) }
it { expect(intermediate_datadog_span.trace_id).to eq(origin_datadog_span.trace_id) }

it {
expect(intermediate_datadog_span.trace_id)
.to eq(low_order_trace_id(origin_datadog_span.trace_id))
}

it { expect(intermediate_datadog_span.parent_id).to eq(origin_datadog_span.span_id) }
it { expect(@intermediate_scope.span.context.baggage).to include(baggage) }

Expand All @@ -182,7 +187,7 @@ def baggage_to_carrier_format(baggage)

it do
expect(@origin_carrier).to include(
'x-datadog-trace-id' => origin_datadog_span.trace_id,
'x-datadog-trace-id' => low_order_trace_id(origin_datadog_span.trace_id),
'x-datadog-parent-id' => origin_datadog_span.span_id,
'x-datadog-sampling-priority' => 1,
'x-datadog-origin' => 'synthetics',
Expand Down Expand Up @@ -378,7 +383,7 @@ def baggage_to_carrier_format(baggage)

it do
expect(@origin_carrier).to include(
'x-datadog-trace-id' => origin_datadog_span.trace_id.to_s,
'x-datadog-trace-id' => low_order_trace_id(origin_datadog_span.trace_id).to_s,
'x-datadog-parent-id' => origin_datadog_span.span_id.to_s,
'x-datadog-sampling-priority' => '1',
'x-datadog-origin' => 'synthetics',
Expand All @@ -388,7 +393,7 @@ def baggage_to_carrier_format(baggage)

it do
expect(@intermediate_carrier).to include(
'x-datadog-trace-id' => intermediate_datadog_span.trace_id.to_s,
'x-datadog-trace-id' => low_order_trace_id(intermediate_datadog_span.trace_id).to_s,
'x-datadog-parent-id' => intermediate_datadog_span.span_id.to_s,
'x-datadog-sampling-priority' => '1',
'x-datadog-origin' => 'synthetics',
Expand Down
6 changes: 4 additions & 2 deletions spec/datadog/opentracer/rack_propagator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@

# Expect carrier to be set with Datadog trace properties
expect(carrier).to receive(:[]=)
.with('x-datadog-trace-id', trace_id.to_s)
.with('x-datadog-trace-id', low_order_trace_id(trace_id).to_s)
expect(carrier).to receive(:[]=)
.with('x-datadog-parent-id', span_id.to_s)
expect(carrier).to receive(:[]=)
.with('x-datadog-sampling-priority', sampling_priority.to_s)
expect(carrier).to receive(:[]=)
.with('x-datadog-origin', origin.to_s)
expect(carrier).to receive(:[]=)
.with('x-datadog-tags', '_dd.p.key=value,_dd.p.dm=-1')
.with('x-datadog-tags',
'_dd.p.key=value,_dd.p.dm=-1,_dd.p.tid=' +
high_order_hex_trace_id(trace_id))

# Expect carrier to be set with OpenTracing baggage
baggage.each do |key, value|
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 @@ -826,7 +826,7 @@ def propagation_inject_style
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 @@ -846,10 +846,10 @@ def propagation_inject_style
describe '#trace_id_128_bit_generation_enabled=' do
it 'updates the #trace_id_128_bit_generation_enabled setting' do
expect do
settings.tracing.trace_id_128_bit_generation_enabled = true
settings.tracing.trace_id_128_bit_generation_enabled = false
end.to change { settings.tracing.trace_id_128_bit_generation_enabled }
.from(false)
.to(true)
.from(true)
.to(false)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/contrib/ethon/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
headers = JSON.parse(response.body)['headers']
distributed_tracing_headers = {
'x-datadog-parent-id' => [span.span_id.to_s],
'x-datadog-trace-id' => [span.trace_id.to_s]
'x-datadog-trace-id' => [low_order_trace_id(span.trace_id).to_s]
}

expect(headers).to include(distributed_tracing_headers)
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/contrib/excon/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
span = datum[:datadog_span]
headers = datum[:headers]
expect(headers).to include(
'x-datadog-trace-id' => span.trace_id.to_s,
'x-datadog-trace-id' => low_order_trace_id(span.trace_id).to_s,
'x-datadog-parent-id' => span.span_id.to_s
)

Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/contrib/faraday/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@

it do
expect(headers).to include(
'x-datadog-trace-id' => span.trace_id.to_s,
'x-datadog-trace-id' => low_order_trace_id(span.trace_id).to_s,
'x-datadog-parent-id' => span.span_id.to_s
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/tracing/contrib/http/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def expect_request_without_distributed_headers
let(:distributed_tracing_headers) do
{
'x-datadog-parent-id' => span.span_id,
'x-datadog-trace-id' => span.trace_id,
'x-datadog-trace-id' => low_order_trace_id(span.trace_id),
'x-datadog-sampling-priority' => sampling_priority
}
end
Expand Down Expand Up @@ -423,7 +423,7 @@ def expect_request_without_distributed_headers
let(:distributed_tracing_headers) do
{
'x-datadog-parent-id' => span.span_id,
'x-datadog-trace-id' => span.trace_id,
'x-datadog-trace-id' => low_order_trace_id(span.trace_id),
'x-datadog-sampling-priority' => sampling_priority
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
end

it 'propogrates the trace id header' do
expect(http_response.headers['X-Datadog-Trace-Id']).to eq(span.trace_id.to_s)
expect(http_response.headers['X-Datadog-Trace-Id']).to eq(low_order_trace_id(span.trace_id).to_s)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/tracing/contrib/httprb/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@
expect(http_response.headers['x-datadog-parent-id']).to eq(span.span_id.to_s)
end

it 'propogrates the trace id header' do
expect(http_response.headers['x-datadog-trace-id']).to eq(span.trace_id.to_s)
it 'propagates the trace id header' do
expect(http_response.headers['x-datadog-trace-id']).to eq(low_order_trace_id(span.trace_id).to_s)
end
end

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(span.trace_id.to_s)
expect(output).to include(low_order_trace_id(span.trace_id).to_s)
end
end

Expand Down
Loading

0 comments on commit 3becb40

Please sign in to comment.