|
23 | 23 | import opentelemetry.instrumentation.requests |
24 | 24 | from opentelemetry import trace |
25 | 25 | from opentelemetry.instrumentation._semconv import ( |
26 | | - _DURATION_HISTOGRAM_NEW_EXPLICIT_BOUNDS, |
27 | | - _DURATION_HISTOGRAM_OLD_EXPLICIT_BOUNDS, |
| 26 | + DURATION_HISTOGRAM_EXPLICIT_BOUNDS_NEW, |
| 27 | + DURATION_HISTOGRAM_EXPLICIT_BOUNDS_OLD, |
28 | 28 | OTEL_SEMCONV_STABILITY_OPT_IN, |
29 | 29 | _OpenTelemetrySemanticConventionStability, |
30 | 30 | ) |
@@ -125,6 +125,7 @@ def setUp(self): |
125 | 125 | def tearDown(self): |
126 | 126 | super().tearDown() |
127 | 127 | self.env_patch.stop() |
| 128 | + _OpenTelemetrySemanticConventionStability._initialized = False |
128 | 129 | RequestsInstrumentor().uninstrument() |
129 | 130 | httpretty.disable() |
130 | 131 |
|
@@ -732,6 +733,7 @@ def setUp(self): |
732 | 733 | def tearDown(self): |
733 | 734 | super().tearDown() |
734 | 735 | self.env_patch.stop() |
| 736 | + _OpenTelemetrySemanticConventionStability._initialized = False |
735 | 737 | RequestsInstrumentor().uninstrument() |
736 | 738 | httpretty.disable() |
737 | 739 |
|
@@ -766,7 +768,7 @@ def test_basic_metric_success(self): |
766 | 768 | for data_point in metric.data.data_points: |
767 | 769 | self.assertEqual( |
768 | 770 | data_point.explicit_bounds, |
769 | | - _DURATION_HISTOGRAM_OLD_EXPLICIT_BOUNDS, |
| 771 | + DURATION_HISTOGRAM_EXPLICIT_BOUNDS_OLD, |
770 | 772 | ) |
771 | 773 | self.assertDictEqual( |
772 | 774 | expected_attributes, dict(data_point.attributes) |
@@ -796,7 +798,7 @@ def test_basic_metric_new_semconv(self): |
796 | 798 | for data_point in metric.data.data_points: |
797 | 799 | self.assertEqual( |
798 | 800 | data_point.explicit_bounds, |
799 | | - _DURATION_HISTOGRAM_NEW_EXPLICIT_BOUNDS, |
| 801 | + DURATION_HISTOGRAM_EXPLICIT_BOUNDS_NEW, |
800 | 802 | ) |
801 | 803 | self.assertDictEqual( |
802 | 804 | expected_attributes, dict(data_point.attributes) |
@@ -843,6 +845,38 @@ def test_basic_metric_both_semconv(self): |
843 | 845 | ) |
844 | 846 | self.assertEqual(data_point.count, 1) |
845 | 847 |
|
| 848 | + def test_custom_histogram_boundaries(self): |
| 849 | + RequestsInstrumentor().uninstrument() |
| 850 | + custom_boundaries = (0, 1, 2, 5, 10, 20, 50, 100) |
| 851 | + meter_provider, memory_reader = self.create_meter_provider() |
| 852 | + RequestsInstrumentor().instrument( |
| 853 | + meter_provider=meter_provider, |
| 854 | + duration_histogram_boundaries=custom_boundaries, |
| 855 | + ) |
| 856 | + |
| 857 | + self.perform_request(self.URL) |
| 858 | + metrics = memory_reader.get_metrics_data().resource_metrics[0] |
| 859 | + self.assertEqual(len(metrics.scope_metrics), 1) |
| 860 | + data_point = metrics.scope_metrics[0].metrics[0].data.data_points[0] |
| 861 | + self.assertEqual(data_point.explicit_bounds, custom_boundaries) |
| 862 | + self.assertEqual(data_point.count, 1) |
| 863 | + |
| 864 | + def test_custom_histogram_boundaries_new_semconv(self): |
| 865 | + RequestsInstrumentor().uninstrument() |
| 866 | + custom_boundaries = (0, 5, 10, 25, 50, 100, 250, 500, 1000) |
| 867 | + meter_provider, memory_reader = self.create_meter_provider() |
| 868 | + RequestsInstrumentor().instrument( |
| 869 | + meter_provider=meter_provider, |
| 870 | + duration_histogram_boundaries=custom_boundaries, |
| 871 | + ) |
| 872 | + |
| 873 | + self.perform_request(self.URL) |
| 874 | + metrics = memory_reader.get_metrics_data().resource_metrics[0] |
| 875 | + self.assertEqual(len(metrics.scope_metrics), 1) |
| 876 | + data_point = metrics.scope_metrics[0].metrics[0].data.data_points[0] |
| 877 | + self.assertEqual(data_point.explicit_bounds, custom_boundaries) |
| 878 | + self.assertEqual(data_point.count, 1) |
| 879 | + |
846 | 880 | def test_basic_metric_non_recording_span(self): |
847 | 881 | expected_attributes = { |
848 | 882 | SpanAttributes.HTTP_STATUS_CODE: 200, |
|
0 commit comments