From c44cd804d80ee550adc884b741eb9f78597c4f41 Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Tue, 24 Sep 2024 18:03:24 -0400 Subject: [PATCH] sample before digest generation --- .../tracing/distributed/propagation.rb | 6 +---- lib/datadog/tracing/trace_operation.rb | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/datadog/tracing/distributed/propagation.rb b/lib/datadog/tracing/distributed/propagation.rb index b4211edd645..0e14259157d 100644 --- a/lib/datadog/tracing/distributed/propagation.rb +++ b/lib/datadog/tracing/distributed/propagation.rb @@ -43,6 +43,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-2.0: Sample trace here instead of when generating digest. # # @param digest [TraceDigest] # @param data [Hash] @@ -62,11 +63,6 @@ def inject!(digest, data) end result = false - # Probably sample here - # Do we need to update tags on the parent span here first? - # That should probably be done in the tracer, not here. - # Can we sample off of digest or do we need to grab the parent span? - # Looking at how we do span sampling would be helpful to answer some of this. components.sampler.sample!(digest) # Inject all configured propagation styles diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index 9ebaf46ef85..e9e096181ef 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -161,6 +161,28 @@ def resource @resource || (root_span && root_span.resource) end + + def get_tag(key) + super || (root_span && root_span.get_tag(key)) + end + + def get_metric(key) + @metric[key?] || (root_span && root_span.get_metric(key)) + end + + def tags + all_tags = {} + all_tags.merge(root_span.tags) if root_span + all_tags.merge(@tags) + all_tags.merge(@metrics) + all_tags + end + + + + @resource || (root_span && root_span.resource) + end + # Returns true if the resource has been explicitly set # # @return [Boolean] @@ -285,6 +307,8 @@ def flush! # Used for propagation across execution contexts. # Data should reflect the active state of the trace. def to_digest + # 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.) # Resolve current span ID span_id = @active_span && @active_span.id span_id ||= @parent_span_id unless finished? @@ -352,7 +376,6 @@ def fork_clone # Callback behavior class Events include Tracing::Events - attr_reader \ :span_before_start, :span_finished,