Skip to content

Commit

Permalink
commenting it up trying to figure out how to move sampling around
Browse files Browse the repository at this point in the history
  • Loading branch information
ZStriker19 committed Aug 23, 2024
1 parent 708bf9b commit 1aac39b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/datadog/tracing/distributed/propagation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ 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
@propagation_style_inject.each do |propagator|
Expand Down
15 changes: 12 additions & 3 deletions lib/datadog/tracing/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ 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(
Expand Down Expand Up @@ -317,7 +318,7 @@ def build_trace(digest = nil)
# Resolve hostname if configured
hostname = Core::Environment::Socket.hostname if Datadog.configuration.tracing.report_hostname
hostname = hostname && !hostname.empty? ? hostname : nil

# So we can build traces out of digests
if digest
TraceOperation.new(
hostname: hostname,
Expand All @@ -342,15 +343,23 @@ def build_trace(digest = nil)
end

def bind_trace_events!(trace_op)
# need to find out what trace_op.send does
# ok trace_op is just a trace and we run bind_trace_events right after
# build_trace
# and what events is.
# events is probably just all the spans
events = trace_op.send(:events)

# so we loop through all the spans and trace sample them if they're the root span
# and span sample all of them as well.
events.span_before_start.subscribe do |event_span_op, event_trace_op|
event_trace_op.service ||= @default_service
event_span_op.service ||= @default_service
# here's where we sample for the trace rn
sample_trace(event_trace_op) if event_span_op && event_span_op.parent_id == 0
end

events.span_finished.subscribe do |event_span, event_trace_op|
# then span sampling is done here
sample_span(event_trace_op, event_span)
flush_trace(event_trace_op)
end
Expand Down

0 comments on commit 1aac39b

Please sign in to comment.