From 8c459795b0268462dff7ec670d8c4a93ebf56a0a 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..40f9e5ae88 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 requests span attributes available to Django sampler + ([#1645](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1645)) + ### 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 )