Skip to content

Commit 1145c19

Browse files
committed
check legacy_ignore in any_sampling
1 parent b5b7f3a commit 1145c19

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/scout_apm/core/sampler.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, config):
3232
self.ignore_endpoints = set(
3333
config.value("ignore_endpoints") + config.value("ignore")
3434
)
35+
self.legacy_ignore = set(config.value("ignore"))
3536
self.ignore_jobs = set(config.value("ignore_jobs"))
3637
self.endpoint_sample_rate = config.value("endpoint_sample_rate")
3738
self.job_sample_rate = config.value("job_sample_rate")
@@ -48,6 +49,7 @@ def _any_sampling(self):
4849
or self.sample_endpoints
4950
or self.sample_jobs
5051
or self.ignore_endpoints
52+
or self.legacy_ignore
5153
or self.ignore_jobs
5254
or self.endpoint_sample_rate is not None
5355
or self.job_sample_rate is not None

tests/unit/core/test_sampler.py

+27
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,30 @@ def test_prefix_matching_precedence(config):
168168

169169
# VIP users API should always be sampled
170170
assert sampler.should_sample("Controller/api/users/vip/list", False) is True
171+
172+
173+
def test_should_sample_with_legacy_ignore(config):
174+
"""Test that sampling works correctly when only legacy 'ignore' config is set."""
175+
config.set(
176+
sample_rate=100, # Return config to defaults
177+
sample_endpoints={},
178+
sample_jobs={},
179+
ignore_endpoints=[], # No explicit ignore_endpoints
180+
ignore_jobs=[],
181+
ignore=["metrics", "health"], # Only set legacy ignore patterns
182+
endpoint_sample_rate=None,
183+
job_sample_rate=None,
184+
)
185+
sampler = Sampler(config)
186+
187+
# Legacy ignored endpoints should not be sampled
188+
assert sampler.should_sample("Controller/metrics/stats", False) is False
189+
assert sampler.should_sample("Controller/health/check", False) is False
190+
191+
# Legacy ignore should be combined with ignore_endpoints
192+
assert "metrics" in sampler.ignore_endpoints
193+
assert "health" in sampler.ignore_endpoints
194+
195+
# Non-ignored endpoints and jobs should be sampled
196+
assert sampler.should_sample("Controller/users/list", False) is True
197+
assert sampler.should_sample("Job/process_data", False) is True

0 commit comments

Comments
 (0)