question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in opentelemetry/instrumentation/django/middleware.py related to "wsgi.url_scheme"

See original GitHub issue

Hi, Appreciate your support. We try to use DjangoInstrumentor by putting it in settings.py as the below,


from opentelemetry.instrumentation.django import DjangoInstrumentor
DjangoInstrumentor().instrument()

Our application uses Django channels and the above code gives us an error. After debugging we found out that the cause of the error is in opentelemetry/instrumentation/django/middleware.py related to “wsgi.url_scheme”. Please check the stacktrace for details.

Any thoughts on how to bypass this issue in both development and production servers ?

My environment: Django version 3.1.2 Python version 3.8 Channels version 2.2.0

Stack trace:


Traceback (most recent call last):
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/django/utils/deprecation.py", line 113, in __call__
    response = self.process_request(request)
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/opentelemetry/instrumentation/django/middleware.py", line 140, in process_request
    attributes = collect_request_attributes(environ)
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/opentelemetry/instrumentation/wsgi/__init__.py", line 122, in collect_request_attributes
    result["http.url"] = wsgiref_util.request_uri(environ)
  File "/usr/lib/python3.8/wsgiref/util.py", line 72, in request_uri
    url = application_uri(environ)
  File "/usr/lib/python3.8/wsgiref/util.py", line 52, in application_uri
    url = environ['wsgi.url_scheme']+'://'
KeyError: 'wsgi.url_scheme'
[public ERROR  ] Internal Server Error: /
Traceback (most recent call last):
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/django/utils/deprecation.py", line 113, in __call__
    response = self.process_request(request)
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/opentelemetry/instrumentation/django/middleware.py", line 140, in process_request
    attributes = collect_request_attributes(environ)
  File "/home/omar/workspace/testapp/testapp/venv/lib/python3.8/site-packages/opentelemetry/instrumentation/wsgi/__init__.py", line 122, in collect_request_attributes
    result["http.url"] = wsgiref_util.request_uri(environ)
  File "/usr/lib/python3.8/wsgiref/util.py", line 72, in request_uri
    url = application_uri(environ)
  File "/usr/lib/python3.8/wsgiref/util.py", line 52, in application_uri
    url = environ['wsgi.url_scheme']+'://'
KeyError: 'wsgi.url_scheme'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adamantikecommented, Oct 15, 2021

@OmarEltamasehy, as this issue was automatically closed, I’m pinging you to let you know that Django ASGI support has been added in #391, and released in version 0.25b0. It requires installing opentelemetry-instrumentation-django with the asgi extra.

0reactions
github-actions[bot]commented, Jun 5, 2021

Closed as inactive. Feel free to reopen if this issue needs resolving.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in opentelemetry/instrumentation/django/middleware.py ...
Hi, Appreciate your support. ... Our application uses Django channels and the above code gives us an error. ... related to "wsgi.url_scheme". Please ......
Read more >
wsgi.py cannot be loaded as Python module Error / No ...
I have restart the project and this issue comes in each time I start using Postgres db, so my guess is that it...
Read more >
Debugging Techniques — mod_wsgi 4.9.4 documentation
An alternative to the Python debugger modules which is available is an extension of the WSGI error catching middleware previously described. This is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found