Open sentrivana opened 6 months ago
What I just noticed. In our starlette integration when using the decorator on _sentry_patched_asgi_app
the error occurs. In the stacktrace above it is in asgi2.py
in uvicorn. And our integration calls our internal _run_asgi3
. So maybe it has something to do with ASGI 2 and 3 protocoll differences.
In my investigation, I found that the issue comes from this part in uvicorn:
Basically, it tries to call the "app" (which can be an app factory at this point) with no arguments, and it expects the call to fail if you have an app and not a factory. However, the patched app.__call__
succeeds with no arguments, which leads uvicorn to think it was given an app factory instead of an app (hence the WARNING: ASGI app factory detected. Using it, but please consider setting the --factory flag explicitly.
in #3021).
Then, the inspect.isfunction(self.loaded_app)
returns false though I wasn't able to pinpoint why at the moment. This leads to uvicorn calling the app with ASGI2.
Hope this helps a little!
Two different ways in which the decorator seems to alter the behavior of the decorated function. Unsure whether it's the same issue or two different ones.
1. Repro via a simple Starlette app
Install
sentry-sdk==2.0.0
,uvicorn
,starlette
.Create a simple Starlette app as
app.py
:Run with
uvicorn app:app
.Request
http://127.0.0.1:8000/
(or wherever your server is running). We didn't define any routes so it's not expected to resolve -- you should get a 404. Instead you'll get a 500:If you remove the
ensure_integration_enabled_async
decorator from the Starlette integration, rerun the server and request/
again, you'll get a 404 as expected.2. Repro via tests
_create_span_call
wrapper with theensure_integration_enabled_async
decorator.The tests will fail, even though the code should behave the same way as before the change.
This can also be observed with Starlette in CI on this PR: these are the failing tests, and this change makes the tests green.
I've observed this in other integrations as well, so it appears to be a problem with the decorator itself. The sync version of the decorator works without issues.