Skip to content

Django instrumentation assumes ASGI is only for Django3+ #1416

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

Open
pilhuhn opened this issue Oct 28, 2022 · 1 comment · May be fixed by #1418
Open

Django instrumentation assumes ASGI is only for Django3+ #1416

pilhuhn opened this issue Oct 28, 2022 · 1 comment · May be fixed by #1418
Labels
bug Something isn't working

Comments

@pilhuhn
Copy link

pilhuhn commented Oct 28, 2022

Describe your environment

My code is on Django 2.x. And I run into open-telemetry/opentelemetry-python#2833
Debugging down shows that the _is_asgi_request() in otel_middleware.py is thus determining that a request can't be an ASGI request.

Steps to reproduce

Just look at the code. Also when you continue and set is_asgi_request to True manually, my code works as expected

What is the expected behavior?

Just use ASGi and don't run into #2833

What is the actual behavior?

Run into #2833 as even valid ASGi requests are treated like WSGi ones, which then fails.

@pilhuhn pilhuhn added the bug Something isn't working label Oct 28, 2022
@pilhuhn
Copy link
Author

pilhuhn commented Oct 28, 2022

A fix in my case, as we use the channels.http library / channels package would be:

if DJANGO_3_0:
    from django.core.handlers.asgi import ASGIRequest
else:
    try:
        from channels.http import AsgiRequest
        ASGIRequest = AsgiRequest
    except ImportError:
        ASGIRequest = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant