From 3b0414fb76f4db1d2f47e3db9b567e6f2fdf0c7f Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Thu, 21 Oct 2021 21:08:50 -0300 Subject: [PATCH] django: Fix carrier usage on ASGI requests For ASGI requests, we must use `request.scope` instead of `request.META`. This is because `ASGIGetter` retrieves the `headers` key from the carrier [0], which is only present in `request.scope`. [0] https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L133 --- CHANGELOG.md | 2 ++ .../src/opentelemetry/instrumentation/django/middleware.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5afb9f39ba..941fa396f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#766](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/766)) - `opentelemetry-instrumentation-falcon` Dropped broken support for Python 3.4. ([#774](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/774)) +- `opentelemetry-instrumentation-django` Fixed carrier usage on ASGI requests. + ([#767](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/767)) ## [1.6.2-0.25b2](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.6.2-0.25b2) - 2021-10-19 diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py index 114f6f4a51..91af787c28 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py @@ -184,7 +184,7 @@ def process_request(self, request): carrier_getter = wsgi_getter collect_request_attributes = wsgi_collect_request_attributes - token = attach(extract(request_meta, getter=carrier_getter)) + token = attach(extract(carrier, getter=carrier_getter)) span = self._tracer.start_span( self._get_span_name(request),