Skip to content

Commit 4d311a8

Browse files
committed
rename agent_sampling_rules to agent_based_samplers to improve clarity
1 parent d790205 commit 4d311a8

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

ddtrace/_trace/processor/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __init__(
132132
compute_stats_enabled: bool,
133133
single_span_rules: List[SpanSamplingRule],
134134
apm_opt_out: bool,
135-
agent_sampling_rules: Optional[dict] = None,
135+
agent_based_samplers: Optional[dict] = None,
136136
):
137137
super(TraceSamplingProcessor, self).__init__()
138138
self._compute_stats_enabled = compute_stats_enabled
@@ -146,10 +146,10 @@ def __init__(
146146
rate_limit=1,
147147
rate_limit_window=60e9,
148148
rate_limit_always_on=True,
149-
agent_sampling_rules=agent_sampling_rules,
149+
agent_based_samplers=agent_based_samplers,
150150
)
151151
else:
152-
self.sampler = DatadogSampler(agent_sampling_rules=agent_sampling_rules)
152+
self.sampler = DatadogSampler(agent_based_samplers=agent_based_samplers)
153153

154154
def process_trace(self, trace: List[Span]) -> Optional[List[Span]]:
155155
if trace:
@@ -506,7 +506,7 @@ def _reset(self):
506506
config._trace_compute_stats,
507507
get_span_sampling_rules(),
508508
asm_config._apm_opt_out,
509-
self.sampling_processor.sampler._agent_sampling_rules,
509+
self.sampling_processor.sampler._agent_based_samplers,
510510
)
511511
self._traces = defaultdict(lambda: _Trace())
512512
self._span_metrics = {

ddtrace/_trace/sampler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class DatadogSampler:
7575
"limiter",
7676
"rules",
7777
"_rate_limit_always_on",
78-
"_agent_sampling_rules",
78+
"_agent_based_samplers",
7979
)
8080
_default_key = "service:,env:"
8181

@@ -85,7 +85,7 @@ def __init__(
8585
rate_limit: Optional[int] = None,
8686
rate_limit_window: float = 1e9,
8787
rate_limit_always_on: bool = False,
88-
agent_sampling_rules: Optional[Dict[str, RateSampler]] = None,
88+
agent_based_samplers: Optional[Dict[str, RateSampler]] = None,
8989
):
9090
"""
9191
Constructor for DatadogSampler sampler
@@ -102,7 +102,7 @@ def __init__(
102102
else:
103103
self.rules: List[SamplingRule] = rules or []
104104
# Set Agent based samplers
105-
self._agent_sampling_rules = agent_sampling_rules or {}
105+
self._agent_based_samplers = agent_based_samplers or {}
106106
# Set rate limiter
107107
self._rate_limit_always_on: bool = rate_limit_always_on
108108
if rate_limit is None:
@@ -120,10 +120,10 @@ def update_rate_by_service_sample_rates(self, rate_by_service: Dict[str, float])
120120
samplers: Dict[str, RateSampler] = {}
121121
for key, sample_rate in rate_by_service.items():
122122
samplers[key] = RateSampler(sample_rate)
123-
self._agent_sampling_rules = samplers
123+
self._agent_based_samplers = samplers
124124

125125
def __str__(self):
126-
rates = {key: sampler.sample_rate for key, sampler in self._agent_sampling_rules.items()}
126+
rates = {key: sampler.sample_rate for key, sampler in self._agent_based_samplers.items()}
127127
return "{}(agent_rates={!r}, limiter={!r}, rules={!r}), rate_limit_always_on={!r}".format(
128128
self.__class__.__name__,
129129
rates,
@@ -182,11 +182,11 @@ def sample(self, span: Span) -> bool:
182182
sample_rate = matched_rule.sample_rate
183183
else:
184184
key = self._key(span.service, span.get_tag(ENV_KEY))
185-
if key in self._agent_sampling_rules:
185+
if key in self._agent_based_samplers:
186186
# Agent service based sampling
187187
agent_service_based = True
188-
sampled = self._agent_sampling_rules[key].sample(span)
189-
sample_rate = self._agent_sampling_rules[key].sample_rate
188+
sampled = self._agent_based_samplers[key].sample(span)
189+
sample_rate = self._agent_based_samplers[key].sample_rate
190190

191191
if matched_rule or self._rate_limit_always_on:
192192
# Avoid rate limiting when trace sample rules and/or sample rates are NOT provided

tests/integration/test_priority_sampling.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _prime_tracer_with_priority_sample_rate_from_agent(t, service):
4040
t.flush()
4141

4242
sampler_key = "service:{},env:".format(service)
43-
while sampler_key not in t._span_aggregator.sampling_processor.sampler._agent_sampling_rules:
43+
while sampler_key not in t._span_aggregator.sampling_processor.sampler._agent_based_samplers:
4444
time.sleep(1)
4545
s = t.trace("operation", service=service)
4646
s.finish()
@@ -69,9 +69,9 @@ def test_priority_sampling_rate_honored():
6969

7070
_prime_tracer_with_priority_sample_rate_from_agent(t, service)
7171
sampler_key = "service:{},env:".format(service)
72-
assert sampler_key in t._span_aggregator.sampling_processor.sampler._agent_sampling_rules
72+
assert sampler_key in t._span_aggregator.sampling_processor.sampler._agent_based_samplers
7373

74-
rate_from_agent = t._span_aggregator.sampling_processor.sampler._agent_sampling_rules[sampler_key].sample_rate
74+
rate_from_agent = t._span_aggregator.sampling_processor.sampler._agent_based_samplers[sampler_key].sample_rate
7575
assert 0 < rate_from_agent < 1
7676

7777
_turn_tracer_into_dummy(t)
@@ -102,10 +102,10 @@ def test_priority_sampling_response():
102102
_id = time.time()
103103
service = "my-svc-{}".format(_id)
104104
sampler_key = "service:{},env:".format(service)
105-
assert sampler_key not in t._span_aggregator.sampling_processor.sampler._agent_sampling_rules
105+
assert sampler_key not in t._span_aggregator.sampling_processor.sampler._agent_based_samplers
106106
_prime_tracer_with_priority_sample_rate_from_agent(t, service)
107107
assert (
108-
sampler_key in t._span_aggregator.sampling_processor.sampler._agent_sampling_rules
108+
sampler_key in t._span_aggregator.sampling_processor.sampler._agent_based_samplers
109109
), "after fetching priority sample rates from the agent, the tracer should hold those rates"
110110
t.shutdown()
111111

@@ -154,13 +154,13 @@ def test_sampling_configurations_are_not_reset_on_tracer_configure():
154154

155155
_prime_tracer_with_priority_sample_rate_from_agent(t, service)
156156

157-
agent_sampling_rules = t._span_aggregator.sampling_processor.sampler._agent_sampling_rules
157+
agent_based_samplers = t._span_aggregator.sampling_processor.sampler._agent_based_samplers
158158
trace_sampling_rules = t._span_aggregator.sampling_processor.sampler.rules
159159
single_span_sampling_rules = t._span_aggregator.sampling_processor.single_span_rules
160160
assert (
161-
agent_sampling_rules and trace_sampling_rules and single_span_sampling_rules
161+
agent_based_samplers and trace_sampling_rules and single_span_sampling_rules
162162
), "Expected agent sampling rules, span sampling rules, trace sampling rules to be set"
163-
f", got {agent_sampling_rules}, {trace_sampling_rules}, {single_span_sampling_rules}"
163+
f", got {agent_based_samplers}, {trace_sampling_rules}, {single_span_sampling_rules}"
164164

165165
class CustomFilter(TraceFilter):
166166
def process_trace(self, trace):
@@ -171,9 +171,9 @@ def process_trace(self, trace):
171171

172172
t.configure(trace_processors=[CustomFilter()]) # Triggers AgentWriter recreate
173173
assert (
174-
t._span_aggregator.sampling_processor.sampler._agent_sampling_rules == agent_sampling_rules
175-
), f"Expected agent sampling rules to be set to {agent_sampling_rules}, "
176-
f"got {t._span_aggregator.sampling_processor.sampler._agent_sampling_rules}"
174+
t._span_aggregator.sampling_processor.sampler._agent_based_samplers == agent_based_samplers
175+
), f"Expected agent sampling rules to be set to {agent_based_samplers}, "
176+
f"got {t._span_aggregator.sampling_processor.sampler._agent_based_samplers}"
177177

178178
assert (
179179
t._span_aggregator.sampling_processor.sampler.rules == trace_sampling_rules

tests/tracer/test_sampler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def test_update_rate_by_service_sample_rates(priority_sampler):
820820
for given_rates in cases:
821821
priority_sampler.update_rate_by_service_sample_rates(given_rates)
822822
actual_rates = {}
823-
for k, v in priority_sampler._agent_sampling_rules.items():
823+
for k, v in priority_sampler._agent_based_samplers.items():
824824
actual_rates[k] = v.sample_rate
825825
assert given_rates == actual_rates, "sampler should store the rates it's given"
826826
# It's important to also test in reverse mode for we want to make sure key deletion
@@ -829,7 +829,7 @@ def test_update_rate_by_service_sample_rates(priority_sampler):
829829
for given_rates in cases:
830830
priority_sampler.update_rate_by_service_sample_rates(given_rates)
831831
actual_rates = {}
832-
for k, v in priority_sampler._agent_sampling_rules.items():
832+
for k, v in priority_sampler._agent_based_samplers.items():
833833
actual_rates[k] = v.sample_rate
834834
assert given_rates == actual_rates, "sampler should store the rates it's given"
835835

0 commit comments

Comments
 (0)