Skip to content

Commit c1578c2

Browse files
committed
requests: add explicit_bucket_boundaries_advisory support for duration metrics
Signed-off-by: emdneto <[email protected]>
1 parent 7f347e5 commit c1578c2

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def response_hook(span, request_obj, response):
8787
from requests.structures import CaseInsensitiveDict
8888

8989
from opentelemetry.instrumentation._semconv import (
90+
_DURATION_HISTOGRAM_NEW_EXPLICIT_BOUNDS,
9091
_client_duration_attrs_new,
9192
_client_duration_attrs_old,
9293
_filter_semconv_duration_attrs,
@@ -445,6 +446,7 @@ def _instrument(self, **kwargs: Any):
445446
name=HTTP_CLIENT_REQUEST_DURATION,
446447
unit="s",
447448
description="Duration of HTTP client requests.",
449+
explicit_bucket_boundaries_advisory=_DURATION_HISTOGRAM_NEW_EXPLICIT_BOUNDS,
448450
)
449451
_instrument(
450452
tracer,

instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import opentelemetry.instrumentation.requests
2424
from opentelemetry import trace
2525
from opentelemetry.instrumentation._semconv import (
26+
_DURATION_HISTOGRAM_NEW_EXPLICIT_BOUNDS,
27+
_DURATION_HISTOGRAM_OLD_EXPLICIT_BOUNDS,
2628
OTEL_SEMCONV_STABILITY_OPT_IN,
2729
_OpenTelemetrySemanticConventionStability,
2830
)
@@ -762,6 +764,10 @@ def test_basic_metric_success(self):
762764
"measures the duration of the outbound HTTP request",
763765
)
764766
for data_point in metric.data.data_points:
767+
self.assertEqual(
768+
data_point.explicit_bounds,
769+
_DURATION_HISTOGRAM_OLD_EXPLICIT_BOUNDS,
770+
)
765771
self.assertDictEqual(
766772
expected_attributes, dict(data_point.attributes)
767773
)
@@ -788,6 +794,10 @@ def test_basic_metric_new_semconv(self):
788794
metric.description, "Duration of HTTP client requests."
789795
)
790796
for data_point in metric.data.data_points:
797+
self.assertEqual(
798+
data_point.explicit_bounds,
799+
_DURATION_HISTOGRAM_NEW_EXPLICIT_BOUNDS,
800+
)
791801
self.assertDictEqual(
792802
expected_attributes, dict(data_point.attributes)
793803
)

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,43 @@
4747
from opentelemetry.semconv.trace import SpanAttributes
4848
from opentelemetry.trace.status import Status, StatusCode
4949

50+
# Values defined in milliseconds
51+
_DURATION_HISTOGRAM_OLD_EXPLICIT_BOUNDS = (
52+
0.0,
53+
5.0,
54+
10.0,
55+
25.0,
56+
50.0,
57+
75.0,
58+
100.0,
59+
250.0,
60+
500.0,
61+
750.0,
62+
1000.0,
63+
2500.0,
64+
5000.0,
65+
7500.0,
66+
10000.0,
67+
)
68+
69+
# Values defined in seconds
70+
_DURATION_HISTOGRAM_NEW_EXPLICIT_BOUNDS = (
71+
0.005,
72+
0.01,
73+
0.025,
74+
0.05,
75+
0.075,
76+
0.1,
77+
0.25,
78+
0.5,
79+
0.75,
80+
1,
81+
2.5,
82+
5,
83+
7.5,
84+
10,
85+
)
86+
5087
# These lists represent attributes for metrics that are currently supported
5188

5289
_client_duration_attrs_old = [

0 commit comments

Comments
 (0)