From 09b7afdcf8721586c1efcf51953a8d5c9ac9b767 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Tue, 24 Sep 2024 20:35:46 -0400 Subject: [PATCH] sample before digest --- lib/datadog/tracing/distributed/propagation.rb | 1 + lib/datadog/tracing/trace_operation.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/distributed/propagation.rb b/lib/datadog/tracing/distributed/propagation.rb index 9ab993eb56e..9ad8b63ee35 100644 --- a/lib/datadog/tracing/distributed/propagation.rb +++ b/lib/datadog/tracing/distributed/propagation.rb @@ -44,6 +44,7 @@ def initialize( # DEV-2.0: if needed. # DEV-2.0: Ideally, we'd have a separate stream to report tracer errors and never # DEV-2.0: touch the active span. + # DEV-3.0: Sample trace here instead of when generating digest. # # @param digest [TraceDigest] # @param data [Hash] diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index 9ebaf46ef85..42f68afb305 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -2,7 +2,7 @@ require_relative '../core/environment/identity' require_relative '../core/utils' - +require_relative 'tracer' require_relative 'event' require_relative 'metadata/tagging' require_relative 'sampling/ext' @@ -284,10 +284,14 @@ def flush! # 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.) def to_digest # Resolve current span ID 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) TraceDigest.new( span_id: span_id,