From b9a8d764d57d8769f9db5a462ad812de15f95a66 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 | 3 +++ .../instrumentation/django/middleware/otel_middleware.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce84cd8a67..8b94afebd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1690](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1690)) - Add metrics instrumentation for sqlalchemy ([#1645](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1645)) +- 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 )