From 86d15b50ddc526fc26d21adb9a29f304bfb365bf Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Thu, 24 Oct 2024 15:03:48 +0530 Subject: [PATCH] fix: provide ASGI support with Django Signed-off-by: Varsha GS --- src/instana/instrumentation/django/middleware.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/instana/instrumentation/django/middleware.py b/src/instana/instrumentation/django/middleware.py index d14851630..53e3aed5a 100644 --- a/src/instana/instrumentation/django/middleware.py +++ b/src/instana/instrumentation/django/middleware.py @@ -2,7 +2,6 @@ # (c) Copyright Instana Inc. 2018 -import os import sys import opentracing as ot @@ -45,7 +44,7 @@ def _extract_custom_headers(self, span, headers, format): def process_request(self, request): try: - env = request.environ + env = request.META ctx = tracer.extract(ot.Format.HTTP_HEADERS, env) request.iscope = tracer.start_active_span('django', child_of=ctx) @@ -92,7 +91,7 @@ def process_response(self, request, response): except Exception: logger.debug("Instana middleware @ process_response", exc_info=True) finally: - if request.iscope is not None: + if hasattr(request, "iscope") and request.iscope: request.iscope.close() request.iscope = None return response