From e9b2cd709f2db4e24534431012f1862f2156fbd4 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Wed, 25 Sep 2024 13:19:14 -0400 Subject: [PATCH] update trace operation to take tracer for sampling --- lib/datadog/tracing/trace_operation.rb | 7 +++++-- lib/datadog/tracing/tracer.rb | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index ac820d2ecf1..833b7954b81 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -75,7 +75,9 @@ def initialize( metrics: nil, trace_state: nil, trace_state_unknown_fields: nil, - remote_parent: false + remote_parent: false, + tracer: nil + ) # Attributes @id = id || Tracing::Utils::TraceId.next_id @@ -98,6 +100,7 @@ def initialize( @profiling_enabled = profiling_enabled @trace_state = trace_state @trace_state_unknown_fields = trace_state_unknown_fields + @tracer = tracer # Generic tags set_tags(tags) if tags @@ -291,7 +294,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 sampled? + tracer&.sample_trace(self) unless priority_sampled? TraceDigest.new( span_id: span_id, diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index a16384ed857..952074fff8e 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -331,12 +331,14 @@ def build_trace(digest = nil) trace_state: digest.trace_state, trace_state_unknown_fields: digest.trace_state_unknown_fields, remote_parent: digest.span_remote, + tracer: self ) else TraceOperation.new( hostname: hostname, profiling_enabled: profiling_enabled, remote_parent: false, + tracer: self ) end end