Skip to content

Commit c7d6608

Browse files
committed
Fixed spell check errors
1 parent 4efd462 commit c7d6608

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_rate_limited_sampling.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
from azure.monitor.opentelemetry.exporter.export.trace._utils import _get_djb2_sample_score, _round_down_to_nearest
2222

2323
class _State:
24-
def __init__(self, effective_window_count: float, effective_window_nanos: float, last_nano_time: int):
24+
def __init__(self, effective_window_count: float, effective_window_nanoseconds: float, last_nano_time: int):
2525
self.effective_window_count = effective_window_count
26-
self.effective_window_nanos = effective_window_nanos
26+
self.effective_window_nanoseconds = effective_window_nanoseconds
2727
self.last_nano_time = last_nano_time
2828

2929
class RateLimitedSamplingPercentage:
@@ -34,7 +34,7 @@ def __init__(self, target_spans_per_second_limit: float,
3434
self._nano_time_supplier = nano_time_supplier or (lambda: int(time.time_ns()))
3535
# Hardcoded adaptation time of 0.1 seconds for adjusting to sudden changes in telemetry volumes
3636
adaptation_time_seconds = 0.1
37-
self._inverse_adaptation_time_nanos = 1e-9 / adaptation_time_seconds
37+
self._inverse_adaptation_time_nanoseconds = 1e-9 / adaptation_time_seconds
3838
self._target_spans_per_nanosecond_limit = 1e-9 * target_spans_per_second_limit
3939
initial_nano_time = self._nano_time_supplier()
4040
self._state = _State(0.0, 0.0, initial_nano_time)
@@ -45,39 +45,38 @@ def _update_state(self, old_state: _State, current_nano_time: int) -> _State:
4545
if current_nano_time <= old_state.last_nano_time:
4646
return _State(
4747
old_state.effective_window_count + 1,
48-
old_state.effective_window_nanos,
48+
old_state.effective_window_nanoseconds,
4949
old_state.last_nano_time
5050
)
5151
nano_time_delta = current_nano_time - old_state.last_nano_time
52-
decay_factor = math.exp(-nano_time_delta * self._inverse_adaptation_time_nanos)
52+
decay_factor = math.exp(-nano_time_delta * self._inverse_adaptation_time_nanoseconds)
5353
current_effective_window_count = old_state.effective_window_count * decay_factor + 1
54-
current_effective_window_nanos = old_state.effective_window_nanos * decay_factor + nano_time_delta
55-
56-
return _State(current_effective_window_count, current_effective_window_nanos, current_nano_time)
54+
current_effective_window_nanoseconds = old_state.effective_window_nanoseconds * decay_factor + nano_time_delta
55+
56+
return _State(current_effective_window_count, current_effective_window_nanoseconds, current_nano_time)
5757

5858
def get(self) -> float:
59-
"""Get the current sampling percentage (0.0 to 100.0)."""
6059
current_nano_time = self._nano_time_supplier()
61-
60+
6261
with self._lock:
6362
old_state = self._state
64-
self._state = self._update_state(self._state, current_nano_time)
63+
self._state = self._update_state(old_state, current_nano_time)
6564
current_state = self._state
66-
65+
6766
# Calculate sampling probability based on current state
6867
if current_state.effective_window_count == 0:
6968
return 100.0
70-
69+
7170
sampling_probability = (
72-
(current_state.effective_window_nanos * self._target_spans_per_nanosecond_limit) /
71+
(current_state.effective_window_nanoseconds * self._target_spans_per_nanosecond_limit) /
7372
current_state.effective_window_count
7473
)
75-
74+
7675
sampling_percentage = 100 * min(sampling_probability, 1.0)
77-
76+
7877
if self._round_to_nearest:
7978
sampling_percentage = _round_down_to_nearest(sampling_percentage)
80-
79+
8180
return sampling_percentage
8281

8382

@@ -96,11 +95,11 @@ def should_sample(
9695
links: Optional[Sequence["Link"]] = None,
9796
trace_state: Optional["TraceState"] = None,
9897
) -> "SamplingResult":
99-
98+
10099
if parent_context is not None:
101100
parent_span = get_current_span(parent_context)
102101
parent_span_context = parent_span.get_span_context()
103-
102+
104103
# Check if parent is valid and local (not remote)
105104
if parent_span_context.is_valid and not parent_span_context.is_remote:
106105
# Check if parent was dropped/record-only first
@@ -111,50 +110,50 @@ def should_sample(
111110
else:
112111
new_attributes = dict(attributes)
113112
new_attributes[_SAMPLE_RATE_KEY] = 0.0
114-
113+
115114
return SamplingResult(
116115
Decision.DROP,
117116
new_attributes,
118117
_get_parent_trace_state(parent_context),
119118
)
120-
119+
121120
# Parent is recording, check for sample rate attribute
122121
parent_attributes = getattr(parent_span, 'attributes', {})
123122
parent_sample_rate = parent_attributes.get(_SAMPLE_RATE_KEY)
124-
123+
125124
if parent_sample_rate is not None:
126125
# Honor parent's sampling rate
127126
if attributes is None:
128127
new_attributes = {}
129128
else:
130129
new_attributes = dict(attributes)
131130
new_attributes[_SAMPLE_RATE_KEY] = parent_sample_rate
132-
131+
133132
return SamplingResult(
134133
Decision.RECORD_AND_SAMPLE,
135134
new_attributes,
136135
_get_parent_trace_state(parent_context),
137136
)
138-
137+
139138
sampling_percentage = self._sampling_percentage_generator.get()
140139
sampling_score = _get_djb2_sample_score(format_trace_id(trace_id).lower())
141-
140+
142141
if sampling_score < sampling_percentage:
143142
decision = Decision.RECORD_AND_SAMPLE
144143
else:
145144
decision = Decision.DROP
146-
145+
147146
if attributes is None:
148147
new_attributes = {}
149148
else:
150149
new_attributes = dict(attributes)
151150
new_attributes[_SAMPLE_RATE_KEY] = sampling_percentage
152-
151+
153152
return SamplingResult(
154153
decision,
155154
new_attributes,
156155
_get_parent_trace_state(parent_context),
157156
)
158157

159158
def get_description(self) -> str:
160-
return self._description
159+
return self._description

0 commit comments

Comments
 (0)