From 04e5c5449917b8b82550f24d40b451c142411fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1oz=20C=C3=A1rdenas?= Date: Mon, 27 Mar 2023 16:41:18 +0200 Subject: [PATCH] Pass request attributes to Sampler in Django --- CHANGELOG.md | 2 ++ .../instrumentation/django/middleware/otel_middleware.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b3191c27b..df1f3f3af3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1645](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1645)) - Add `excluded_urls` functionality to `urllib` and `urllib3` instrumentations ([#1733](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1733)) +- Make Django request span attributes available for `start_span`. + ([#1730](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1730)) ### Fixed diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py index 42cdf40812..1baa05eca9 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py @@ -212,6 +212,7 @@ def process_request(self, request): carrier_getter = wsgi_getter collect_request_attributes = wsgi_collect_request_attributes + attributes = collect_request_attributes(carrier) span, token = _start_internal_or_server_span( tracer=self._tracer, span_name=self._get_span_name(request), @@ -220,9 +221,9 @@ def process_request(self, request): ), context_carrier=carrier, context_getter=carrier_getter, + attributes=attributes, ) - attributes = collect_request_attributes(carrier) active_requests_count_attrs = _parse_active_request_count_attrs( attributes )