Skip to content

Commit

Permalink
Merge pull request #3299 from DataDog/case-insensitive-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc authored Dec 5, 2023
2 parents 03a0a8f + d4b1d76 commit 9df7a53
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/tracing/configuration/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Correlation
# @public_api
module Distributed
# Custom Datadog format
PROPAGATION_STYLE_DATADOG = 'Datadog'
PROPAGATION_STYLE_DATADOG = 'datadog'

PROPAGATION_STYLE_B3_MULTI_HEADER = 'b3multi'
PROPAGATION_STYLE_B3_SINGLE_HEADER = 'b3'
Expand Down
21 changes: 16 additions & 5 deletions lib/datadog/tracing/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def self.extended(base)
#
# @public_api
settings :distributed_tracing do
# An ordered list of what data propagation styles the tracer will use to extract distributed tracing propagation
# An ordered, case-insensitive list of what data propagation styles the tracer will use to extract distributed tracing propagation
# data from incoming requests and messages.
#
# The tracer will try to find distributed headers in the order they are present in the list provided to this option.
# The first format to have valid data present will be used.
#
# @default `DD_TRACE_PROPAGATION_STYLE_EXTRACT` environment variable (comma-separated list),
# otherwise `['Datadog','b3multi','b3']`.
# otherwise `['datadog','b3multi','b3']`.
# @return [Array<String>]
option :propagation_extract_style do |o|
o.type :array
Expand All @@ -60,14 +60,18 @@ def self.extended(base)
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT,
]
)
o.after_set do |styles|
# Make values case-insensitive
styles.map!(&:downcase)
end
end

# The data propagation styles the tracer will use to inject distributed tracing propagation
# The case-insensitive list of the data propagation styles the tracer will use to inject distributed tracing propagation
# data into outgoing requests and messages.
#
# The tracer will inject data from all styles specified in this option.
#
# @default `DD_TRACE_PROPAGATION_STYLE_INJECT` environment variable (comma-separated list), otherwise `['Datadog']`.
# @default `DD_TRACE_PROPAGATION_STYLE_INJECT` environment variable (comma-separated list), otherwise `['datadog','tracecontext']`.
# @return [Array<String>]
option :propagation_inject_style do |o|
o.type :array
Expand All @@ -76,9 +80,13 @@ def self.extended(base)
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG,
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT,
]
o.after_set do |styles|
# Make values case-insensitive
styles.map!(&:downcase)
end
end

# An ordered list of what data propagation styles the tracer will use to extract distributed tracing propagation
# An ordered, case-insensitive 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}
Expand All @@ -93,6 +101,9 @@ def self.extended(base)
o.after_set do |styles|
next if styles.empty?

# Make values case-insensitive
styles.map!(&:downcase)

set_option(:propagation_extract_style, styles)
set_option(:propagation_inject_style, styles)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/opentelemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Datadog.configure do |c|
c.tracing.writer = writer_
c.tracing.partial_flush.min_spans_threshold = 1 # Ensure tests flush spans quickly
c.tracing.distributed_tracing.propagation_style = ['Datadog'] # Ensure test has consistent propagation configuration
c.tracing.distributed_tracing.propagation_style = ['datadog'] # Ensure test has consistent propagation configuration
end

::OpenTelemetry::SDK.configure do |c|
Expand Down Expand Up @@ -732,7 +732,7 @@ def headers

before do
Datadog.configure do |c|
c.tracing.distributed_tracing.propagation_extract_style = ['Datadog', 'tracecontext']
c.tracing.distributed_tracing.propagation_extract_style = ['datadog', 'tracecontext']
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/opentracer/rack_propagator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

before do
Datadog.configure do |c|
c.tracing.distributed_tracing.propagation_style = ['Datadog']
c.tracing.distributed_tracing.propagation_style = ['datadog']
end

# Expect carrier to be set with Datadog trace properties
Expand Down
40 changes: 37 additions & 3 deletions spec/datadog/tracing/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@
]
)
end

context 'with a mixed case value' do
let(:var_value) { 'B3Multi,B3' }

it 'parses in a case-insensitive manner' do
is_expected.to eq(
[
Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER,
Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER
]
)
end
end
end
end
end
Expand All @@ -114,7 +127,7 @@
end

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

it do
is_expected.to eq(
Expand All @@ -124,6 +137,19 @@
]
)
end

context 'with a mixed case value' do
let(:var_value) { 'Datadog,B3' }

it 'parses in a case-insensitive manner' do
is_expected.to eq(
[
Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG,
Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER
]
)
end
end
end
end
end
Expand All @@ -148,11 +174,11 @@ def propagation_inject_style
it { is_expected.to eq [] }

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

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

Expand All @@ -168,6 +194,14 @@ def propagation_inject_style
it 'sets propagation_inject_style' do
expect { propagation_style }.to change { propagation_inject_style }.to(%w[b3multi b3])
end

context 'with a mixed case value' do
let(:var_value) { 'b3MULTI' }

it 'parses in a case-insensitive manner' do
expect { propagation_style }.to change { propagation_extract_style }.to(%w[b3multi])
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

context 'for Datadog' do
it_behaves_like 'Datadog distributed format' do
before { Datadog.configure { |c| c.tracing.distributed_tracing.propagation_style = ['Datadog'] } }
before { Datadog.configure { |c| c.tracing.distributed_tracing.propagation_style = ['datadog'] } }
let(:datadog) { propagation }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

context 'for Datadog' do
it_behaves_like 'Datadog distributed format' do
before { Datadog.configure { |c| c.tracing.distributed_tracing.propagation_style = ['Datadog'] } }
before { Datadog.configure { |c| c.tracing.distributed_tracing.propagation_style = ['datadog'] } }
let(:datadog) { propagation }
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/distributed/propagation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

let(:propagation_styles) do
{
'Datadog' => Datadog::Tracing::Distributed::Datadog.new(fetcher: fetcher_class),
'datadog' => Datadog::Tracing::Distributed::Datadog.new(fetcher: fetcher_class),
'tracecontext' => Datadog::Tracing::Distributed::TraceContext.new(fetcher: fetcher_class),
}
end
Expand Down

0 comments on commit 9df7a53

Please sign in to comment.