-
Notifications
You must be signed in to change notification settings - Fork 222
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
[Bug] asgi middleware doesn't see exceptions #1548
Comments
I'm a little unclear how The documentation introduced in #1528 only covers adding the new middleware but does not say anything about modifying or removing and previous installation methods. I recenty modified a standard Django 5.0 project which previously used WSGI to a Channels + Daphne ASGI setup with a light subclass of class DjangoASGITracingMiddleware(ASGITracingMiddleware):
"""Override the transaction name so that it reflects the URL. The default
implementation returns a very unhelpful e.g. "GET unknown route" which results in
APM lumping every transaction under that name.
"""
def set_transaction_name(self, method: str, url: str) -> None:
elasticapm.set_transaction_name(f"{method.upper()} {url}")
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter(
{
"http": DjangoASGITracingMiddleware(django_asgi_app, **connection_details),
}
) I wired up a basic async test view to trigger an async def test_asgi(request):
assert request.foo
return HttpResponse("Hello World") I see the exception captured in APM: This is only captured by using the dynamically injected If I remove "elasticapm.contrib.django" from INSTALLED_APPS, I lose exception tracking per this issue. (I also lose the CLIENT_SINGLETON created by If I only run "elasticapm.contrib.django" and remove It appears we need both the new tracing middleware to capture transactions and the old middleware to capture exceptions until this issue is resolved. By the way, is there a reason the |
@jsma In theory, if you're using the Django integration, you don't also need the Without the |
@jsma So I think the correct course of action here is to make the Django integration work with ASGI, rather than stacking the integrations. Would you mind making a separate issue for this work? Just bring over this last comment, effectively, showing that the Django integration doesn't work with ASGI. Thanks! |
As noted in #1528, the ASGI middleware doesn't see exceptions. We need to figure out why, so users of the middleware actually see unhandled exceptions.
Ref #1528 and #1341
The text was updated successfully, but these errors were encountered: