From 4ef9fbda1c9bbe6b3dba11d103f38e2930689f93 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Tue, 24 Sep 2024 16:12:05 -0400 Subject: [PATCH] sample on trace flush --- lib/datadog/tracing/tracer.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index c36d4d31479..f65b32ad596 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -44,8 +44,7 @@ class Tracer # @param default_service [String] A fallback value for {Datadog::Tracing::Span#service}, as spans without # service are rejected # @param enabled [Boolean] set if the tracer submits or not spans to the local agent - # @param - sampler [Datadog::Tracing::Sampler] a tracer sampler, responsible for filtering out spans when needed + # @param sampler [Datadog::Tracing::Sampler] a tracer sampler, responsible for filtering out spans when needed # @param tags [Hash] default tags added to all spans # @param writer [Datadog::Tracing::Writer] consumes traces returned by the provided +trace_flush+ def initialize( @@ -503,7 +502,10 @@ 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? + sample(trace) + 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}" }