Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample before propagation, context switching, and writing #3866

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sample before digest generation
  • Loading branch information
ZStriker19 committed Sep 24, 2024
commit c846f06e64dfcd155445e3077bc73c27a5530879
6 changes: 1 addition & 5 deletions lib/datadog/tracing/distributed/propagation.rb
Original file line number Diff line number Diff line change
@@ -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-3.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
25 changes: 24 additions & 1 deletion lib/datadog/tracing/trace_operation.rb
Original file line number Diff line number Diff line change
@@ -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,