diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 8f3111fe6e9..d7c704a0de2 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -2064,8 +2064,8 @@ For example, if `tracing.sampling.default_rate` is configured by [Remote Configu | `tracing.analytics.enabled` | `DD_TRACE_ANALYTICS_ENABLED` | `nil` | Enables or disables trace analytics. See [Sampling](#sampling) for more details. | | `tracing.contrib.peer_service_mapping` | `DD_TRACE_PEER_SERVICE_MAPPING` | `nil` | Defines remapping of `peer.service` tag across all instrumentation. Provide a list of `old_value1:new_value1, old_value2:new_value2, ...` | | `tracing.contrib.global_default_service_name.enabled` | `DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED` | `false` | Changes the default value for `service_name` to the application service name across all instrumentation | -| `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_extract_style` | `DD_TRACE_PROPAGATION_STYLE_EXTRACT` | `['Datadog','tracecontext']` | 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','tracecontext']` | 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.header_tags` | `DD_TRACE_HEADER_TAGS` | `nil` | Record HTTP headers as span tags. See [Applying header tags to root spans][header tags] for more information. | @@ -2340,10 +2340,10 @@ Service C: Tracing supports the following distributed trace formats: - - `Datadog`: **Default** + - `Datadog` + - `tracecontext`: [W3C Trace Context](https://www.w3.org/TR/trace-context/) - `b3multi`: [B3 multiple-headers](https://github.com/openzipkin/b3-propagation#multiple-headers) - `b3`: [B3 single-header](https://github.com/openzipkin/b3-propagation#single-header) - - `tracecontext`: [W3C Trace Context](https://www.w3.org/TR/trace-context/) - `none`: No-op. You can enable/disable the use of these formats via `Datadog.configure`: diff --git a/lib/datadog/tracing/configuration/settings.rb b/lib/datadog/tracing/configuration/settings.rb index e5c67e731f6..ddc3f93e861 100644 --- a/lib/datadog/tracing/configuration/settings.rb +++ b/lib/datadog/tracing/configuration/settings.rb @@ -61,8 +61,7 @@ def self.extended(base) o.default( [ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG, - Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER, - Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER, + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT, ] ) o.after_set do |styles| @@ -93,7 +92,10 @@ def self.extended(base) o.deprecated_env Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT_OLD o.env Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT # DEV-2.0: Change default value to `tracecontext, Datadog`. - o.default [Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG] + o.default [ + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG, + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT, + ] o.after_set do |styles| # Modernize B3 options # DEV-2.0: Can be removed with the removal of deprecated B3 constants. diff --git a/spec/datadog/tracing/configuration/settings_spec.rb b/spec/datadog/tracing/configuration/settings_spec.rb index 52d8e102be1..7a44c00d539 100644 --- a/spec/datadog/tracing/configuration/settings_spec.rb +++ b/spec/datadog/tracing/configuration/settings_spec.rb @@ -74,12 +74,9 @@ let(:var_value) { nil } it do - is_expected.to eq( - [ - Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG, - Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER, - Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER - ] + is_expected.to contain_exactly( + Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG, + Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT ) end end @@ -214,27 +211,25 @@ 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 b3multi b3]) + 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(['Datadog']) + expect { propagation_style }.to_not change { propagation_inject_style }.from(%w[Datadog tracecontext]) end end context 'is defined' do - let(:var_value) { 'Datadog,b3' } + let(:var_value) { 'b3multi,b3' } - it { is_expected.to contain_exactly('Datadog', 'b3') } + it { is_expected.to contain_exactly('b3multi', 'b3') } it 'sets propagation_extract_style' do - expect { propagation_style }.to change { propagation_extract_style } - .from(%w[Datadog b3multi b3]).to(%w[Datadog b3]) + expect { propagation_style }.to change { propagation_extract_style }.to(%w[b3multi b3]) end it 'sets propagation_inject_style' do - expect { propagation_style }.to change { propagation_inject_style }.from(['Datadog']).to(%w[Datadog b3]) + expect { propagation_style }.to change { propagation_inject_style }.to(%w[b3multi b3]) end end end diff --git a/spec/datadog/tracing/distributed/propagation_spec.rb b/spec/datadog/tracing/distributed/propagation_spec.rb index 6158999385b..731f455fef5 100644 --- a/spec/datadog/tracing/distributed/propagation_spec.rb +++ b/spec/datadog/tracing/distributed/propagation_spec.rb @@ -2,20 +2,24 @@ require 'datadog/tracing/distributed/propagation' -RSpec.shared_examples 'Distributed tracing propagator' do +RSpec.describe Datadog::Tracing::Distributed::Propagation do subject(:propagator) { described_class.new(propagation_styles: propagation_styles) } let(:propagation_styles) do { 'Datadog' => Datadog::Tracing::Distributed::Datadog.new(fetcher: fetcher_class), - 'b3multi' => Datadog::Tracing::Distributed::B3Multi.new(fetcher: fetcher_class), - 'b3' => Datadog::Tracing::Distributed::B3Single.new(fetcher: fetcher_class), + 'tracecontext' => Datadog::Tracing::Distributed::TraceContext.new(fetcher: fetcher_class), } end let(:fetcher_class) { Datadog::Tracing::Distributed::Fetcher } let(:prepare_key) { defined?(super) ? super() : proc { |key| key } } + let(:traceparent) do + "00-#{format('%032x', tracecontext_trace_id)}-#{format('%016x', tracecontext_span_id)}-" \ + "#{format('%02x', tracecontext_trace_flags)}" + end + describe '::inject!' do subject(:inject!) { propagator.inject!(trace, data) } let(:data) { {} } @@ -208,76 +212,27 @@ end end - context 'B3 Multi trace id and parent id' do - let(:data) do - { - prepare_key['x-b3-traceid'] => '00ef01', - prepare_key['x-b3-spanid'] => '011ef0' - } - end + context 'tracecontext trace id, parent id, and sampling priority' do + let(:data) { { prepare_key['traceparent'] => traceparent } } - it do - expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.span_id).to eq(73456) - expect(trace_digest.trace_id).to eq(61185) - expect(trace_digest.trace_sampling_priority).to be nil - end - - context 'and sampling priority' do - let(:data) do - { - prepare_key['x-b3-traceid'] => '00ef01', - prepare_key['x-b3-spanid'] => '011ef0', - prepare_key['x-b3-sampled'] => '0' - } - end - - it do - expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.span_id).to eq(73456) - expect(trace_digest.trace_id).to eq(61185) - expect(trace_digest.trace_sampling_priority).to eq(0) - end - end - end - - context 'B3 Single trace id and parent id' do - let(:data) do - { - prepare_key['b3'] => '00ef01-011ef0' - } - end + let(:tracecontext_trace_id) { 0xc0ffee } + let(:tracecontext_span_id) { 0xbee } + let(:tracecontext_trace_flags) { 0x00 } it do expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.span_id).to eq(73456) - expect(trace_digest.trace_id).to eq(61185) - expect(trace_digest.trace_sampling_priority).to be nil - end - - context 'and sampling priority' do - let(:data) do - { - prepare_key['b3'] => '00ef01-011ef0-0' - } - end - - it do - expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.span_id).to eq(73456) - expect(trace_digest.trace_id).to eq(61185) - expect(trace_digest.trace_sampling_priority).to eq(0) - end + expect(trace_digest.span_id).to eq(0xbee) + expect(trace_digest.trace_id).to eq(0xc0ffee) + expect(trace_digest.trace_sampling_priority).to eq(0) end end - context 'datadog, and b3 header' do + context 'datadog, and tracecontext header' do let(:data) do { prepare_key['x-datadog-trace-id'] => '61185', prepare_key['x-datadog-parent-id'] => '73456', - prepare_key['x-b3-traceid'] => '00ef01', - prepare_key['x-b3-spanid'] => '011ef0' + prepare_key['traceparent'] => '00-11111111111111110000000000000001-000000003ade68b1-01', } end @@ -294,9 +249,7 @@ prepare_key['x-datadog-trace-id'] => '61185', prepare_key['x-datadog-parent-id'] => '73456', prepare_key['x-datadog-sampling-priority'] => '1', - prepare_key['x-b3-traceid'] => '00ef01', - prepare_key['x-b3-spanid'] => '011ef0', - prepare_key['x-b3-sampled'] => '0' + prepare_key['traceparent'] => '00-00000000000000000000000000c0ffee-0000000000000bee-00', } end @@ -320,10 +273,10 @@ expect(Datadog.logger).to have_received(:error).with(/Cause: test_err Location: caller:1/) end - it 'extracts values from non-failing propagator (B3)' do + it 'extracts values from non-failing propagator (tracecontext)' do expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.span_id).to eq(73456) - expect(trace_digest.trace_id).to eq(61185) + expect(trace_digest.span_id).to eq(0xbee) + expect(trace_digest.trace_id).to eq(0xc0ffee) expect(trace_digest.trace_sampling_priority).to eq(0) end end @@ -407,16 +360,18 @@ context 'when conflict across different extractions' do let(:datadog_trace_id) { 0xabcdef } - let(:b3_multi_trace_id) { 0x123456 } - let(:b3_trace_id) { 0xfedcba } - let(:span_id) { 0xfffffff } + let(:tracecontext_trace_id) { 0x123456 } + + let(:datadog_span_id) { 0xfffffff } + let(:tracecontext_span_id) { 0x1111111 } + + let(:tracecontext_trace_flags) { 0x01 } + let(:data) do { prepare_key['x-datadog-trace-id'] => datadog_trace_id.to_s(10), - prepare_key['x-datadog-parent-id'] => span_id.to_s(10), - prepare_key['x-b3-traceid'] => b3_multi_trace_id.to_s(16), - prepare_key['x-b3-spanid'] => span_id.to_s(16), - prepare_key['b3'] => "#{b3_trace_id.to_s(16)}-#{span_id.to_s(16)}" + prepare_key['x-datadog-parent-id'] => datadog_span_id.to_s(10), + prepare_key['traceparent'] => traceparent, } end @@ -424,64 +379,12 @@ Datadog.configuration.reset! end - context "when extraction styles ['Datadog', 'b3multi', 'b3']" do - before do - Datadog.configure do |c| - c.tracing.distributed_tracing.propagation_extract_style = [ - 'Datadog', - 'b3multi', - 'b3', - ] - end - end - - it 'returns trace digest from `Datadog` extraction' do - expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.trace_id).to eq(datadog_trace_id) - expect(trace_digest.span_id).to eq(0xfffffff) - end - end - - context "when extraction styles ['b3multi', 'b3', 'Datadog']" do - before do - Datadog.configure do |c| - c.tracing.distributed_tracing.propagation_extract_style = [ - 'b3multi', - 'b3', - 'Datadog', - ] - end - end - - it 'returns trace digest from `b3multi` extraction' do - expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.trace_id).to eq(b3_multi_trace_id) - expect(trace_digest.span_id).to eq(0xfffffff) - end - end - - context "when extraction styles ['b3', 'Datadog', 'b3multi']" do - before do - Datadog.configure do |c| - c.tracing.distributed_tracing.propagation_extract_style = [ - 'b3', - 'Datadog', - 'b3multi', - ] - end - end - - it 'returns trace digest from `b3` extraction' do - expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) - expect(trace_digest.trace_id).to eq(b3_trace_id) - expect(trace_digest.span_id).to eq(0xfffffff) - end + it 'returns trace digest from the first successful extraction' do + expect(trace_digest).to be_a_kind_of(Datadog::Tracing::TraceDigest) + expect(trace_digest.trace_id).to eq(datadog_trace_id) + expect(trace_digest.span_id).to eq(0xfffffff) end end end end end - -RSpec.describe Datadog::Tracing::Distributed::Propagation do - it_behaves_like 'Distributed tracing propagator' -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b6c3d73d781..261aec57332 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -82,6 +82,7 @@ config.order = :random config.filter_run focus: true config.run_all_when_everything_filtered = true + config.example_status_persistence_file_path = 'tmp/example_status_persistence' # rspec-wait configuration config.wait_timeout = 5 # default timeout for `wait_for(...)`, in seconds