20
20
21
21
from opentelemetry import trace
22
22
from opentelemetry .instrumentation ._semconv import (
23
+ HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
23
24
OTEL_SEMCONV_STABILITY_OPT_IN ,
24
25
_OpenTelemetrySemanticConventionStability ,
25
26
_server_active_requests_count_attrs_new ,
@@ -522,6 +523,10 @@ def test_flask_metrics_new_semconv(self):
522
523
self .assertAlmostEqual (
523
524
duration_s , point .sum , places = 1
524
525
)
526
+ self .assertEqual (
527
+ point .explicit_bounds ,
528
+ HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
529
+ )
525
530
histogram_data_point_seen = True
526
531
if isinstance (point , NumberDataPoint ):
527
532
number_data_point_seen = True
@@ -552,8 +557,12 @@ def test_flask_metric_values(self):
552
557
self .assertEqual (point .value , 0 )
553
558
554
559
def _assert_basic_metric (
555
- self , expected_duration_attributes , expected_requests_count_attributes
560
+ self ,
561
+ expected_duration_attributes ,
562
+ expected_requests_count_attributes ,
563
+ expected_histogram_explicit_bounds = None ,
556
564
):
565
+ # pylint: disable=too-many-nested-blocks
557
566
metrics_list = self .memory_metrics_reader .get_metrics_data ()
558
567
for resource_metric in metrics_list .resource_metrics :
559
568
for scope_metrics in resource_metric .scope_metrics :
@@ -564,6 +573,11 @@ def _assert_basic_metric(
564
573
expected_duration_attributes ,
565
574
dict (point .attributes ),
566
575
)
576
+ if expected_histogram_explicit_bounds is not None :
577
+ self .assertEqual (
578
+ expected_histogram_explicit_bounds ,
579
+ point .explicit_bounds ,
580
+ )
567
581
self .assertEqual (point .count , 1 )
568
582
elif isinstance (point , NumberDataPoint ):
569
583
self .assertDictEqual (
@@ -613,6 +627,7 @@ def test_basic_metric_success_new_semconv(self):
613
627
self ._assert_basic_metric (
614
628
expected_duration_attributes ,
615
629
expected_requests_count_attributes ,
630
+ expected_histogram_explicit_bounds = HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
616
631
)
617
632
618
633
def test_basic_metric_nonstandard_http_method_success (self ):
@@ -654,6 +669,7 @@ def test_basic_metric_nonstandard_http_method_success_new_semconv(self):
654
669
self ._assert_basic_metric (
655
670
expected_duration_attributes ,
656
671
expected_requests_count_attributes ,
672
+ expected_histogram_explicit_bounds = HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
657
673
)
658
674
659
675
@patch .dict (
@@ -679,6 +695,7 @@ def test_basic_metric_nonstandard_http_method_allowed_success_new_semconv(
679
695
self ._assert_basic_metric (
680
696
expected_duration_attributes ,
681
697
expected_requests_count_attributes ,
698
+ expected_histogram_explicit_bounds = HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
682
699
)
683
700
684
701
def test_metric_uninstrument (self ):
0 commit comments