From d4b1d760e4d53cb3cef39ccafdaab5c1c594dcf3 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Thu, 30 Nov 2023 17:04:29 -0800 Subject: [PATCH] Case-insensitive propagation style configuration --- lib/datadog/tracing/configuration/ext.rb | 2 +- lib/datadog/tracing/configuration/settings.rb | 21 +++++++--- spec/datadog/opentelemetry_spec.rb | 4 +- .../opentracer/rack_propagator_spec.rb | 2 +- .../tracing/configuration/settings_spec.rb | 40 +++++++++++++++++-- .../grpc/distributed/propagation_spec.rb | 2 +- .../http/distributed/propagation_spec.rb | 2 +- .../tracing/distributed/propagation_spec.rb | 2 +- 8 files changed, 60 insertions(+), 15 deletions(-) diff --git a/lib/datadog/tracing/configuration/ext.rb b/lib/datadog/tracing/configuration/ext.rb index 68bed3ed546..afb4a19acf6 100644 --- a/lib/datadog/tracing/configuration/ext.rb +++ b/lib/datadog/tracing/configuration/ext.rb @@ -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' diff --git a/lib/datadog/tracing/configuration/settings.rb b/lib/datadog/tracing/configuration/settings.rb index e7727c6288d..558af6497ba 100644 --- a/lib/datadog/tracing/configuration/settings.rb +++ b/lib/datadog/tracing/configuration/settings.rb @@ -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] option :propagation_extract_style do |o| o.type :array @@ -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] option :propagation_inject_style do |o| o.type :array @@ -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} @@ -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 diff --git a/spec/datadog/opentelemetry_spec.rb b/spec/datadog/opentelemetry_spec.rb index edfad383866..51b2740d370 100644 --- a/spec/datadog/opentelemetry_spec.rb +++ b/spec/datadog/opentelemetry_spec.rb @@ -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| @@ -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 diff --git a/spec/datadog/opentracer/rack_propagator_spec.rb b/spec/datadog/opentracer/rack_propagator_spec.rb index d2a9af36ae3..4a1b22dfb2b 100644 --- a/spec/datadog/opentracer/rack_propagator_spec.rb +++ b/spec/datadog/opentracer/rack_propagator_spec.rb @@ -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 diff --git a/spec/datadog/tracing/configuration/settings_spec.rb b/spec/datadog/tracing/configuration/settings_spec.rb index f0166abf5f1..647b26322be 100644 --- a/spec/datadog/tracing/configuration/settings_spec.rb +++ b/spec/datadog/tracing/configuration/settings_spec.rb @@ -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 @@ -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( @@ -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 @@ -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 @@ -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 diff --git a/spec/datadog/tracing/contrib/grpc/distributed/propagation_spec.rb b/spec/datadog/tracing/contrib/grpc/distributed/propagation_spec.rb index a063078707e..aac699d71c1 100644 --- a/spec/datadog/tracing/contrib/grpc/distributed/propagation_spec.rb +++ b/spec/datadog/tracing/contrib/grpc/distributed/propagation_spec.rb @@ -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 diff --git a/spec/datadog/tracing/contrib/http/distributed/propagation_spec.rb b/spec/datadog/tracing/contrib/http/distributed/propagation_spec.rb index 33fc58cb4ea..3e9b6f01fa1 100644 --- a/spec/datadog/tracing/contrib/http/distributed/propagation_spec.rb +++ b/spec/datadog/tracing/contrib/http/distributed/propagation_spec.rb @@ -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 diff --git a/spec/datadog/tracing/distributed/propagation_spec.rb b/spec/datadog/tracing/distributed/propagation_spec.rb index 0a9ddd0a781..d726ef942f0 100644 --- a/spec/datadog/tracing/distributed/propagation_spec.rb +++ b/spec/datadog/tracing/distributed/propagation_spec.rb @@ -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