46
46
from logging import getLogger
47
47
from os import environ
48
48
from threading import Lock
49
- from typing import Dict , List , Optional , Sequence , Union , cast
49
+ from typing import Any , Dict , List , Optional , Sequence , Union , cast
50
50
51
51
from opentelemetry .environment_variables import OTEL_PYTHON_METER_PROVIDER
52
52
from opentelemetry .metrics ._internal .instrument import (
53
53
CallbackT ,
54
54
Counter ,
55
55
Gauge ,
56
56
Histogram ,
57
- MetricsCommonAdvisory ,
58
- MetricsHistogramAdvisory ,
59
57
NoOpCounter ,
60
58
NoOpGauge ,
61
59
NoOpHistogram ,
67
65
ObservableGauge ,
68
66
ObservableUpDownCounter ,
69
67
UpDownCounter ,
70
- _MetricsInstrumentAdvisory ,
71
68
_ProxyCounter ,
72
69
_ProxyGauge ,
73
70
_ProxyHistogram ,
@@ -188,7 +185,7 @@ class _InstrumentRegistrationStatus:
188
185
instrument_id : str
189
186
already_registered : bool
190
187
conflict : bool
191
- current_advisory : Optional [_MetricsInstrumentAdvisory ]
188
+ current_advisory : Optional [Any ]
192
189
193
190
194
191
class Meter (ABC ):
@@ -208,9 +205,7 @@ def __init__(
208
205
self ._name = name
209
206
self ._version = version
210
207
self ._schema_url = schema_url
211
- self ._instrument_ids : Dict [
212
- str , Optional [_MetricsInstrumentAdvisory ]
213
- ] = {}
208
+ self ._instrument_ids : Dict [str , Optional [Any ]] = {}
214
209
self ._instrument_ids_lock = Lock ()
215
210
216
211
@property
@@ -240,7 +235,7 @@ def _register_instrument(
240
235
type_ : type ,
241
236
unit : str ,
242
237
description : str ,
243
- advisory : Optional [_MetricsInstrumentAdvisory ] = None ,
238
+ advisory : Optional [Any ] = None ,
244
239
) -> _InstrumentRegistrationStatus :
245
240
"""
246
241
Register an instrument with the name, type, unit and description as
@@ -303,7 +298,6 @@ def create_counter(
303
298
name : str ,
304
299
unit : str = "" ,
305
300
description : str = "" ,
306
- advisory : Optional [MetricsCommonAdvisory ] = None ,
307
301
) -> Counter :
308
302
"""Creates a `Counter` instrument
309
303
@@ -320,7 +314,6 @@ def create_up_down_counter(
320
314
name : str ,
321
315
unit : str = "" ,
322
316
description : str = "" ,
323
- advisory : Optional [MetricsCommonAdvisory ] = None ,
324
317
) -> UpDownCounter :
325
318
"""Creates an `UpDownCounter` instrument
326
319
@@ -338,7 +331,6 @@ def create_observable_counter(
338
331
callbacks : Optional [Sequence [CallbackT ]] = None ,
339
332
unit : str = "" ,
340
333
description : str = "" ,
341
- advisory : Optional [MetricsCommonAdvisory ] = None ,
342
334
) -> ObservableCounter :
343
335
"""Creates an `ObservableCounter` instrument
344
336
@@ -435,7 +427,7 @@ def create_histogram(
435
427
name : str ,
436
428
unit : str = "" ,
437
429
description : str = "" ,
438
- advisory : Optional [MetricsHistogramAdvisory ] = None ,
430
+ explicit_bucket_boundaries_advisory : Optional [Sequence [ float ] ] = None ,
439
431
) -> Histogram :
440
432
"""Creates a :class:`~opentelemetry.metrics.Histogram` instrument
441
433
@@ -451,7 +443,6 @@ def create_gauge( # type: ignore # pylint: disable=no-self-use
451
443
name : str ,
452
444
unit : str = "" ,
453
445
description : str = "" ,
454
- advisory : Optional [MetricsCommonAdvisory ] = None ,
455
446
) -> Gauge :
456
447
"""Creates a ``Gauge`` instrument
457
448
@@ -470,7 +461,6 @@ def create_observable_gauge(
470
461
callbacks : Optional [Sequence [CallbackT ]] = None ,
471
462
unit : str = "" ,
472
463
description : str = "" ,
473
- advisory : Optional [MetricsCommonAdvisory ] = None ,
474
464
) -> ObservableGauge :
475
465
"""Creates an `ObservableGauge` instrument
476
466
@@ -491,7 +481,6 @@ def create_observable_up_down_counter(
491
481
callbacks : Optional [Sequence [CallbackT ]] = None ,
492
482
unit : str = "" ,
493
483
description : str = "" ,
494
- advisory : Optional [MetricsCommonAdvisory ] = None ,
495
484
) -> ObservableUpDownCounter :
496
485
"""Creates an `ObservableUpDownCounter` instrument
497
486
@@ -540,7 +529,6 @@ def create_counter(
540
529
name : str ,
541
530
unit : str = "" ,
542
531
description : str = "" ,
543
- advisory : Optional [MetricsCommonAdvisory ] = None ,
544
532
) -> Counter :
545
533
with self ._lock :
546
534
if self ._real_meter :
@@ -554,7 +542,6 @@ def create_up_down_counter(
554
542
name : str ,
555
543
unit : str = "" ,
556
544
description : str = "" ,
557
- advisory : Optional [MetricsCommonAdvisory ] = None ,
558
545
) -> UpDownCounter :
559
546
with self ._lock :
560
547
if self ._real_meter :
@@ -571,7 +558,6 @@ def create_observable_counter(
571
558
callbacks : Optional [Sequence [CallbackT ]] = None ,
572
559
unit : str = "" ,
573
560
description : str = "" ,
574
- advisory : Optional [MetricsCommonAdvisory ] = None ,
575
561
) -> ObservableCounter :
576
562
with self ._lock :
577
563
if self ._real_meter :
@@ -589,14 +575,19 @@ def create_histogram(
589
575
name : str ,
590
576
unit : str = "" ,
591
577
description : str = "" ,
592
- advisory : Optional [MetricsHistogramAdvisory ] = None ,
578
+ explicit_bucket_boundaries_advisory : Optional [Sequence [ float ] ] = None ,
593
579
) -> Histogram :
594
580
with self ._lock :
595
581
if self ._real_meter :
596
582
return self ._real_meter .create_histogram (
597
- name , unit , description , advisory
583
+ name ,
584
+ unit ,
585
+ description ,
586
+ explicit_bucket_boundaries_advisory ,
598
587
)
599
- proxy = _ProxyHistogram (name , unit , description , advisory )
588
+ proxy = _ProxyHistogram (
589
+ name , unit , description , explicit_bucket_boundaries_advisory
590
+ )
600
591
self ._instruments .append (proxy )
601
592
return proxy
602
593
@@ -605,7 +596,6 @@ def create_gauge(
605
596
name : str ,
606
597
unit : str = "" ,
607
598
description : str = "" ,
608
- advisory : Optional [MetricsCommonAdvisory ] = None ,
609
599
) -> Gauge :
610
600
with self ._lock :
611
601
if self ._real_meter :
@@ -620,7 +610,6 @@ def create_observable_gauge(
620
610
callbacks : Optional [Sequence [CallbackT ]] = None ,
621
611
unit : str = "" ,
622
612
description : str = "" ,
623
- advisory : Optional [MetricsCommonAdvisory ] = None ,
624
613
) -> ObservableGauge :
625
614
with self ._lock :
626
615
if self ._real_meter :
@@ -639,7 +628,6 @@ def create_observable_up_down_counter(
639
628
callbacks : Optional [Sequence [CallbackT ]] = None ,
640
629
unit : str = "" ,
641
630
description : str = "" ,
642
- advisory : Optional [MetricsCommonAdvisory ] = None ,
643
631
) -> ObservableUpDownCounter :
644
632
with self ._lock :
645
633
if self ._real_meter :
@@ -667,11 +655,10 @@ def create_counter(
667
655
name : str ,
668
656
unit : str = "" ,
669
657
description : str = "" ,
670
- advisory : Optional [MetricsCommonAdvisory ] = None ,
671
658
) -> Counter :
672
659
"""Returns a no-op Counter."""
673
660
status = self ._register_instrument (
674
- name , NoOpCounter , unit , description , advisory
661
+ name , NoOpCounter , unit , description
675
662
)
676
663
if status .conflict :
677
664
self ._log_instrument_registration_conflict (
@@ -689,12 +676,9 @@ def create_gauge(
689
676
name : str ,
690
677
unit : str = "" ,
691
678
description : str = "" ,
692
- advisory : Optional [MetricsCommonAdvisory ] = None ,
693
679
) -> Gauge :
694
680
"""Returns a no-op Gauge."""
695
- status = self ._register_instrument (
696
- name , NoOpGauge , unit , description , advisory
697
- )
681
+ status = self ._register_instrument (name , NoOpGauge , unit , description )
698
682
if status .conflict :
699
683
self ._log_instrument_registration_conflict (
700
684
name ,
@@ -710,11 +694,10 @@ def create_up_down_counter(
710
694
name : str ,
711
695
unit : str = "" ,
712
696
description : str = "" ,
713
- advisory : Optional [MetricsCommonAdvisory ] = None ,
714
697
) -> UpDownCounter :
715
698
"""Returns a no-op UpDownCounter."""
716
699
status = self ._register_instrument (
717
- name , NoOpUpDownCounter , unit , description , advisory
700
+ name , NoOpUpDownCounter , unit , description
718
701
)
719
702
if status .conflict :
720
703
self ._log_instrument_registration_conflict (
@@ -732,11 +715,10 @@ def create_observable_counter(
732
715
callbacks : Optional [Sequence [CallbackT ]] = None ,
733
716
unit : str = "" ,
734
717
description : str = "" ,
735
- advisory : Optional [MetricsCommonAdvisory ] = None ,
736
718
) -> ObservableCounter :
737
719
"""Returns a no-op ObservableCounter."""
738
720
status = self ._register_instrument (
739
- name , NoOpObservableCounter , unit , description , advisory
721
+ name , NoOpObservableCounter , unit , description
740
722
)
741
723
if status .conflict :
742
724
self ._log_instrument_registration_conflict (
@@ -758,11 +740,18 @@ def create_histogram(
758
740
name : str ,
759
741
unit : str = "" ,
760
742
description : str = "" ,
761
- advisory : Optional [MetricsHistogramAdvisory ] = None ,
743
+ explicit_bucket_boundaries_advisory : Optional [Sequence [ float ] ] = None ,
762
744
) -> Histogram :
763
745
"""Returns a no-op Histogram."""
746
+ # FIXME: should be use a dataclass here instead for the advisory param?
764
747
status = self ._register_instrument (
765
- name , NoOpHistogram , unit , description , advisory
748
+ name ,
749
+ NoOpHistogram ,
750
+ unit ,
751
+ description ,
752
+ {
753
+ "explicit_bucket_boundaries_advisory" : explicit_bucket_boundaries_advisory
754
+ },
766
755
)
767
756
if status .conflict :
768
757
self ._log_instrument_registration_conflict (
@@ -773,7 +762,10 @@ def create_histogram(
773
762
status ,
774
763
)
775
764
return NoOpHistogram (
776
- name , unit = unit , description = description , advisory = advisory
765
+ name ,
766
+ unit = unit ,
767
+ description = description ,
768
+ explicit_bucket_boundaries_advisory = explicit_bucket_boundaries_advisory ,
777
769
)
778
770
779
771
def create_observable_gauge (
@@ -782,11 +774,10 @@ def create_observable_gauge(
782
774
callbacks : Optional [Sequence [CallbackT ]] = None ,
783
775
unit : str = "" ,
784
776
description : str = "" ,
785
- advisory : Optional [MetricsCommonAdvisory ] = None ,
786
777
) -> ObservableGauge :
787
778
"""Returns a no-op ObservableGauge."""
788
779
status = self ._register_instrument (
789
- name , NoOpObservableGauge , unit , description , advisory
780
+ name , NoOpObservableGauge , unit , description
790
781
)
791
782
if status .conflict :
792
783
self ._log_instrument_registration_conflict (
@@ -809,11 +800,10 @@ def create_observable_up_down_counter(
809
800
callbacks : Optional [Sequence [CallbackT ]] = None ,
810
801
unit : str = "" ,
811
802
description : str = "" ,
812
- advisory : Optional [MetricsCommonAdvisory ] = None ,
813
803
) -> ObservableUpDownCounter :
814
804
"""Returns a no-op ObservableUpDownCounter."""
815
805
status = self ._register_instrument (
816
- name , NoOpObservableUpDownCounter , unit , description , advisory
806
+ name , NoOpObservableUpDownCounter , unit , description
817
807
)
818
808
if status .conflict :
819
809
self ._log_instrument_registration_conflict (
0 commit comments