Skip to content

Commit 378fbab

Browse files
authored
Merge branch 'main' into proper-buckets-http-stable-wsgi
2 parents f42b543 + 5e4b558 commit 378fbab

File tree

11 files changed

+258
-59
lines changed

11 files changed

+258
-59
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
([#3012](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3012))
1818
- `opentelemetry-instrumentation-wsgi`: add explicit http duration buckets for stable semconv
1919
([#3527](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3527))
20+
- `opentelemetry-instrumentation-asgi`: add explicit http duration buckets for stable semconv
21+
([#3526](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3526))
22+
- `opentelemetry-instrumentation-flask`: proper bucket boundaries in stable semconv http duration
23+
([#3523](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3523))
24+
- `opentelemetry-instrumentation-django`: proper bucket boundaries in stable semconv http duration
25+
([#3524](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3524))
26+
- `opentelemetry-instrumentation-grpc`: support non-list interceptors
27+
([#3520](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3520))
2028

2129
### Breaking changes
2230

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
202202

203203
from opentelemetry import context, trace
204204
from opentelemetry.instrumentation._semconv import (
205+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
205206
_filter_semconv_active_request_count_attr,
206207
_filter_semconv_duration_attrs,
207208
_get_schema_url,
@@ -589,6 +590,7 @@ def __init__(
589590
name=HTTP_SERVER_REQUEST_DURATION,
590591
description="Duration of HTTP server requests.",
591592
unit="s",
593+
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
592594
)
593595
self.server_response_size_histogram = None
594596
if _report_old(sem_conv_opt_in_mode):

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import opentelemetry.instrumentation.asgi as otel_asgi
2424
from opentelemetry import trace as trace_api
2525
from opentelemetry.instrumentation._semconv import (
26+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
2627
OTEL_SEMCONV_STABILITY_OPT_IN,
2728
_OpenTelemetrySemanticConventionStability,
2829
_server_active_requests_count_attrs_new,
@@ -1245,6 +1246,7 @@ async def test_asgi_metrics(self):
12451246
self.assertTrue(number_data_point_seen and histogram_data_point_seen)
12461247

12471248
async def test_asgi_metrics_new_semconv(self):
1249+
# pylint: disable=too-many-nested-blocks
12481250
app = otel_asgi.OpenTelemetryMiddleware(simple_asgi)
12491251
self.seed_app(app)
12501252
await self.send_default_request()
@@ -1274,6 +1276,11 @@ async def test_asgi_metrics_new_semconv(self):
12741276
for point in data_points:
12751277
if isinstance(point, HistogramDataPoint):
12761278
self.assertEqual(point.count, 3)
1279+
if metric.name == "http.server.request.duration":
1280+
self.assertEqual(
1281+
point.explicit_bounds,
1282+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
1283+
)
12771284
histogram_data_point_seen = True
12781285
if isinstance(point, NumberDataPoint):
12791286
number_data_point_seen = True
@@ -1284,6 +1291,7 @@ async def test_asgi_metrics_new_semconv(self):
12841291
self.assertTrue(number_data_point_seen and histogram_data_point_seen)
12851292

12861293
async def test_asgi_metrics_both_semconv(self):
1294+
# pylint: disable=too-many-nested-blocks
12871295
app = otel_asgi.OpenTelemetryMiddleware(simple_asgi)
12881296
self.seed_app(app)
12891297
await self.send_default_request()
@@ -1313,6 +1321,11 @@ async def test_asgi_metrics_both_semconv(self):
13131321
for point in data_points:
13141322
if isinstance(point, HistogramDataPoint):
13151323
self.assertEqual(point.count, 3)
1324+
if metric.name == "http.server.request.duration":
1325+
self.assertEqual(
1326+
point.explicit_bounds,
1327+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
1328+
)
13161329
histogram_data_point_seen = True
13171330
if isinstance(point, NumberDataPoint):
13181331
number_data_point_seen = True

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def response_hook(span, request, response):
246246
from django.core.exceptions import ImproperlyConfigured
247247

248248
from opentelemetry.instrumentation._semconv import (
249+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
249250
_get_schema_url,
250251
_OpenTelemetrySemanticConventionStability,
251252
_OpenTelemetryStabilitySignalType,
@@ -378,6 +379,7 @@ def _instrument(self, **kwargs):
378379
name=HTTP_SERVER_REQUEST_DURATION,
379380
description="Duration of HTTP server requests.",
380381
unit="s",
382+
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
381383
)
382384
_DjangoMiddleware._active_request_counter = (
383385
create_http_server_active_requests(meter)

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
from opentelemetry import trace
2828
from opentelemetry.instrumentation._semconv import (
29+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
30+
HTTP_DURATION_HISTOGRAM_BUCKETS_OLD,
2931
OTEL_SEMCONV_STABILITY_OPT_IN,
3032
_OpenTelemetrySemanticConventionStability,
3133
)
@@ -814,6 +816,10 @@ def test_wsgi_metrics_new_semconv(self):
814816
expected_duration_attributes,
815817
dict(point.attributes),
816818
)
819+
self.assertEqual(
820+
point.explicit_bounds,
821+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
822+
)
817823
if isinstance(point, NumberDataPoint):
818824
number_data_point_seen = True
819825
self.assertEqual(point.value, 0)
@@ -886,6 +892,10 @@ def test_wsgi_metrics_both_semconv(self):
886892
expected_duration_attributes_new,
887893
dict(point.attributes),
888894
)
895+
self.assertEqual(
896+
point.explicit_bounds,
897+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
898+
)
889899
elif metric.name == "http.server.duration":
890900
self.assertAlmostEqual(
891901
duration, point.sum, delta=100
@@ -894,6 +904,10 @@ def test_wsgi_metrics_both_semconv(self):
894904
expected_duration_attributes_old,
895905
dict(point.attributes),
896906
)
907+
self.assertEqual(
908+
point.explicit_bounds,
909+
HTTP_DURATION_HISTOGRAM_BUCKETS_OLD,
910+
)
897911
if isinstance(point, NumberDataPoint):
898912
number_data_point_seen = True
899913
self.assertEqual(point.value, 0)

instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
ElasticsearchInstrumentor,
3232
)
3333
from opentelemetry.instrumentation.elasticsearch.utils import sanitize_body
34-
from opentelemetry.semconv.trace import SpanAttributes
34+
from opentelemetry.semconv._incubating.attributes.db_attributes import (
35+
DB_STATEMENT,
36+
DB_SYSTEM,
37+
)
3538
from opentelemetry.test.test_base import TestBase
3639
from opentelemetry.trace import StatusCode
3740

@@ -76,15 +79,15 @@ def get_elasticsearch_client(*args, **kwargs):
7679
)
7780
class TestElasticsearchIntegration(TestBase):
7881
search_attributes = {
79-
SpanAttributes.DB_SYSTEM: "elasticsearch",
82+
DB_SYSTEM: "elasticsearch",
8083
"elasticsearch.url": "/test-index/_search",
8184
"elasticsearch.method": helpers.dsl_search_method,
8285
"elasticsearch.target": "test-index",
83-
SpanAttributes.DB_STATEMENT: str({"query": {"bool": {"filter": "?"}}}),
86+
DB_STATEMENT: str({"query": {"bool": {"filter": "?"}}}),
8487
}
8588

8689
create_attributes = {
87-
SpanAttributes.DB_SYSTEM: "elasticsearch",
90+
DB_SYSTEM: "elasticsearch",
8891
"elasticsearch.url": "/test-index",
8992
"elasticsearch.method": "HEAD",
9093
}
@@ -361,13 +364,13 @@ def test_dsl_create(self, request_mock):
361364
)
362365

363366
attributes = {
364-
SpanAttributes.DB_SYSTEM: "elasticsearch",
367+
DB_SYSTEM: "elasticsearch",
365368
"elasticsearch.url": "/test-index",
366369
"elasticsearch.method": "PUT",
367370
}
368371
self.assertSpanHasAttributes(span2, attributes)
369372
self.assertEqual(
370-
literal_eval(span2.attributes[SpanAttributes.DB_STATEMENT]),
373+
literal_eval(span2.attributes[DB_STATEMENT]),
371374
helpers.dsl_create_statement,
372375
)
373376

@@ -408,13 +411,13 @@ def test_dsl_index(self, request_mock):
408411
span = spans[0]
409412
self.assertEqual(span.name, helpers.dsl_index_span_name)
410413
attributes = {
411-
SpanAttributes.DB_SYSTEM: "elasticsearch",
414+
DB_SYSTEM: "elasticsearch",
412415
"elasticsearch.url": helpers.dsl_index_url,
413416
"elasticsearch.method": "PUT",
414417
}
415418
self.assertSpanHasAttributes(span, attributes)
416419
self.assertEqual(
417-
literal_eval(span.attributes[SpanAttributes.DB_STATEMENT]),
420+
literal_eval(span.attributes[DB_STATEMENT]),
418421
{
419422
"body": "A few words here, a few words there",
420423
"title": "About searching",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def response_hook(span: Span, status: str, response_headers: List):
257257
import opentelemetry.instrumentation.wsgi as otel_wsgi
258258
from opentelemetry import context, trace
259259
from opentelemetry.instrumentation._semconv import (
260+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
260261
_get_schema_url,
261262
_OpenTelemetrySemanticConventionStability,
262263
_OpenTelemetryStabilitySignalType,
@@ -583,6 +584,7 @@ def __init__(self, *args, **kwargs):
583584
name=HTTP_SERVER_REQUEST_DURATION,
584585
unit="s",
585586
description="Duration of HTTP server requests.",
587+
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
586588
)
587589
active_requests_counter = meter.create_up_down_counter(
588590
name=MetricInstruments.HTTP_SERVER_ACTIVE_REQUESTS,
@@ -716,6 +718,7 @@ def instrument_app(
716718
name=HTTP_SERVER_REQUEST_DURATION,
717719
unit="s",
718720
description="Duration of HTTP server requests.",
721+
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
719722
)
720723
active_requests_counter = meter.create_up_down_counter(
721724
name=MetricInstruments.HTTP_SERVER_ACTIVE_REQUESTS,

instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from opentelemetry import trace
2222
from opentelemetry.instrumentation._semconv import (
23+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
2324
OTEL_SEMCONV_STABILITY_OPT_IN,
2425
_OpenTelemetrySemanticConventionStability,
2526
_server_active_requests_count_attrs_new,
@@ -522,6 +523,10 @@ def test_flask_metrics_new_semconv(self):
522523
self.assertAlmostEqual(
523524
duration_s, point.sum, places=1
524525
)
526+
self.assertEqual(
527+
point.explicit_bounds,
528+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
529+
)
525530
histogram_data_point_seen = True
526531
if isinstance(point, NumberDataPoint):
527532
number_data_point_seen = True
@@ -552,8 +557,12 @@ def test_flask_metric_values(self):
552557
self.assertEqual(point.value, 0)
553558

554559
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,
556564
):
565+
# pylint: disable=too-many-nested-blocks
557566
metrics_list = self.memory_metrics_reader.get_metrics_data()
558567
for resource_metric in metrics_list.resource_metrics:
559568
for scope_metrics in resource_metric.scope_metrics:
@@ -564,6 +573,11 @@ def _assert_basic_metric(
564573
expected_duration_attributes,
565574
dict(point.attributes),
566575
)
576+
if expected_histogram_explicit_bounds is not None:
577+
self.assertEqual(
578+
expected_histogram_explicit_bounds,
579+
point.explicit_bounds,
580+
)
567581
self.assertEqual(point.count, 1)
568582
elif isinstance(point, NumberDataPoint):
569583
self.assertDictEqual(
@@ -613,6 +627,7 @@ def test_basic_metric_success_new_semconv(self):
613627
self._assert_basic_metric(
614628
expected_duration_attributes,
615629
expected_requests_count_attributes,
630+
expected_histogram_explicit_bounds=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
616631
)
617632

618633
def test_basic_metric_nonstandard_http_method_success(self):
@@ -654,6 +669,7 @@ def test_basic_metric_nonstandard_http_method_success_new_semconv(self):
654669
self._assert_basic_metric(
655670
expected_duration_attributes,
656671
expected_requests_count_attributes,
672+
expected_histogram_explicit_bounds=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
657673
)
658674

659675
@patch.dict(
@@ -679,6 +695,7 @@ def test_basic_metric_nonstandard_http_method_allowed_success_new_semconv(
679695
self._assert_basic_metric(
680696
expected_duration_attributes,
681697
expected_requests_count_attributes,
698+
expected_histogram_explicit_bounds=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
682699
)
683700

684701
def test_metric_uninstrument(self):

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ def _instrument(self, **kwargs):
334334
tracer_provider = kwargs.get("tracer_provider")
335335

336336
def server(*args, **kwargs):
337-
if "interceptors" in kwargs:
337+
if "interceptors" in kwargs and kwargs["interceptors"]:
338+
kwargs["interceptors"] = list(kwargs["interceptors"])
338339
# add our interceptor as the first
339340
kwargs["interceptors"].insert(
340341
0,
@@ -348,6 +349,7 @@ def server(*args, **kwargs):
348349
tracer_provider=tracer_provider, filter_=self._filter
349350
)
350351
]
352+
351353
return self._original_func(*args, **kwargs)
352354

353355
grpc.server = server
@@ -386,7 +388,8 @@ def _instrument(self, **kwargs):
386388
tracer_provider = kwargs.get("tracer_provider")
387389

388390
def server(*args, **kwargs):
389-
if "interceptors" in kwargs:
391+
if "interceptors" in kwargs and kwargs["interceptors"]:
392+
kwargs["interceptors"] = list(kwargs["interceptors"])
390393
# add our interceptor as the first
391394
kwargs["interceptors"].insert(
392395
0,
@@ -516,6 +519,7 @@ def instrumentation_dependencies(self) -> Collection[str]:
516519

517520
def _add_interceptors(self, tracer_provider, kwargs):
518521
if "interceptors" in kwargs and kwargs["interceptors"]:
522+
kwargs["interceptors"] = list(kwargs["interceptors"])
519523
kwargs["interceptors"] = (
520524
aio_client_interceptors(
521525
tracer_provider=tracer_provider,

0 commit comments

Comments
 (0)