Skip to content

Commit bc1b06b

Browse files
committed
nits
1 parent b158e59 commit bc1b06b

3 files changed

Lines changed: 24 additions & 43 deletions

File tree

docs/examples/exemplars/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ and they may focus on measurements with abnormally high/low values.
4545
.. literalinclude:: trace_exemplars.py
4646
:language: python
4747
:lines: 1-
48+
4849
Currently only the Google Cloud Monitoring exporter supports uploading these exemplars.

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/aggregate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, config=None):
4242
self.config = config
4343
else:
4444
self.config = {}
45-
self.checkpoint_exemplars = list()
45+
self.checkpoint_exemplars = []
4646

4747
@abc.abstractmethod
4848
def update(self, value, dropped_labels=None):

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/exemplars.py

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,23 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""
16-
Exemplars are sample data points for aggregators. For more information, see the `spec <https://github.com/open-telemetry/oteps/pull/113>`_
15+
"""Exemplars are sample data points for aggregators. For more information, see the `spec <https://github.com/open-telemetry/oteps/pull/113>`_
1716
18-
Every synchronous aggregator is instrumented with two exemplar recorders:
19-
1. A "trace" exemplar sampler, which only samples exemplars if they have a sampled trace context (and can pick exemplars with other biases, ie min + max).
20-
2. A "statistical" exemplar sampler, which samples exemplars without bias (ie no preferenced for traced exemplars)
17+
Every synchronous aggregator is instrumented with two exemplar recorders:
18+
1. A "trace" exemplar sampler, which only samples exemplars if they have a sampled trace context (and can pick exemplars with other biases, ie min + max).
19+
2. A "statistical" exemplar sampler, which samples exemplars without bias (ie no preferenced for traced exemplars)
2120
22-
To use an exemplar recorder, pass in two arguments to the aggregator config in views (see the :ref:`Exemplars` example for an example):
23-
"num_exemplars": The number of exemplars to record (if applicable, in each bucket). Note that in non-statistical mode the recorder may not use "num_exemplars"
24-
"statistical_exemplars": If exemplars should be recorded statistically
21+
To use an exemplar recorder, pass in two arguments to the aggregator config in views (see the :ref:`Exemplars` example for an example):
22+
"num_exemplars": The number of exemplars to record (if applicable, in each bucket). Note that in non-statistical mode the recorder may not use "num_exemplars"
23+
"statistical_exemplars": If exemplars should be recorded statistically
2524
26-
For exemplars to be recorded, `num_exemplars` must be greater than 0.
25+
For exemplars to be recorded, `num_exemplars` must be greater than 0.
2726
"""
2827

2928
import abc
3029
import itertools
3130
import random
32-
from typing import List, Optional, Tuple, Union
31+
from typing import List, Optional, Tuple, Type, Union
3332

3433
from opentelemetry.context import get_current
3534
from opentelemetry.util import time_ns
@@ -95,7 +94,8 @@ def sample_count(self):
9594
"""For statistical exemplars, how many measurements a single exemplar represents"""
9695
return self._sample_count
9796

98-
def set_sample_count(self, count: float):
97+
@sample_count.setter
98+
def sample_count(self, count: float):
9999
self._sample_count = count
100100

101101

@@ -122,11 +122,13 @@ def sample_set(self):
122122
Return the list of exemplars that have been sampled
123123
"""
124124

125-
@abc.abstractmethod
126125
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
127126
"""
128-
Given two lists of sampled exemplars, merge them while maintaining the invariants specified by this sampler
127+
Assume that set2 is the latest set of exemplars.
128+
For simplicity, we will just keep set2 and assume set1 has already been exported.
129+
This may need to change with a different SDK implementation.
129130
"""
131+
return set2
130132

131133
@abc.abstractmethod
132134
def reset(self):
@@ -162,14 +164,6 @@ def sample(self, exemplar: Exemplar, **kwargs):
162164
if replace_index < self._k:
163165
self._sample_set[replace_index] = exemplar
164166

165-
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
166-
"""
167-
Assume that set2 is the latest set of exemplars.
168-
For simplicity, we will just keep set2 and assume set1 has already been exported.
169-
This may need to change with a different SDK implementation.
170-
"""
171-
return set2
172-
173167
@property
174168
def sample_set(self):
175169
if self._statistical:
@@ -212,14 +206,6 @@ def sample(self, exemplar: Exemplar, **kwargs):
212206
def sample_set(self):
213207
return self._sample_set
214208

215-
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
216-
"""
217-
Assume that set2 is the latest set of exemplars.
218-
For simplicity, we will just keep set2 and assume set1 has already been exported.
219-
This may need to change with a different SDK implementation.
220-
"""
221-
return set2
222-
223209
def reset(self):
224210
self._sample_set = []
225211

@@ -233,7 +219,7 @@ class BucketedExemplarSampler(ExemplarSampler):
233219
"""
234220

235221
def __init__(
236-
self, k: int, statistical: bool = False, boundaries: list = None
222+
self, k: int, statistical: bool = False, boundaries: List[float] = None
237223
):
238224
super().__init__(k)
239225
self._boundaries = boundaries
@@ -242,7 +228,9 @@ def __init__(
242228
for _ in range(len(self._boundaries) + 1)
243229
]
244230

245-
def sample(self, exemplar: Exemplar, **kwargs):
231+
def sample(
232+
self, exemplar: Exemplar, bucket_index: Optional[int] = None, **kwargs
233+
):
246234
bucket_index = kwargs.get("bucket_index")
247235
if bucket_index is None:
248236
return
@@ -253,18 +241,10 @@ def sample(self, exemplar: Exemplar, **kwargs):
253241
def sample_set(self):
254242
return list(
255243
itertools.chain.from_iterable(
256-
[sampler.sample_set for sampler in self._sample_set]
244+
sampler.sample_set for sampler in self._sample_set
257245
)
258246
)
259247

260-
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
261-
"""
262-
Assume that set2 is the latest set of exemplars.
263-
For simplicity, we will just keep set2 and assume set1 has already been exported.
264-
This may need to change with a different SDK implementation.
265-
"""
266-
return set2
267-
268248
def reset(self):
269249
for sampler in self._sample_set:
270250
sampler.reset()
@@ -280,8 +260,8 @@ class ExemplarManager:
280260
def __init__(
281261
self,
282262
config: dict,
283-
default_exemplar_sampler: ExemplarSampler,
284-
statistical_exemplar_sampler: ExemplarSampler,
263+
default_exemplar_sampler: Type[ExemplarSampler],
264+
statistical_exemplar_sampler: Type[ExemplarSampler],
285265
**kwargs
286266
):
287267
if config:

0 commit comments

Comments
 (0)