Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
OmarEltamasehy opened this issue Dec 27, 2020 · 6 comments · Fixed by #391
Labels

Comments

@OmarEltamasehy
Copy link

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'
@lzchen
Copy link
Contributor

lzchen commented Jan 4, 2021

Moving to contrib repo.

@lzchen lzchen transferred this issue from open-telemetry/opentelemetry-python Jan 4, 2021
@OmarEltamasehy
Copy link
Author

Any update regarding this issue ?

@srikanthccv
Copy link
Member

@OmarEltamasehy Django instrumentation doesn't support the ASGI yet. There are also other things that should be done along with fixing this issue to make it work with ASGI. Please look at #334 for more details.

adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Mar 31, 2021
Still a WIP, this diff adds `asgi` as an extra, and uses its methods if
the current request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
@adamantike adamantike mentioned this issue Mar 31, 2021
7 tasks
adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Mar 31, 2021
Still a WIP, this diff adds `asgi` as an extra, and uses its methods if
the current request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
@github-actions
Copy link

github-actions bot commented Apr 6, 2021

This issue was marked stale due to lack of activity. It will be closed in 30 days.

adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Apr 6, 2021
Still a WIP, this diff adds `asgi` as an extra, and uses its methods if
the current request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue May 30, 2021
Still a WIP, this diff adds `asgi` as an extra, and uses its methods if
the current request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Jun 3, 2021
This diff adds `asgi` as an extra, and uses its methods if the current
request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
@github-actions
Copy link

github-actions bot commented Jun 5, 2021

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

@github-actions github-actions bot closed this as completed Jun 5, 2021
adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Jul 6, 2021
This diff adds `asgi` as an extra, and uses its methods if the current
request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Sep 21, 2021
This diff adds `asgi` as an extra, and uses its methods if the current
request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Sep 28, 2021
This diff adds `asgi` as an extra, and uses its methods if the current
request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
adamantike added a commit to adamantike/opentelemetry-python-contrib that referenced this issue Oct 11, 2021
This diff adds `asgi` as an extra, and uses its methods if the current
request is an `ASGIRequest`.

I still need to dig deeper in the current test suite, to find a way to
duplicate the tests in
`instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py`,
but using an
[`AsyncClient`](https://docs.djangoproject.com/en/3.1/topics/testing/tools/#testing-asynchronous-code).

Fixes open-telemetry#165, open-telemetry#185, open-telemetry#280, open-telemetry#334.
@adamantike
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants