Skip to content

Commit

Permalink
Merge branch 'ivana/potel/port-sample-rate-update' of github.com:gets…
Browse files Browse the repository at this point in the history
…entry/sentry-python into ivana/potel/port-sample-rate-update
  • Loading branch information
antonpirker committed Feb 28, 2025
2 parents e434be1 + f60670c commit eb93d9c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
14 changes: 2 additions & 12 deletions sentry_sdk/integrations/opentelemetry/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ def get_parent_sample_rate(parent_context, trace_id):
return None


def _update_sample_rate(sample_rate, trace_state):
# type: (float, TraceState) -> TraceState
if TRACESTATE_SAMPLE_RATE_KEY in trace_state:
trace_state = trace_state.update(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))
else:
trace_state = trace_state.add(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))

return trace_state


def dropped_result(parent_span_context, attributes, sample_rate=None):
# type: (SpanContext, Attributes, Optional[float]) -> SamplingResult
# these will only be added the first time in a root span sampling decision
Expand All @@ -92,7 +82,7 @@ def dropped_result(parent_span_context, attributes, sample_rate=None):
trace_state = trace_state.update(TRACESTATE_SAMPLED_KEY, "false")

if sample_rate is not None:
trace_state = _update_sample_rate(sample_rate, trace_state)
trace_state = trace_state.update(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))

is_root_span = not (
parent_span_context.is_valid and not parent_span_context.is_remote
Expand Down Expand Up @@ -130,7 +120,7 @@ def sampled_result(span_context, attributes, sample_rate):
trace_state = trace_state.update(TRACESTATE_SAMPLED_KEY, "true")

if sample_rate is not None:
trace_state = _update_sample_rate(sample_rate, trace_state)
trace_state = trace_state.update(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))

return SamplingResult(
Decision.RECORD_AND_SAMPLE,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def my_traces_sampler(sampling_context):
if test_data["sentry_trace_header_parent_sampled"] is None:
sentry_trace = f"{incoming_trace_id}-1234567890abcdef"
else:
sentry_trace = f"{incoming_trace_id}-1234567890abcdef-{test_data["sentry_trace_header_parent_sampled"]}"
sentry_trace = f"{incoming_trace_id}-1234567890abcdef-{test_data['sentry_trace_header_parent_sampled']}"

baggage = (
f"sentry-trace_id={incoming_trace_id}, "
Expand Down

0 comments on commit eb93d9c

Please sign in to comment.