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.

Django Middleware and ASGI

See original GitHub issue

I read that middleware was working last March per https://github.com/elastic/apm-agent-python/issues/737#issuecomment-597288157 so I have been investigating a transition from WSGI to ASGI.

I am hitting this problem:

 Traceback (most recent call last):
   File "/django/core/handlers/exception.py", line 47, in inner
     response = get_response(request)
   File "/django/utils/deprecation.py", line 116, in __call__
     response = self.process_response(request, response)
   File "/elasticapm/contrib/django/middleware/__init__.py", line 114, in process_response_wrapper
     response = wrapped(*args, **kwargs)
   File "/wagtail/contrib/redirects/middleware.py", line 37, in process_response
     if response.status_code != 404:
 AttributeError: 'coroutine' object has no attribute 'status_code'

Relevant packages per the linked issue comment

Python 3.7.10
elastic-apm==6.0.0
asgiref==3.3.1
Django==3.1.6

Any tips?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
beniwohlicommented, Feb 18, 2021

@thenewguy ELASTIC_APM_INSTRUMENT_DJANGO_MIDDLEWARE doesn’t prevent installation of our middleware, but instrumentation of all other middleware. I suspected that there could be an issue with our middleware instrumentation, but that turned out to be not the case.

0reactions
thenewguycommented, Feb 17, 2021

After removing elasticapm from installed apps it seems like this isn’t an elasticapm problem and it was just in the traceback.

Should there be an issue for export ELASTIC_APM_INSTRUMENT_DJANGO_MIDDLEWARE=False not preventing the middleware from being installed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deploy with ASGI - Django documentation
To apply ASGI middleware, or to embed Django in another ASGI application, you can wrap Django's application object in the asgi.py file. For...
Read more >
Django 3.0 + Channels + ASGI + TokenAuthMiddleware
The problem is that you can't access synchronous code from an asynchronous context. Here is a TokenAuthMiddleware for Django 3.0:
Read more >
OpenTelemetry ASGI Instrumentation
This library provides a ASGI middleware that can be used on any ASGI framework (such as Django, Starlette, FastAPI or Quart) to track...
Read more >
feat: support Django asgi middleware by daniel-sanche · Pull ...
This PR updates our old deprecated MiddlewareMixin Django middleware to use the current best practices, which fixes a crashing bug when using modern...
Read more >
A Guide to ASGI in Django 3.0 and its Performance - Arunrocks
If you have a component that can play both roles, then you have created a “middleware” or an intermediate layer in this pipeline....
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