Skip to content

Merge branch 'master' into ivana/span-first-14-custom-sampling-context

7403dd2
Select commit
Loading
Failed to load commit list.
Sign in for the full log view
Merged

ref: Add support for custom sampling context to span first (14) #5628

Merge branch 'master' into ivana/span-first-14-custom-sampling-context
7403dd2
Select commit
Loading
Failed to load commit list.
GitHub Actions / warden: find-bugs completed Mar 11, 2026 in 2m 46s

1 issue

find-bugs: Found 1 issue (1 medium)

Medium

custom_sampling_context can overwrite SDK-provided 'span' key in traces_sampler - `sentry_sdk/tracing_utils.py:1434`

On line 1434, sampling_context.update(propagation_context.custom_sampling_context) will overwrite any keys in sampling_context, including the 'span' key created on lines 1424-1430. If a user or integration sets custom_sampling_context with a 'span' key (e.g., via ASGI scope integration mentioned in the PR description), it will silently replace the SDK-provided span information. This breaks the contract that traces_sampler callbacks can reliably access sampling_context["span"]["name"], sampling_context["span"]["trace_id"], etc., as demonstrated in test_custom_sampling_context_update_to_context_value_persists.


Duration: 2m 46s · Tokens: 1.5M in / 9.2k out · Cost: $3.26 (+extraction: $0.01)

Annotations

Check warning on line 1434 in sentry_sdk/tracing_utils.py

See this annotation in the file changed.

@github-actions github-actions / warden: find-bugs

custom_sampling_context can overwrite SDK-provided 'span' key in traces_sampler

On line 1434, `sampling_context.update(propagation_context.custom_sampling_context)` will overwrite any keys in sampling_context, including the 'span' key created on lines 1424-1430. If a user or integration sets custom_sampling_context with a 'span' key (e.g., via ASGI scope integration mentioned in the PR description), it will silently replace the SDK-provided span information. This breaks the contract that traces_sampler callbacks can reliably access `sampling_context["span"]["name"]`, `sampling_context["span"]["trace_id"]`, etc., as demonstrated in test_custom_sampling_context_update_to_context_value_persists.