From 26057a15c5ba412f19a6b66ec7e82949c2320fb2 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Tue, 3 Dec 2024 15:55:18 -0500 Subject: [PATCH 1/7] create propagate span event and publish it in to_digest --- lib/datadog/tracing/trace_operation.rb | 13 +++++++++++-- lib/datadog/tracing/tracer.rb | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index eb85182af75..ab48e86f864 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -311,7 +311,7 @@ def to_digest span_id = @active_span && @active_span.id span_id ||= @parent_span_id unless finished? # sample the trace_operation with the tracer - @tracer&.sample_trace(self) unless sampling_priority + events.propagate.publish(span, self) TraceDigest.new( span_id: span_id, @@ -380,12 +380,14 @@ class Events attr_reader \ :span_before_start, :span_finished, - :trace_finished + :trace_finished, + :propagate def initialize @span_before_start = SpanBeforeStart.new @span_finished = SpanFinished.new @trace_finished = TraceFinished.new + @propagate = Propagate.new end # Triggered before a span starts. @@ -402,6 +404,13 @@ def initialize end end + # Triggered when trace is being propagated between applications or contexts + class Propagate < Tracing::Event + def initialize + super(:propagate) + end + end + # Triggered when the trace finishes, regardless of error. class TraceFinished < Tracing::Event def initialize diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index a6da0e98199..2af89861469 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -362,6 +362,11 @@ def bind_trace_events!(trace_op) event_span_op.service ||= @default_service end + events.propagate.subscribe do |event_span, event_trace_op| + sample_span(event_trace_op, event_span) + sample_trace(event_trace_op) unless event_trace_op.sampling_priority + end + events.span_finished.subscribe do |event_span, event_trace_op| sample_span(event_trace_op, event_span) flush_trace(event_trace_op) From 9e8b54c8b597bbb224109986d6d1ede67f2fca53 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Wed, 4 Dec 2024 16:04:53 -0500 Subject: [PATCH 2/7] fix span passed into callback --- lib/datadog/tracing/trace_operation.rb | 2 +- lib/datadog/tracing/tracer.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index ab48e86f864..31c39261665 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -311,7 +311,7 @@ def to_digest span_id = @active_span && @active_span.id span_id ||= @parent_span_id unless finished? # sample the trace_operation with the tracer - events.propagate.publish(span, self) + events.propagate.publish(@active_span, self) TraceDigest.new( span_id: span_id, diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index 2af89861469..038bca18bfa 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -362,12 +362,12 @@ def bind_trace_events!(trace_op) event_span_op.service ||= @default_service end - events.propagate.subscribe do |event_span, event_trace_op| - sample_span(event_trace_op, event_span) + events.propagate.subscribe do |_event_span, event_trace_op| sample_trace(event_trace_op) unless event_trace_op.sampling_priority end events.span_finished.subscribe do |event_span, event_trace_op| + sample_trace(trace_op) unless trace_op.sampling_priority sample_span(event_trace_op, event_span) flush_trace(event_trace_op) end @@ -503,7 +503,6 @@ def sample_span(trace_op, span) # Flush finished spans from the trace buffer, send them to writer. def flush_trace(trace_op) - sample_trace(trace_op) unless trace_op.sampling_priority begin trace = @trace_flush.consume!(trace_op) write(trace) if trace && !trace.empty? From f205d2819f2c93aad93a2a4addd8baaedca1433f Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Wed, 4 Dec 2024 17:45:05 -0500 Subject: [PATCH 3/7] remove previously added test that no longer applies --- spec/datadog/tracing/trace_operation_spec.rb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/spec/datadog/tracing/trace_operation_spec.rb b/spec/datadog/tracing/trace_operation_spec.rb index d168a99f73c..6a1b383b26c 100644 --- a/spec/datadog/tracing/trace_operation_spec.rb +++ b/spec/datadog/tracing/trace_operation_spec.rb @@ -136,22 +136,6 @@ end context 'given' do - context ':trace_operation_samples' do - let(:tracer) { instance_double(Datadog::Tracing::Tracer) } - let(:trace_op) { described_class.new(tracer: tracer) } - - describe '#to_digest' do - before do - allow(tracer).to receive(:sample_trace) - end - - it 'calls tracer.sample_trace' do - expect(tracer).to receive(:sample_trace).with(trace_op) - trace_op.to_digest - end - end - end - context ':agent_sample_rate' do subject(:options) { { agent_sample_rate: agent_sample_rate } } let(:agent_sample_rate) { 0.5 } @@ -2326,7 +2310,8 @@ def span [ :span_before_start, :span_finished, - :trace_finished + :trace_finished, + :propagate, ].each do |event| expect(new_events.send(event).subscriptions).to eq(old_events.send(event).subscriptions) end From e5010164b0984e77536e0dda129e0a59e3d17f90 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Mon, 16 Dec 2024 13:25:28 -0500 Subject: [PATCH 4/7] make check for sampling_priority already set implicit in sample_trace, change event name --- lib/datadog/tracing/trace_operation.rb | 10 +++++----- lib/datadog/tracing/tracer.rb | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index 31c39261665..612dda33f1b 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -311,7 +311,7 @@ def to_digest span_id = @active_span && @active_span.id span_id ||= @parent_span_id unless finished? # sample the trace_operation with the tracer - events.propagate.publish(@active_span, self) + events.trace_propagated.publish(@active_span, self) TraceDigest.new( span_id: span_id, @@ -381,13 +381,13 @@ class Events :span_before_start, :span_finished, :trace_finished, - :propagate + :trace_propagated def initialize @span_before_start = SpanBeforeStart.new @span_finished = SpanFinished.new @trace_finished = TraceFinished.new - @propagate = Propagate.new + @trace_propagated = TracePropagated.new end # Triggered before a span starts. @@ -405,9 +405,9 @@ def initialize end # Triggered when trace is being propagated between applications or contexts - class Propagate < Tracing::Event + class TracePropagated < Tracing::Event def initialize - super(:propagate) + super(:trace_propagated) end end diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index 038bca18bfa..ce58a003ada 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -265,7 +265,7 @@ def continue_trace!(digest, key = nil, &block) # Sample a span, tagging the trace as appropriate. def sample_trace(trace_op) begin - @sampler.sample!(trace_op) + @sampler.sample!(trace_op) if trace_op.sampling_priority.nil? rescue StandardError => e SAMPLE_TRACE_LOG_ONLY_ONCE.run do Datadog.logger.warn { "Failed to sample trace: #{e.class.name} #{e} at #{Array(e.backtrace).first}" } @@ -362,12 +362,12 @@ def bind_trace_events!(trace_op) event_span_op.service ||= @default_service end - events.propagate.subscribe do |_event_span, event_trace_op| - sample_trace(event_trace_op) unless event_trace_op.sampling_priority + events.trace_propagated.subscribe do |_event_span, event_trace_op| + sample_trace(event_trace_op) end events.span_finished.subscribe do |event_span, event_trace_op| - sample_trace(trace_op) unless trace_op.sampling_priority + sample_trace(trace_op) sample_span(event_trace_op, event_span) flush_trace(event_trace_op) end From 5a86486a6196f4c7867ce4775f728c2ae969772f Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Mon, 16 Dec 2024 13:33:41 -0500 Subject: [PATCH 5/7] fix event test --- spec/datadog/tracing/trace_operation_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/datadog/tracing/trace_operation_spec.rb b/spec/datadog/tracing/trace_operation_spec.rb index 6a1b383b26c..4977ef7cdd0 100644 --- a/spec/datadog/tracing/trace_operation_spec.rb +++ b/spec/datadog/tracing/trace_operation_spec.rb @@ -2311,7 +2311,7 @@ def span :span_before_start, :span_finished, :trace_finished, - :propagate, + :trace_propagated, ].each do |event| expect(new_events.send(event).subscriptions).to eq(old_events.send(event).subscriptions) end From f32301edf315603194f1910c8e74891258c89784 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Mon, 16 Dec 2024 13:42:29 -0500 Subject: [PATCH 6/7] remove uneeded span passing into event --- lib/datadog/tracing/trace_operation.rb | 2 +- lib/datadog/tracing/tracer.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index 612dda33f1b..7c1d4fa55a7 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -311,7 +311,7 @@ def to_digest span_id = @active_span && @active_span.id span_id ||= @parent_span_id unless finished? # sample the trace_operation with the tracer - events.trace_propagated.publish(@active_span, self) + events.trace_propagated.publish(self) TraceDigest.new( span_id: span_id, diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index ce58a003ada..9261d2e1d7e 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -362,7 +362,7 @@ def bind_trace_events!(trace_op) event_span_op.service ||= @default_service end - events.trace_propagated.subscribe do |_event_span, event_trace_op| + events.trace_propagated.subscribe do |event_trace_op| sample_trace(event_trace_op) end From 7396654e0f65d88bca8ed8813105eee0e117ad73 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Wed, 18 Dec 2024 14:21:27 -0500 Subject: [PATCH 7/7] switch to propagate! alias for to_digest, add to_digest_without_propagate --- benchmarks/tracing_trace.rb | 20 +++++----- docs/GettingStarted.md | 2 +- lib/datadog/opentelemetry/trace.rb | 5 ++- .../context_composite_executor_service.rb | 2 +- .../tracing/contrib/ethon/multi_patch.rb | 2 +- .../contrib/propagation/sql_comment.rb | 2 +- .../tracing/distributed/propagation.rb | 2 +- lib/datadog/tracing/trace_operation.rb | 37 +++++++++++++++++-- sig/datadog/tracing/trace_operation.rbs | 2 + .../contrib/propagation/sql_comment_spec.rb | 2 +- .../sql_comment_propagation_examples.rb | 4 +- spec/datadog/tracing/trace_operation_spec.rb | 16 ++++++++ .../tracing/tracer_integration_spec.rb | 4 +- spec/datadog/tracing/tracer_spec.rb | 2 +- 14 files changed, 76 insertions(+), 26 deletions(-) diff --git a/benchmarks/tracing_trace.rb b/benchmarks/tracing_trace.rb index 35d1ec8bfae..a34c39089de 100644 --- a/benchmarks/tracing_trace.rb +++ b/benchmarks/tracing_trace.rb @@ -78,13 +78,13 @@ def trace(x, depth) end end - def benchmark_to_digest + def benchmark_propagate! Datadog::Tracing.trace('op.name') do |span, trace| Benchmark.ips do |x| x.config(**benchmark_time) - x.report("trace.to_digest") do - trace.to_digest + x.report("trace.propagate!") do + trace.propagate! end x.save! "#{File.basename(__FILE__)}-results.json" unless VALIDATE_BENCHMARK_MODE @@ -108,13 +108,13 @@ def benchmark_log_correlation end end - def benchmark_to_digest_continue + def benchmark_propagate_continue Datadog::Tracing.trace('op.name') do |span, trace| Benchmark.ips do |x| x.config(**benchmark_time) - x.report("trace.to_digest - Continue") do - digest = trace.to_digest + x.report("trace.propagate! - Continue") do + digest = trace.propagate! Datadog::Tracing.continue_trace!(digest) end @@ -136,7 +136,7 @@ def benchmark_propagation_datadog end Datadog::Tracing.trace('op.name') do |span, trace| - injected_trace_digest = trace.to_digest + injected_trace_digest = trace.propagate! Benchmark.ips do |x| x.config(**benchmark_time) @@ -159,7 +159,7 @@ def benchmark_propagation_trace_context end Datadog::Tracing.trace('op.name') do |span, trace| - injected_trace_digest = trace.to_digest + injected_trace_digest = trace.propagate! Benchmark.ips do |x| x.config(**benchmark_time) @@ -190,9 +190,9 @@ def run_benchmark(&block) TracingTraceBenchmark.new.instance_exec do run_benchmark { benchmark_no_writer } run_benchmark { benchmark_no_network } - run_benchmark { benchmark_to_digest } + run_benchmark { benchmark_propagate! } run_benchmark { benchmark_log_correlation } - run_benchmark { benchmark_to_digest_continue } + run_benchmark { benchmark_propagate_continue } run_benchmark { benchmark_propagation_datadog } run_benchmark { benchmark_propagation_trace_context } end diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 98cade51313..e5bc9ba9667 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -2418,7 +2418,7 @@ On the client: ```ruby Datadog::Tracing.trace('web.call') do |span, trace| # Inject trace headers into request headers (`env` must be a Hash) - Datadog::Tracing::Contrib::HTTP.inject(trace.to_digest, env) + Datadog::Tracing::Contrib::HTTP.inject(trace.propagate!, env) end ``` diff --git a/lib/datadog/opentelemetry/trace.rb b/lib/datadog/opentelemetry/trace.rb index e05dd6cb176..32f12d5e470 100644 --- a/lib/datadog/opentelemetry/trace.rb +++ b/lib/datadog/opentelemetry/trace.rb @@ -17,7 +17,7 @@ def start_trace_copy(trace, parent_span: nil) digest = if parent_span digest_with_parent_span(trace, parent_span) else - trace.to_digest + trace.to_digest_without_propagate end # Create a new TraceOperation, attached to the current Datadog Tracer. @@ -30,7 +30,8 @@ def start_trace_copy(trace, parent_span: nil) # This supports the implementation of `OpenTelemetry::Trace.context_with_span`, # which allows you to specific any span as the arbitrary parent of a new span. def digest_with_parent_span(trace, parent_span) - digest = trace.to_digest + # sampling_priority added here right upon otel span creation + digest = trace.to_digest_without_propagate Tracing::TraceDigest.new( span_id: parent_span.id, diff --git a/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb b/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb index e80baca6cf0..5ab6c126d70 100644 --- a/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +++ b/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb @@ -19,7 +19,7 @@ def initialize(composited_executor) # post method runs the task within composited executor - in a different thread. The original arguments are # captured to be propagated to the composited executor post method def post(*args, &task) - digest = Tracing.active_trace && Tracing.active_trace.to_digest + digest = Tracing.active_trace && Tracing.active_trace.propagate! executor = @composited_executor.is_a?(Symbol) ? Concurrent.executor(@composited_executor) : @composited_executor # Pass the original arguments to the composited executor, which diff --git a/lib/datadog/tracing/contrib/ethon/multi_patch.rb b/lib/datadog/tracing/contrib/ethon/multi_patch.rb index b8541155a35..e4456d521cb 100644 --- a/lib/datadog/tracing/contrib/ethon/multi_patch.rb +++ b/lib/datadog/tracing/contrib/ethon/multi_patch.rb @@ -62,7 +62,7 @@ def datadog_multi_span Ext::SPAN_MULTI_REQUEST, service: datadog_configuration[:service_name] ) - @datadog_multi_trace_digest = Tracing.active_trace.to_digest + @datadog_multi_trace_digest = Tracing.active_trace.propagate! @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_MULTI_REQUEST) diff --git a/lib/datadog/tracing/contrib/propagation/sql_comment.rb b/lib/datadog/tracing/contrib/propagation/sql_comment.rb index 62765f026ec..c68f319ba12 100644 --- a/lib/datadog/tracing/contrib/propagation/sql_comment.rb +++ b/lib/datadog/tracing/contrib/propagation/sql_comment.rb @@ -45,7 +45,7 @@ def self.prepend_comment(sql, span_op, trace_op, mode) # When tracing is disabled, trace_operation is a dummy object that does not contain data to build traceparent if config.tracing.enabled tags[Ext::KEY_TRACEPARENT] = - Tracing::Distributed::TraceContext.new(fetcher: nil).send(:build_traceparent, trace_op.to_digest) + Tracing::Distributed::TraceContext.new(fetcher: nil).send(:build_traceparent, trace_op.propagate!) else Datadog.logger.warn( 'Sql comment propagation with `full` mode is aborted, because tracing is disabled. '\ diff --git a/lib/datadog/tracing/distributed/propagation.rb b/lib/datadog/tracing/distributed/propagation.rb index 9ad8b63ee35..cf1e4183745 100644 --- a/lib/datadog/tracing/distributed/propagation.rb +++ b/lib/datadog/tracing/distributed/propagation.rb @@ -56,7 +56,7 @@ def inject!(digest, data) return nil end - digest = digest.to_digest if digest.respond_to?(:to_digest) + digest = digest.propagate! if digest.respond_to?(:propagate!) if digest.trace_id.nil? ::Datadog.logger.debug('Cannot inject distributed trace data: digest.trace_id is nil.') diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index 7c1d4fa55a7..bc5dd1db837 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -301,11 +301,42 @@ def flush! build_trace(spans, !finished) end + # DEV-3.0: Sampling is a side effect of generating the digest in to_digest. With 3.0 we should remove the side effect + # and push users to use propagate! instead of to_digest. With that we can remove this method. + def to_digest_no_propagation + span_id = @active_span && @active_span.id + span_id ||= @parent_span_id unless finished? + TraceDigest.new( + span_id: span_id, + span_name: (@active_span && @active_span.name), + span_resource: (@active_span && @active_span.resource), + span_service: (@active_span && @active_span.service), + span_type: (@active_span && @active_span.type), + trace_distributed_tags: distributed_tags, + trace_hostname: @hostname, + trace_id: @id, + trace_name: name, + trace_origin: @origin, + trace_process_id: Core::Environment::Identity.pid, + trace_resource: resource, + trace_runtime_id: Core::Environment::Identity.id, + trace_sampling_priority: @sampling_priority, + trace_service: service, + trace_state: @trace_state, + trace_state_unknown_fields: @trace_state_unknown_fields, + span_remote: (@remote_parent && @active_span.nil?), + ).freeze + end + + def propagate! + to_digest + end + # Returns a set of trace headers used for continuing traces. # Used for propagation across execution contexts. # Data should reflect the active state of the trace. - # DEV-3.0: Sampling is a side effect of generating the digest. - # We should move the sample call to inject and right before moving to new contexts(threads, forking etc.) + # DEV-3.0: Sampling is a side effect of generating the digest in to_digest. + # With 3.0 we should remove the side effect and push users to use propagate! instead of to_digest. def to_digest # Resolve current span ID span_id = @active_span && @active_span.id @@ -523,7 +554,7 @@ def build_trace(spans, partial = false) end # Returns tracer tags that will be propagated if this span's context - # is exported through {.to_digest}. + # is exported through {.propagate!}. # @return [Hash] key value pairs of distributed tags def distributed_tags meta.select { |name, _| name.start_with?(Metadata::Ext::Distributed::TAGS_PREFIX) } diff --git a/sig/datadog/tracing/trace_operation.rbs b/sig/datadog/tracing/trace_operation.rbs index e434c9872d6..85245e75954 100644 --- a/sig/datadog/tracing/trace_operation.rbs +++ b/sig/datadog/tracing/trace_operation.rbs @@ -39,6 +39,8 @@ module Datadog def build_span: (untyped op_name, ?events: untyped?, ?on_error: untyped?, ?resource: untyped?, ?service: untyped?, ?start_time: untyped?, ?tags: untyped?, ?type: untyped?) -> untyped def flush!: () { (untyped) -> untyped } -> untyped def to_digest: () -> untyped + def propagate!: () -> untyped + def to_digest_without_propagate: () -> untyped def fork_clone: () -> untyped class Events diff --git a/spec/datadog/tracing/contrib/propagation/sql_comment_spec.rb b/spec/datadog/tracing/contrib/propagation/sql_comment_spec.rb index 9217b684fa2..91bf84721d9 100644 --- a/spec/datadog/tracing/contrib/propagation/sql_comment_spec.rb +++ b/spec/datadog/tracing/contrib/propagation/sql_comment_spec.rb @@ -66,7 +66,7 @@ end let(:trace_op) do double( - to_digest: Datadog::Tracing::TraceDigest.new( + propagate!: Datadog::Tracing::TraceDigest.new( trace_id: 0xC0FFEE, span_id: 0xBEE, trace_flags: 0xFE diff --git a/spec/datadog/tracing/contrib/sql_comment_propagation_examples.rb b/spec/datadog/tracing/contrib/sql_comment_propagation_examples.rb index 0c401a74648..70da8f41357 100644 --- a/spec/datadog/tracing/contrib/sql_comment_propagation_examples.rb +++ b/spec/datadog/tracing/contrib/sql_comment_propagation_examples.rb @@ -69,7 +69,7 @@ expect(Datadog::Tracing::Contrib::Propagation::SqlComment).to have_received(:prepend_comment).with( sql_statement, a_span_operation_with(service: service_name), - duck_type(:to_digest), + duck_type(:propagate!), propagation_mode ) end @@ -90,7 +90,7 @@ expect(Datadog::Tracing::Contrib::Propagation::SqlComment).to have_received(:prepend_comment).with( sql_statement, a_span_operation_with(service: service_name), - duck_type(:to_digest), + duck_type(:propagate!), propagation_mode ) end diff --git a/spec/datadog/tracing/trace_operation_spec.rb b/spec/datadog/tracing/trace_operation_spec.rb index 4977ef7cdd0..a4ba92226e3 100644 --- a/spec/datadog/tracing/trace_operation_spec.rb +++ b/spec/datadog/tracing/trace_operation_spec.rb @@ -136,6 +136,22 @@ end context 'given' do + context ':trace_operation_triggers_trace_propagated_event' do + let(:events) { instance_double('Events') } + let(:trace_propagated) { instance_double('TracePropagated') } + let(:trace_op) { described_class.new(events: events) } + before do + allow(events).to receive(:trace_propagated).and_return(trace_propagated) + allow(trace_propagated).to receive(:publish) + end + describe '#propagate!' do + it 'calls events.trace_propagated.publish with self' do + expect(trace_propagated).to receive(:publish).with(trace_op) + trace_op.to_digest + end + end + end + context ':agent_sample_rate' do subject(:options) { { agent_sample_rate: agent_sample_rate } } let(:agent_sample_rate) { 0.5 } diff --git a/spec/datadog/tracing/tracer_integration_spec.rb b/spec/datadog/tracing/tracer_integration_spec.rb index e7f1f3b0462..c4a3e2a3670 100644 --- a/spec/datadog/tracing/tracer_integration_spec.rb +++ b/spec/datadog/tracing/tracer_integration_spec.rb @@ -84,7 +84,7 @@ def lang_tag(span) workers = nil tracer.trace('start_inserts', resource: 'inventory') do - trace_digest = trace.to_digest + trace_digest = trace.propagate! workers = Array.new(5) do |index| Thread.new do @@ -305,7 +305,7 @@ def lang_tag(span) describe 'distributed trace' do let(:extract) { Datadog::Tracing::Contrib::HTTP.extract(rack_headers) } let(:trace) { Datadog::Tracing.continue_trace!(extract) } - let(:inject) { {}.tap { |env| Datadog::Tracing::Contrib::HTTP.inject(trace.to_digest, env) } } + let(:inject) { {}.tap { |env| Datadog::Tracing::Contrib::HTTP.inject(trace.propagate!, env) } } let(:rack_headers) { headers.map { |k, v| [RackSupport.header_to_rack(k), v] }.to_h } diff --git a/spec/datadog/tracing/tracer_spec.rb b/spec/datadog/tracing/tracer_spec.rb index 945b3884e25..8d42cac80d8 100644 --- a/spec/datadog/tracing/tracer_spec.rb +++ b/spec/datadog/tracing/tracer_spec.rb @@ -893,7 +893,7 @@ trace_state_unknown_fields: 'any;field', ) expect(digest.span_remote).to be true - expect(trace.to_digest.span_remote).to be false + expect(trace.propagate!.span_remote).to be false expect(trace.send(:distributed_tags)).to eq('_dd.p.test' => 'value')