Skip to content

Commit ad24b0c

Browse files
committed
Merge branch 'potel-base' into ivana/potel/fix-strawberry
2 parents ab4432c + 94f06e6 commit ad24b0c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

sentry_sdk/integrations/opentelemetry/sampler.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ def get_parent_sampled(parent_context, trace_id):
4848

4949
def dropped_result(span_context, attributes, sample_rate=None):
5050
# type: (SpanContext, Attributes, Optional[float]) -> SamplingResult
51-
# note that trace_state.add will NOT overwrite existing entries
52-
# so these will only be added the first time in a root span sampling decision
53-
trace_state = span_context.trace_state.add(TRACESTATE_SAMPLED_KEY, "false")
54-
if sample_rate:
51+
# these will only be added the first time in a root span sampling decision
52+
trace_state = span_context.trace_state
53+
54+
if TRACESTATE_SAMPLED_KEY not in trace_state:
55+
trace_state = trace_state.add(TRACESTATE_SAMPLED_KEY, "false")
56+
57+
if sample_rate and TRACESTATE_SAMPLE_RATE_KEY not in trace_state:
5558
trace_state = trace_state.add(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))
5659

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

6467
def sampled_result(span_context, attributes, sample_rate):
6568
# type: (SpanContext, Attributes, float) -> SamplingResult
66-
# note that trace_state.add will NOT overwrite existing entries
67-
# so these will only be added the first time in a root span sampling decision
68-
trace_state = span_context.trace_state.add(TRACESTATE_SAMPLED_KEY, "true").add(
69-
TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate)
70-
)
69+
# these will only be added the first time in a root span sampling decision
70+
trace_state = span_context.trace_state
71+
72+
if TRACESTATE_SAMPLED_KEY not in trace_state:
73+
trace_state = trace_state.add(TRACESTATE_SAMPLED_KEY, "true")
74+
if TRACESTATE_SAMPLE_RATE_KEY not in trace_state:
75+
trace_state = trace_state.add(TRACESTATE_SAMPLE_RATE_KEY, str(sample_rate))
7176

7277
return SamplingResult(
7378
Decision.RECORD_AND_SAMPLE,

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ envlist =
117117
# Falcon
118118
{py3.7}-falcon-v{1,1.4,2}
119119
{py3.7,py3.11,py3.12}-falcon-v{3}
120+
{py3.8,py3.11,py3.12}-falcon-v{4}
120121
{py3.7,py3.11,py3.12}-falcon-latest
121122

122123
# FastAPI
@@ -427,6 +428,8 @@ deps =
427428
falcon-v1: falcon~=1.0
428429
falcon-v2: falcon~=2.0
429430
falcon-v3: falcon~=3.0
431+
# TODO: update to 4.0 stable when out
432+
falcon-v4: falcon==4.0.0b3
430433
falcon-latest: falcon
431434

432435
# FastAPI

0 commit comments

Comments
 (0)