Skip to content

Commit 09070aa

Browse files
merge master
2 parents 1356704 + 7b1b1cb commit 09070aa

5 files changed

Lines changed: 25 additions & 21 deletions

File tree

‎sentry_sdk/scope.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,17 @@ def start_transaction(
11881188
"parent_sampled": transaction.parent_sampled,
11891189
}
11901190
sampling_context.update(custom_sampling_context)
1191+
1192+
keep_incoming_sample_rate = (
1193+
transaction.sampled is None
1194+
and transaction.parent_sampled is not None
1195+
and not callable(client.options.get("traces_sampler"))
1196+
)
1197+
11911198
transaction._set_initial_sampling_decision(sampling_context=sampling_context)
11921199

11931200
# update the sample rate in the dsc
1194-
if transaction.sample_rate is not None:
1201+
if transaction.sample_rate is not None and not keep_incoming_sample_rate:
11951202
propagation_context = self.get_active_propagation_context()
11961203
baggage = propagation_context.baggage
11971204

@@ -1337,7 +1344,12 @@ def start_streamed_span(
13371344
self,
13381345
)
13391346

1340-
if sample_rate is not None:
1347+
keep_incoming_sample_rate = (
1348+
propagation_context.parent_sampled is not None
1349+
and not callable(self.get_client().options.get("traces_sampler"))
1350+
)
1351+
1352+
if sample_rate is not None and not keep_incoming_sample_rate:
13411353
self._update_sample_rate(sample_rate)
13421354

13431355
if sampled is False or sampled is None:

‎tests/integrations/stdlib/test_httplib.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def getresponse(self, *args, **kwargs):
457457
expected_outgoing_baggage = (
458458
"sentry-trace_id=771a43a4192642f0b136d5159a501700,"
459459
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
460-
"sentry-sample_rate=1.0,"
460+
"sentry-sample_rate=0.01337,"
461461
"sentry-user_id=Am%C3%A9lie,"
462462
"sentry-sample_rand=0.000005,"
463463
"sentry-sampled=true"
@@ -487,7 +487,7 @@ def getresponse(self, *args, **kwargs):
487487
expected_outgoing_baggage = (
488488
"sentry-trace_id=771a43a4192642f0b136d5159a501700,"
489489
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
490-
"sentry-sample_rate=1.0,"
490+
"sentry-sample_rate=0.01337,"
491491
"sentry-user_id=Am%C3%A9lie,"
492492
"sentry-sample_rand=0.000005,"
493493
"sentry-sampled=true"

‎tests/test_dsc.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes):
201201
dsn="https://mysecret@o1234.ingest.sentry.io/12312012",
202202
release="myapp@0.0.1",
203203
environment="canary",
204-
traces_sample_rate=1.0,
204+
traces_sample_rate=0.5,
205205
transport=TestTransportWithOptions,
206206
)
207207
envelopes = capture_envelopes()
@@ -244,7 +244,7 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes):
244244

245245
assert "sample_rate" in envelope_trace_header
246246
assert type(envelope_trace_header["sample_rate"]) == str
247-
assert envelope_trace_header["sample_rate"] == "1.0"
247+
assert envelope_trace_header["sample_rate"] == "0.01337"
248248

249249
assert "sampled" in envelope_trace_header
250250
assert type(envelope_trace_header["sampled"]) == str
@@ -272,7 +272,7 @@ def test_dsc_continuation_of_trace_span_streaming(sentry_init, capture_envelopes
272272
dsn="https://mysecret@o1234.ingest.sentry.io/12312012",
273273
release="myapp@0.0.1",
274274
environment="canary",
275-
traces_sample_rate=1.0,
275+
traces_sample_rate=0.5,
276276
trace_lifecycle="stream",
277277
transport=TestTransportWithOptions,
278278
)
@@ -318,7 +318,7 @@ def test_dsc_continuation_of_trace_span_streaming(sentry_init, capture_envelopes
318318

319319
assert "sample_rate" in envelope_trace_header
320320
assert type(envelope_trace_header["sample_rate"]) == str
321-
assert envelope_trace_header["sample_rate"] == "1.0"
321+
assert envelope_trace_header["sample_rate"] == "0.01337"
322322

323323
assert "sampled" in envelope_trace_header
324324
assert type(envelope_trace_header["sampled"]) == str

‎tests/tracing/test_integration_tests.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_continue_trace(sentry_init, capture_envelopes, parent_sampled, sample_r
189189
)
190190

191191
if parent_sampled is not None:
192-
expected_sample_rate = str(float(parent_sampled))
192+
expected_sample_rate = "0.01337"
193193
else:
194194
expected_sample_rate = str(sample_rate)
195195

@@ -262,7 +262,7 @@ def test_continue_trace_span_streaming(
262262
assert not baggage.mutable
263263

264264
if parent_sampled is not None:
265-
expected_sample_rate = str(float(parent_sampled))
265+
expected_sample_rate = parent_sample_rate
266266
else:
267267
if sample_rate is None:
268268
expected_sample_rate = parent_sample_rate
@@ -312,7 +312,7 @@ def test_continue_trace_span_streaming(
312312
)
313313

314314
if parent_sampled is not None:
315-
expected_sample_rate = str(float(parent_sampled))
315+
expected_sample_rate = parent_sample_rate
316316
else:
317317
if sample_rate is None:
318318
expected_sample_rate = parent_sample_rate

‎tests/tracing/test_span_streaming.py‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,12 +1082,7 @@ def test_outgoing_traceparent_and_baggage_incoming_trace(
10821082
baggage_items = dict(tuple(item.split("=")) for item in baggage.split(","))
10831083

10841084
# As we've received incoming baggage, we shouldn't modify it ourselves
1085-
# and should propagate it as-is. However, in the case where our
1086-
# effective sample rate overrides the parent sample rate, we update the
1087-
# sample rate in the baggage as a consequence of updating the sample rate
1088-
# in the DSC.
1089-
if traces_sample_rate is not None:
1090-
incoming_baggage["sentry-sample_rate"] = str(float(parent_sampled))
1085+
# and should propagate it as-is
10911086

10921087
assert baggage_items == incoming_baggage
10931088

@@ -1133,12 +1128,9 @@ def test_outgoing_traceparent_and_baggage_inconsistent_incoming_trace(
11331128
span_id = span.span_id
11341129
assert traceparent == f"{trace_id}-{span_id}-0"
11351130

1136-
# We shouldn't be updating incoming baggage, but in the case where our
1137-
# effective sample rate overrides the parent sample rate, we do this as
1138-
# a consequence of updating the sample rate in the DSC.
1131+
# We shouldn't be updating incoming baggage
11391132
baggage = sentry_sdk.get_baggage()
11401133
baggage_items = dict(tuple(item.split("=")) for item in baggage.split(","))
1141-
incoming_baggage["sentry-sample_rate"] = "0.0"
11421134
assert baggage_items == incoming_baggage
11431135

11441136

0 commit comments

Comments
 (0)