@@ -181,12 +181,12 @@ def create_up_down_counter(
181
181
182
182
@abstractmethod
183
183
def create_observable_counter (
184
- self , name , callback , unit = "" , description = ""
184
+ self , name , callbacks = None , unit = "" , description = ""
185
185
) -> ObservableCounter :
186
186
"""Creates an `ObservableCounter` instrument
187
187
188
188
An observable counter observes a monotonically increasing count by
189
- calling a provided callback which returns multiple
189
+ calling provided callbacks which returns multiple
190
190
:class:`~opentelemetry._metrics.measurement.Measurement`.
191
191
192
192
For example, an observable counter could be used to report system CPU
@@ -207,7 +207,7 @@ def cpu_time_callback() -> Iterable[Measurement]:
207
207
208
208
meter.create_observable_counter(
209
209
"system.cpu.time",
210
- callback= cpu_time_callback,
210
+ callbacks=[ cpu_time_callback] ,
211
211
unit="s",
212
212
description="CPU time"
213
213
)
@@ -225,8 +225,8 @@ def cpu_time_callback() -> Iterable[Measurement]:
225
225
yield Measurement(int(states[1]) // 100, {"cpu": cpu, "state": "nice"})
226
226
# ... other states
227
227
228
- Alternatively, you can pass a generator directly instead of a callback,
229
- which should return iterables of
228
+ Alternatively, you can pass a sequence of generators directly instead
229
+ of a sequence of callbacks, which each should return iterables of
230
230
:class:`~opentelemetry._metrics.measurement.Measurement`::
231
231
232
232
def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurement]]:
@@ -246,16 +246,17 @@ def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurem
246
246
247
247
meter.create_observable_counter(
248
248
"system.cpu.time",
249
- callback= cpu_time_callback({"user", "system"}),
249
+ callbacks=[ cpu_time_callback({"user", "system"})] ,
250
250
unit="s",
251
251
description="CPU time"
252
252
)
253
253
254
254
Args:
255
255
name: The name of the instrument to be created
256
- callback : A callback that returns an iterable of
256
+ callbacks : A sequence of callbacks that return an iterable of
257
257
:class:`~opentelemetry._metrics.measurement.Measurement`.
258
- Alternatively, can be a generator that yields iterables of
258
+ Alternatively, can be a sequence of generators that each yields
259
+ iterables of
259
260
:class:`~opentelemetry._metrics.measurement.Measurement`.
260
261
unit: The unit for measurements this instrument reports. For
261
262
example, ``By`` for bytes. UCUM units are recommended.
@@ -275,13 +276,13 @@ def create_histogram(self, name, unit="", description="") -> Histogram:
275
276
276
277
@abstractmethod
277
278
def create_observable_gauge (
278
- self , name , callback , unit = "" , description = ""
279
+ self , name , callbacks = None , unit = "" , description = ""
279
280
) -> ObservableGauge :
280
281
"""Creates an `ObservableGauge` instrument
281
282
282
283
Args:
283
284
name: The name of the instrument to be created
284
- callback : A callback that returns an iterable of
285
+ callbacks : A sequence of callbacks that return an iterable of
285
286
:class:`~opentelemetry._metrics.measurement.Measurement`.
286
287
Alternatively, can be a generator that yields iterables of
287
288
:class:`~opentelemetry._metrics.measurement.Measurement`.
@@ -292,13 +293,13 @@ def create_observable_gauge(
292
293
293
294
@abstractmethod
294
295
def create_observable_up_down_counter (
295
- self , name , callback , unit = "" , description = ""
296
+ self , name , callbacks = None , unit = "" , description = ""
296
297
) -> ObservableUpDownCounter :
297
298
"""Creates an `ObservableUpDownCounter` instrument
298
299
299
300
Args:
300
301
name: The name of the instrument to be created
301
- callback : A callback that returns an iterable of
302
+ callbacks : A sequence of callbacks that return an iterable of
302
303
:class:`~opentelemetry._metrics.measurement.Measurement`.
303
304
Alternatively, can be a generator that yields iterables of
304
305
:class:`~opentelemetry._metrics.measurement.Measurement`.
@@ -358,15 +359,15 @@ def create_up_down_counter(
358
359
return proxy
359
360
360
361
def create_observable_counter (
361
- self , name , callback , unit = "" , description = ""
362
+ self , name , callbacks = None , unit = "" , description = ""
362
363
) -> ObservableCounter :
363
364
with self ._lock :
364
365
if self ._real_meter :
365
366
return self ._real_meter .create_observable_counter (
366
- name , callback , unit , description
367
+ name , callbacks , unit , description
367
368
)
368
369
proxy = _ProxyObservableCounter (
369
- name , callback , unit = unit , description = description
370
+ name , callbacks , unit = unit , description = description
370
371
)
371
372
self ._instruments .append (proxy )
372
373
return proxy
@@ -382,32 +383,32 @@ def create_histogram(self, name, unit="", description="") -> Histogram:
382
383
return proxy
383
384
384
385
def create_observable_gauge (
385
- self , name , callback , unit = "" , description = ""
386
+ self , name , callbacks = None , unit = "" , description = ""
386
387
) -> ObservableGauge :
387
388
with self ._lock :
388
389
if self ._real_meter :
389
390
return self ._real_meter .create_observable_gauge (
390
- name , callback , unit , description
391
+ name , callbacks , unit , description
391
392
)
392
393
proxy = _ProxyObservableGauge (
393
- name , callback , unit = unit , description = description
394
+ name , callbacks , unit = unit , description = description
394
395
)
395
396
self ._instruments .append (proxy )
396
397
return proxy
397
398
398
399
def create_observable_up_down_counter (
399
- self , name , callback , unit = "" , description = ""
400
+ self , name , callbacks = None , unit = "" , description = ""
400
401
) -> ObservableUpDownCounter :
401
402
with self ._lock :
402
403
if self ._real_meter :
403
404
return self ._real_meter .create_observable_up_down_counter (
404
405
name ,
405
- callback ,
406
+ callbacks ,
406
407
unit ,
407
408
description ,
408
409
)
409
410
proxy = _ProxyObservableUpDownCounter (
410
- name , callback , unit = unit , description = description
411
+ name , callbacks , unit = unit , description = description
411
412
)
412
413
self ._instruments .append (proxy )
413
414
return proxy
@@ -454,11 +455,11 @@ def create_up_down_counter(
454
455
return DefaultUpDownCounter (name , unit = unit , description = description )
455
456
456
457
def create_observable_counter (
457
- self , name , callback , unit = "" , description = ""
458
+ self , name , callbacks = None , unit = "" , description = ""
458
459
) -> ObservableCounter :
459
460
"""Returns a no-op ObservableCounter."""
460
461
super ().create_observable_counter (
461
- name , callback , unit = unit , description = description
462
+ name , callbacks , unit = unit , description = description
462
463
)
463
464
if self ._check_instrument_id (
464
465
name , DefaultObservableCounter , unit , description
@@ -473,7 +474,7 @@ def create_observable_counter(
473
474
)
474
475
return DefaultObservableCounter (
475
476
name ,
476
- callback ,
477
+ callbacks ,
477
478
unit = unit ,
478
479
description = description ,
479
480
)
@@ -495,11 +496,11 @@ def create_histogram(self, name, unit="", description="") -> Histogram:
495
496
return DefaultHistogram (name , unit = unit , description = description )
496
497
497
498
def create_observable_gauge (
498
- self , name , callback , unit = "" , description = ""
499
+ self , name , callbacks = None , unit = "" , description = ""
499
500
) -> ObservableGauge :
500
501
"""Returns a no-op ObservableGauge."""
501
502
super ().create_observable_gauge (
502
- name , callback , unit = unit , description = description
503
+ name , callbacks , unit = unit , description = description
503
504
)
504
505
if self ._check_instrument_id (
505
506
name , DefaultObservableGauge , unit , description
@@ -514,17 +515,17 @@ def create_observable_gauge(
514
515
)
515
516
return DefaultObservableGauge (
516
517
name ,
517
- callback ,
518
+ callbacks ,
518
519
unit = unit ,
519
520
description = description ,
520
521
)
521
522
522
523
def create_observable_up_down_counter (
523
- self , name , callback , unit = "" , description = ""
524
+ self , name , callbacks = None , unit = "" , description = ""
524
525
) -> ObservableUpDownCounter :
525
526
"""Returns a no-op ObservableUpDownCounter."""
526
527
super ().create_observable_up_down_counter (
527
- name , callback , unit = unit , description = description
528
+ name , callbacks , unit = unit , description = description
528
529
)
529
530
if self ._check_instrument_id (
530
531
name , DefaultObservableUpDownCounter , unit , description
@@ -539,7 +540,7 @@ def create_observable_up_down_counter(
539
540
)
540
541
return DefaultObservableUpDownCounter (
541
542
name ,
542
- callback ,
543
+ callbacks ,
543
544
unit = unit ,
544
545
description = description ,
545
546
)
0 commit comments