From df0ca3b60414c089a4c7ee7bf535282504cab0c3 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Wed, 14 Jul 2021 23:52:29 +0530 Subject: [PATCH] Fix AttributeError: `ResolverMatch` object has no attribute `route` (#581) --- CHANGELOG.md | 2 ++ .../src/opentelemetry/instrumentation/django/middleware.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df68c6593d..9b45f3cfe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-requests` Fix potential `AttributeError` when `requests` is used with a custom transport adapter. ([#562](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/562)) +- `opentelemetry-instrumentation-django` Fix AttributeError: ResolverMatch object has no attribute route + ([#581](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/581)) ### Added - `opentelemetry-instrumentation-httpx` Add `httpx` instrumentation 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 b651d94c53..7fcd3dd158 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py @@ -191,9 +191,9 @@ def process_view(self, request, view_func, *args, **kwargs): span = request.META[self._environ_span_key] if span.is_recording(): - match = getattr(request, "resolver_match") + match = getattr(request, "resolver_match", None) if match: - route = getattr(match, "route") + route = getattr(match, "route", None) if route: span.set_attribute(SpanAttributes.HTTP_ROUTE, route)