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

KeyError: 'wsgi.url_scheme' #185

Closed
OmarEltamasehy opened this issue Nov 16, 2020 · 3 comments · Fixed by #391
Closed

KeyError: 'wsgi.url_scheme' #185

OmarEltamasehy opened this issue Nov 16, 2020 · 3 comments · Fixed by #391
Labels
backlog bug Something isn't working

Comments

@OmarEltamasehy
Copy link

Hi,
Appreciate your support as we try to use DjangoInstrumentor().instrument()
after importing opentelemetry.instrumentation.django as the below
from opentelemetry.instrumentation.django import DjangoInstrumentor
and we are using django_channels dev server in my project but unfortunately, we faced the below issue and we tried to set "wsgi.url_scheme" by our self in python3.8/site-packages/opentelemetry/instrumentation/django/middleware.py and it is ok so please advice if there is another solution to do.

My environment:

Django version 3.1.2
python version 3.8

sever error log

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'

thanks for your time
@oeltamasehy@cloudinn.net

@OmarEltamasehy OmarEltamasehy added the bug Something isn't working label Nov 16, 2020
@adamantike
Copy link
Contributor

Related to #280 and #334.

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.
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.
@github-actions
Copy link

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

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants