@@ -227,7 +227,7 @@ def create_counter(
227
227
228
228
Args:
229
229
name: The name of the instrument to be created
230
- unit: The unit for measurements this instrument reports. For
230
+ unit: The unit for observations this instrument reports. For
231
231
example, ``By`` for bytes. UCUM units are recommended.
232
232
description: A description for this instrument and what it measures.
233
233
"""
@@ -240,7 +240,7 @@ def create_up_down_counter(
240
240
241
241
Args:
242
242
name: The name of the instrument to be created
243
- unit: The unit for measurements this instrument reports. For
243
+ unit: The unit for observations this instrument reports. For
244
244
example, ``By`` for bytes. UCUM units are recommended.
245
245
description: A description for this instrument and what it measures.
246
246
"""
@@ -253,23 +253,23 @@ def create_observable_counter(
253
253
254
254
An observable counter observes a monotonically increasing count by
255
255
calling provided callbacks which returns multiple
256
- :class:`~opentelemetry._metrics.measurement.Measurement `.
256
+ :class:`~opentelemetry._metrics.observation.Observation `.
257
257
258
258
For example, an observable counter could be used to report system CPU
259
259
time periodically. Here is a basic implementation::
260
260
261
- def cpu_time_callback() -> Iterable[Measurement ]:
262
- measurements = []
261
+ def cpu_time_callback() -> Iterable[Observation ]:
262
+ observations = []
263
263
with open("/proc/stat") as procstat:
264
264
procstat.readline() # skip the first line
265
265
for line in procstat:
266
266
if not line.startswith("cpu"): break
267
267
cpu, *states = line.split()
268
- measurements .append(Measurement (int(states[0]) // 100, {"cpu": cpu, "state": "user"}))
269
- measurements .append(Measurement (int(states[1]) // 100, {"cpu": cpu, "state": "nice"}))
270
- measurements .append(Measurement (int(states[2]) // 100, {"cpu": cpu, "state": "system"}))
268
+ observations .append(Observation (int(states[0]) // 100, {"cpu": cpu, "state": "user"}))
269
+ observations .append(Observation (int(states[1]) // 100, {"cpu": cpu, "state": "nice"}))
270
+ observations .append(Observation (int(states[2]) // 100, {"cpu": cpu, "state": "system"}))
271
271
# ... other states
272
- return measurements
272
+ return observations
273
273
274
274
meter.create_observable_counter(
275
275
"system.cpu.time",
@@ -281,34 +281,34 @@ def cpu_time_callback() -> Iterable[Measurement]:
281
281
To reduce memory usage, you can use generator callbacks instead of
282
282
building the full list::
283
283
284
- def cpu_time_callback() -> Iterable[Measurement ]:
284
+ def cpu_time_callback() -> Iterable[Observation ]:
285
285
with open("/proc/stat") as procstat:
286
286
procstat.readline() # skip the first line
287
287
for line in procstat:
288
288
if not line.startswith("cpu"): break
289
289
cpu, *states = line.split()
290
- yield Measurement (int(states[0]) // 100, {"cpu": cpu, "state": "user"})
291
- yield Measurement (int(states[1]) // 100, {"cpu": cpu, "state": "nice"})
290
+ yield Observation (int(states[0]) // 100, {"cpu": cpu, "state": "user"})
291
+ yield Observation (int(states[1]) // 100, {"cpu": cpu, "state": "nice"})
292
292
# ... other states
293
293
294
294
Alternatively, you can pass a sequence of generators directly instead
295
295
of a sequence of callbacks, which each should return iterables of
296
- :class:`~opentelemetry._metrics.measurement.Measurement `::
296
+ :class:`~opentelemetry._metrics.observation.Observation `::
297
297
298
- def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurement ]]:
298
+ def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Observation ]]:
299
299
while True:
300
- measurements = []
300
+ observations = []
301
301
with open("/proc/stat") as procstat:
302
302
procstat.readline() # skip the first line
303
303
for line in procstat:
304
304
if not line.startswith("cpu"): break
305
305
cpu, *states = line.split()
306
306
if "user" in states_to_include:
307
- measurements .append(Measurement (int(states[0]) // 100, {"cpu": cpu, "state": "user"}))
307
+ observations .append(Observation (int(states[0]) // 100, {"cpu": cpu, "state": "user"}))
308
308
if "nice" in states_to_include:
309
- measurements .append(Measurement (int(states[1]) // 100, {"cpu": cpu, "state": "nice"}))
309
+ observations .append(Observation (int(states[1]) // 100, {"cpu": cpu, "state": "nice"}))
310
310
# ... other states
311
- yield measurements
311
+ yield observations
312
312
313
313
meter.create_observable_counter(
314
314
"system.cpu.time",
@@ -320,11 +320,11 @@ def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurem
320
320
Args:
321
321
name: The name of the instrument to be created
322
322
callbacks: A sequence of callbacks that return an iterable of
323
- :class:`~opentelemetry._metrics.measurement.Measurement `.
323
+ :class:`~opentelemetry._metrics.observation.Observation `.
324
324
Alternatively, can be a sequence of generators that each yields
325
325
iterables of
326
- :class:`~opentelemetry._metrics.measurement.Measurement `.
327
- unit: The unit for measurements this instrument reports. For
326
+ :class:`~opentelemetry._metrics.observation.Observation `.
327
+ unit: The unit for observations this instrument reports. For
328
328
example, ``By`` for bytes. UCUM units are recommended.
329
329
description: A description for this instrument and what it measures.
330
330
"""
@@ -335,7 +335,7 @@ def create_histogram(self, name, unit="", description="") -> Histogram:
335
335
336
336
Args:
337
337
name: The name of the instrument to be created
338
- unit: The unit for measurements this instrument reports. For
338
+ unit: The unit for observations this instrument reports. For
339
339
example, ``By`` for bytes. UCUM units are recommended.
340
340
description: A description for this instrument and what it measures.
341
341
"""
@@ -349,10 +349,10 @@ def create_observable_gauge(
349
349
Args:
350
350
name: The name of the instrument to be created
351
351
callbacks: A sequence of callbacks that return an iterable of
352
- :class:`~opentelemetry._metrics.measurement.Measurement `.
352
+ :class:`~opentelemetry._metrics.observation.Observation `.
353
353
Alternatively, can be a generator that yields iterables of
354
- :class:`~opentelemetry._metrics.measurement.Measurement `.
355
- unit: The unit for measurements this instrument reports. For
354
+ :class:`~opentelemetry._metrics.observation.Observation `.
355
+ unit: The unit for observations this instrument reports. For
356
356
example, ``By`` for bytes. UCUM units are recommended.
357
357
description: A description for this instrument and what it measures.
358
358
"""
@@ -366,10 +366,10 @@ def create_observable_up_down_counter(
366
366
Args:
367
367
name: The name of the instrument to be created
368
368
callbacks: A sequence of callbacks that return an iterable of
369
- :class:`~opentelemetry._metrics.measurement.Measurement `.
369
+ :class:`~opentelemetry._metrics.observation.Observation `.
370
370
Alternatively, can be a generator that yields iterables of
371
- :class:`~opentelemetry._metrics.measurement.Measurement `.
372
- unit: The unit for measurements this instrument reports. For
371
+ :class:`~opentelemetry._metrics.observation.Observation `.
372
+ unit: The unit for observations this instrument reports. For
373
373
example, ``By`` for bytes. UCUM units are recommended.
374
374
description: A description for this instrument and what it measures.
375
375
"""
0 commit comments