Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DD_TRACE_PROPAGATION_STYLE option #2466

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -2078,8 +2078,9 @@ end
| `telemetry.enabled` | `DD_INSTRUMENTATION_TELEMETRY_ENABLED` | `false` | Allows you to enable sending telemetry data to Datadog. In a future release, we will be setting this to `true` by default, as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection). |
| **Tracing** | | | |
| `tracing.analytics.enabled` | `DD_TRACE_ANALYTICS_ENABLED` | `nil` | Enables or disables trace analytics. See [Sampling](#sampling) for more details. |
| `tracing.distributed_tracing.propagation_extract_style` | `DD_TRACE_PROPAGATION_STYLE_EXTRACT` | `['Datadog','b3multi','b3']` | Distributed tracing header formats to extract. See [Distributed Tracing](#distributed-tracing) for more details.|
| `tracing.distributed_tracing.propagation_inject_style` | `DD_TRACE_PROPAGATION_STYLE_INJECT` | `['Datadog']` | Distributed tracing header formats to inject. See [Distributed Tracing](#distributed-tracing) for more details. |
| `tracing.distributed_tracing.propagation_extract_style` | `DD_TRACE_PROPAGATION_STYLE_EXTRACT` | `['Datadog','b3multi','b3']` | Distributed tracing propagation formats to extract. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. |
| `tracing.distributed_tracing.propagation_inject_style` | `DD_TRACE_PROPAGATION_STYLE_INJECT` | `['Datadog']` | Distributed tracing propagation formats to inject. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. |
| `tracing.distributed_tracing.propagation_style` | `DD_TRACE_PROPAGATION_STYLE` | `nil` | Distributed tracing propagation formats to extract and inject. See [Distributed Tracing](#distributed-tracing) for more details. |
| `tracing.enabled` | `DD_TRACE_ENABLED` | `true` | Enables or disables tracing. If set to `false` instrumentation will still run, but no traces are sent to the trace agent. |
| `tracing.instrument(<integration-name>, <options...>)` | | | Activates instrumentation for a specific library. See [Integration instrumentation](#integration-instrumentation) for more details. |
| `tracing.log_injection` | `DD_LOGS_INJECTION` | `true` | Injects [Trace Correlation](#trace-correlation) information into Rails logs if present. Supports the default logger (`ActiveSupport::TaggedLogging`), `lograge`, and `semantic_logger`. |
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/configuration/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Distributed
# Sets both extract and inject propagation style tho the provided value.
# Has lower precedence than `DD_TRACE_PROPAGATION_STYLE_INJECT` or
# `DD_TRACE_PROPAGATION_STYLE_EXTRACT`.
ENV_PROPAGATION_STYLE_EXTRACT = 'DD_TRACE_PROPAGATION_STYLE'.freeze
ENV_PROPAGATION_STYLE = 'DD_TRACE_PROPAGATION_STYLE'.freeze
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced this constant recently (a change still not released), but copy/pasted the constant name. This fixes that.


ENV_PROPAGATION_STYLE_INJECT = 'DD_TRACE_PROPAGATION_STYLE_INJECT'.freeze
# @deprecated Use `DD_TRACE_PROPAGATION_STYLE_INJECT` instead.
Expand Down
38 changes: 38 additions & 0 deletions lib/datadog/tracing/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Configuration
# @public_api
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/BlockLength
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength
# rubocop:disable Layout/LineLength
module Settings
Expand Down Expand Up @@ -124,6 +125,42 @@ def self.extended(base)

o.lazy
end

# An ordered list of what data propagation styles the tracer will use to extract distributed tracing propagation
# data from incoming requests and inject into outgoing requests.
#
# This configuration is the equivalent of configuring both {propagation_extract_style}
# {propagation_inject_style} to value set to {propagation_style}.
#
# @default `DD_TRACE_PROPAGATION_STYLE` environment variable (comma-separated list).
# @return [Array<String>]
option :propagation_style do |o|
o.default do
env_to_list(Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE, nil, comma_separated_only: true)
end

o.on_set do |styles|
next unless styles

# Modernize B3 options
# DEV-2.0: Can be removed with the removal of deprecated B3 constants.
styles.map! do |style|
case style
when Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER
when Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER_OLD
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER
else
style
end
end

set_option(:propagation_extract_style, styles)
set_option(:propagation_inject_style, styles)
end

o.lazy
end
end

# Enable trace collection and span generation.
Expand Down Expand Up @@ -388,6 +425,7 @@ def self.extended(base)
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/BlockLength
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength
# rubocop:enable Layout/LineLength
end
Expand Down
64 changes: 52 additions & 12 deletions spec/datadog/tracing/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
end

describe '#distributed_tracing' do
around do |example|
ClimateControl.modify(var_name => var_value) do
example.run
end
end

describe '#propagation_extract_style' do
subject(:propagation_extract_style) { settings.tracing.distributed_tracing.propagation_extract_style }

around do |example|
ClimateControl.modify(var_name => var_value) do
example.run
end
end

context 'when DD_TRACE_PROPAGATION_STYLE_EXTRACT' do
let(:var_name) { 'DD_TRACE_PROPAGATION_STYLE_EXTRACT' }

Expand Down Expand Up @@ -136,12 +136,6 @@
describe '#propagation_inject_style' do
subject(:propagation_inject_style) { settings.tracing.distributed_tracing.propagation_inject_style }

around do |example|
ClimateControl.modify(var_name => var_value) do
example.run
end
end

context 'with DD_TRACE_PROPAGATION_STYLE_INJECT' do
let(:var_name) { 'DD_TRACE_PROPAGATION_STYLE_INJECT' }

Expand Down Expand Up @@ -197,6 +191,52 @@
end
end
end

describe '#propagation_style' do
subject(:propagation_style) { settings.tracing.distributed_tracing.propagation_style }

def propagation_extract_style
settings.tracing.distributed_tracing.propagation_extract_style
end

def propagation_inject_style
settings.tracing.distributed_tracing.propagation_inject_style
end

context 'with DD_TRACE_PROPAGATION_STYLE' do
let(:var_name) { 'DD_TRACE_PROPAGATION_STYLE' }

context 'is not defined' do
let(:var_value) { nil }

it { is_expected.to be_nil }

it 'does not change propagation_extract_style' do
expect { propagation_style }.to_not change { propagation_extract_style }
.from(%w[Datadog b3multi b3])
end

it 'does not change propagation_inject_style' do
expect { propagation_style }.to_not change { propagation_inject_style }.from(['Datadog'])
end
end

context 'is defined' do
let(:var_value) { 'Datadog,b3' }

it { is_expected.to contain_exactly('Datadog', 'b3') }

it 'sets propagation_extract_style' do
expect { propagation_style }.to change { propagation_extract_style }
.from(%w[Datadog b3multi b3]).to(%w[Datadog b3])
end

it 'sets propagation_inject_style' do
expect { propagation_style }.to change { propagation_inject_style }.from(['Datadog']).to(%w[Datadog b3])
end
end
end
end
end

describe '#enabled' do
Expand Down