Skip to content

Commit 30cdade

Browse files
committed
fix(tracing): Respect explicit empty top-level ignore_spans
An explicit top-level ignore_spans=[] was treated as unset, letting _experiments rules leak through. Use an is-not-None check so top-level config wins whenever provided, including an empty list meant to disable ignoring.
1 parent b96d65a commit 30cdade

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

sentry_sdk/tracing_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,11 @@ def is_ignored_span(name: str, attributes: "Optional[Attributes]") -> bool:
16591659
"ignore_spans"
16601660
)
16611661

1662-
ignore_spans = is_ignored_at_top_level or is_ignored_in_experiment_config
1662+
ignore_spans = (
1663+
is_ignored_at_top_level
1664+
if is_ignored_at_top_level is not None
1665+
else is_ignored_in_experiment_config
1666+
)
16631667

16641668
if not ignore_spans:
16651669
return False

tests/tracing/test_span_streaming.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,30 @@ def test_ignore_spans_top_level_with_trace_lifecycle_in_experiments(
18281828
assert span["name"] == "not ignored"
18291829

18301830

1831+
def test_ignore_spans_empty_top_level_overrides_experiments(sentry_init, capture_items):
1832+
# An explicit empty top-level ignore_spans should disable ignoring,
1833+
# taking precedence over any rules set in _experiments.
1834+
sentry_init(
1835+
traces_sample_rate=1.0,
1836+
trace_lifecycle="stream",
1837+
ignore_spans=[],
1838+
_experiments={"ignore_spans": ["ignored"]},
1839+
)
1840+
1841+
items = capture_items("span")
1842+
1843+
with sentry_sdk.traces.start_span(name="ignored") as span:
1844+
assert span.sampled is True
1845+
assert isinstance(span, StreamedSpan)
1846+
1847+
sentry_sdk.get_client().flush()
1848+
spans = [item.payload for item in items]
1849+
1850+
assert len(spans) == 1
1851+
(span,) = spans
1852+
assert span["name"] == "ignored"
1853+
1854+
18311855
@pytest.mark.parametrize(
18321856
("options", "streaming_enabled"),
18331857
[

0 commit comments

Comments
 (0)