From 7203b5188769a87377cfb58066dc4db8a7972c1e Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Tue, 24 Sep 2024 21:04:24 -0400 Subject: [PATCH] sample trace before flush unless already sampled --- lib/datadog/tracing/tracer.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index a16384ed85..8634ca891d 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -494,7 +494,11 @@ def sample_span(trace_op, span) def flush_trace(trace_op) begin trace = @trace_flush.consume!(trace_op) - write(trace) if trace && !trace.empty? + if trace && !trace.empty? + # check if trace is not sampled + sample_trace(trace) unless trace.sampled? + write(trace) + end rescue StandardError => e FLUSH_TRACE_LOG_ONLY_ONCE.run do Datadog.logger.warn { "Failed to flush trace: #{e.class.name} #{e} at #{Array(e.backtrace).first}" }