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