Skip to content

Commit

Permalink
sample before digest generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZStriker19 committed Sep 24, 2024
1 parent 4ef9fbd commit c44cd80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 1 addition & 5 deletions lib/datadog/tracing/distributed/propagation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
25 changes: 24 additions & 1 deletion lib/datadog/tracing/trace_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -352,7 +376,6 @@ def fork_clone
# Callback behavior
class Events
include Tracing::Events

attr_reader \
:span_before_start,
:span_finished,
Expand Down

0 comments on commit c44cd80

Please sign in to comment.