Skip to content

Commit 0064118

Browse files
committed
Updated test
1 parent 1a09fc5 commit 0064118

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

tests/test_dsc.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ def my_traces_sampler(sampling_context):
218218
@pytest.mark.parametrize(
219219
"test_data, expected_sample_rate, expected_sampled",
220220
[
221+
# Test data:
222+
# "incoming_sample_rate":
223+
# The "sentry-sample_rate" in the incoming `baggage` header.
224+
# "incoming_sampled":
225+
# The "sentry-sampled" in the incoming `baggage` header.
226+
# "sentry_trace_header_parent_sampled":
227+
# The number at the end in the `sentry-trace` header, called "parent_sampled".
228+
# "use_local_traces_sampler":
229+
# Whether the local traces sampler is used.
230+
# "local_traces_sampler_result":
231+
# The result of the local traces sampler.
232+
# "local_traces_sample_rate":
233+
# The `traces_sample_rate` setting in the local `sentry_init` call.
221234
(
222235
{
223236
"incoming_sample_rate": 1.0,
@@ -252,7 +265,7 @@ def my_traces_sampler(sampling_context):
252265
"local_traces_sample_rate": 0.7,
253266
},
254267
None, # expected_sample_rate
255-
"tracing-disabled-no-transactions-should-be-sent", # expected_sampled
268+
"tracing-disabled-no-transactions-should-be-sent", # expected_sampled (because the parent sampled is 0)
256269
),
257270
(
258271
{
@@ -264,7 +277,7 @@ def my_traces_sampler(sampling_context):
264277
"local_traces_sample_rate": 0.7,
265278
},
266279
0.5, # expected_sample_rate
267-
"false", # expected_sampled
280+
"false", # expected_sampled (traces sampler can override parent sampled)
268281
),
269282
(
270283
{
@@ -276,7 +289,7 @@ def my_traces_sampler(sampling_context):
276289
"local_traces_sample_rate": None,
277290
},
278291
None, # expected_sample_rate
279-
"tracing-disabled-no-transactions-should-be-sent", # expected_sampled
292+
"tracing-disabled-no-transactions-should-be-sent", # expected_sampled (traces_sample_rate=None disables all transaction creation)
280293
),
281294
(
282295
{
@@ -288,7 +301,7 @@ def my_traces_sampler(sampling_context):
288301
"local_traces_sample_rate": None,
289302
},
290303
0.5, # expected_sample_rate
291-
"true", # expected_sampled
304+
"true", # expected_sampled (traces sampler overrides the traces_sample_rate setting, so transactions are created)
292305
),
293306
(
294307
{
@@ -300,7 +313,7 @@ def my_traces_sampler(sampling_context):
300313
"local_traces_sample_rate": None,
301314
},
302315
None, # expected_sample_rate
303-
"tracing-disabled-no-transactions-should-be-sent", # expected_sampled
316+
"tracing-disabled-no-transactions-should-be-sent", # expected_sampled (traces_sample_rate=None disables all transaction creation)
304317
),
305318
(
306319
{
@@ -317,7 +330,7 @@ def my_traces_sampler(sampling_context):
317330
(
318331
{
319332
"incoming_sample_rate": 1.0,
320-
"incoming_sampled": "true",
333+
"incoming_sampled": None,
321334
"sentry_trace_header_parent_sampled": None,
322335
"use_local_traces_sampler": False,
323336
"local_traces_sampler_result": 0.5,
@@ -330,13 +343,13 @@ def my_traces_sampler(sampling_context):
330343
ids=(
331344
"1 traces_sample_rate does not override incoming",
332345
"2 traces_sampler overrides incoming",
333-
"3 traces_sample_rate does not overrides incoming (incoming not sampled)",
346+
"3 traces_sample_rate does not overrides incoming sample rate or parent (incoming not sampled)",
334347
"4 traces_sampler overrides incoming (incoming not sampled)",
335348
"5 forwarding incoming (traces_sample_rate not set)",
336349
"6 traces_sampler overrides incoming (traces_sample_rate not set)",
337350
"7 forwarding incoming (traces_sample_rate not set) (incoming not sampled)",
338351
"8 traces_sampler overrides incoming (traces_sample_rate not set) (incoming not sampled)",
339-
"9 traces_sample_rate overrides incoming",
352+
"9 traces_sample_rate overrides incoming (upstream deferred sampling decision)",
340353
),
341354
)
342355
def test_dsc_sample_rate_change(
@@ -408,6 +421,9 @@ def my_traces_sampler(sampling_context):
408421
assert dsc_in_envelope_header["trace_id"] == incoming_trace_id
409422

410423

424+
# TODO: test for dcs sample_rate upate in case of backpressure down sampling.
425+
426+
411427
def test_dsc_issue(sentry_init, capture_envelopes):
412428
"""
413429
Our service is a standalone service that does not have tracing enabled. Just uses Sentry for error reporting.

0 commit comments

Comments
 (0)