Skip to content
Merged
Changes from all commits
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
23 changes: 14 additions & 9 deletions sentry_sdk/integrations/opentelemetry/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ def get_parent_sampled(parent_context, trace_id):

def dropped_result(span_context, attributes, sample_rate=None):
# type: (SpanContext, Attributes, Optional[float]) -> SamplingResult
# note that trace_state.add will NOT overwrite existing entries
# so these will only be added the first time in a root span sampling decision
trace_state = span_context.trace_state.add(TRACESTATE_SAMPLED_KEY, "false")
if sample_rate:
# these will only be added the first time in a root span sampling decision
trace_state = span_context.trace_state

if TRACESTATE_SAMPLED_KEY not in trace_state:
trace_state = trace_state.add(TRACESTATE_SAMPLED_KEY, "false")

if sample_rate and TRACESTATE_SAMPLE_RATE_KEY not in trace_state:
trace_state = trace_state.add(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))

return SamplingResult(
Expand All @@ -63,11 +66,13 @@ def dropped_result(span_context, attributes, sample_rate=None):

def sampled_result(span_context, attributes, sample_rate):
# type: (SpanContext, Attributes, float) -> SamplingResult
# note that trace_state.add will NOT overwrite existing entries
# so these will only be added the first time in a root span sampling decision
trace_state = span_context.trace_state.add(TRACESTATE_SAMPLED_KEY, "true").add(
TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate)
)
# these will only be added the first time in a root span sampling decision
trace_state = span_context.trace_state

if TRACESTATE_SAMPLED_KEY not in trace_state:
trace_state = trace_state.add(TRACESTATE_SAMPLED_KEY, "true")
if TRACESTATE_SAMPLE_RATE_KEY not in trace_state:
trace_state = trace_state.add(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))

return SamplingResult(
Decision.RECORD_AND_SAMPLE,
Expand Down
Loading