-
Notifications
You must be signed in to change notification settings - Fork 518
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
SentryAsgiMiddleware not compatible with Uvicorn 0.13.0 #947
Comments
Does Sanic expose asgi-2 interface or asgi-3? Our detection may be off by a bit. I would append
|
@untitaker thanks for the reply! Both of them seem to successfully start up, a log is presented that the ASGI 'lifespan' protocol is not supported:
Once I try to create request: from sanic import Sanic
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
def create_app():
app = Sanic()
@app.get("/")
def root(request):
return "OK"
return app
app = SentryAsgiMiddleware(create_app())._run_asgi3 I get the following error / logs:
|
Right, then you need |
Both the I tried editing the |
Was able to get it running with I will keep this issue open but I think we may just drop ASGI 2 support instead of actually fixing this issue. There's too much inspection magic going on inside of the SDK and inside of uvicorn to figure out with which arguments to call the app. |
Great, works indeed. Thanks! |
I am getting the same problem, but this time with Interestingly, I don't seem to need to actually call the middleware.
seems to catch errors and report them, even if no-one is actually calling dummy_app. It is as though Sentry somehow hooks it self into the app.... |
@kristjanvalur then the middleware is not the one doing the error-capturing. But that's fine, its primary purpose is to attach request data to events. Error handling may be done via error logs as well. |
I'm using FastAPI. |
What exact error do you get? I wonder which version gunicorn attempts to use |
This is how I invoke the server:
So, using app = SentryAsgiMiddleware(app), I get:
and the server won't start up at all. If I add the _run_asgi2 or _run_asgi3 property access to the Middleware, the servers tarts, but on the first request, I get respectively
and
|
We're seeing this as well with the latest FastAPI + uvicorn:
|
I'm not a ASGI expert. I used to know WSGI. Is there a wrapper I can write to make the middleware callable without waiting for an upstream fix? |
Hm. Okay here is a workaround that does not involve setting any server options:
The problem really is that uvicorn tries to inspect method signatures too much to figure out what to call... it calls |
interesting. I'll mention this with the uvicorn devs. thanks for the help. |
@kristjanvalur I don't think they can do much about it fwiw. It's just something we'll have to see through until asgi2 is dead. |
Actually, the wrapper class above is problematic, because the parent class defines an instance attribute,
There is no need to explicitly call the _run_asgi3 method, signature detection of the middleware seems to work. It is only the code that is trying to analyze how to call the middleware (from uvicorn) that fails. 1 It fails to understand a call instance attribute which is a bound method. Not sure if we should continue this, but it could help to point out that the SentryAsgiMiddleware has an unusal way of being callable and that it might need to be wrapped like above in certain "smart" frameworks. |
Well, if there is a way for uvicorn.workers.Uvicornworker to somehow accept arguments. or have a subclass that just assumes protocol 3. |
@kristjanvalur fair enough, so the fn body is actually irrelevant, yeah. I think the way forward is to drop asgi2 support, then the "unusual way" disappears |
Hey folks, Could anyone using the Sentry ASGI middleware install Uvicorn from encode/uvicorn#914 as a quick confirmation that it fixes the problem seen here? pip install "git+https://github.com/encode/uvicorn.git@fm/factory-inspection#egg=uvicorn" |
@florimondmanca works for me! |
Sweet. :) |
Are y'all sure about this? I don't see how the middleware exposes itself as app factory. |
It doesn't, but due to the |
This is affecting Django users (me) as well as the above Sanic |
@jesenbox Feel free to try the latest state as referred to in #947 (comment) — should make it go away (you might have to install from master now, feel free to use a specific commit hash). We'll go ahead and issue a new release of Uvicorn with this patch soon. |
Are you still experiencing this error with the latest version of |
It's fixed, from my end. |
I think this issue can be closed, after the implemented fixes. |
inspect.py
this is the problem line.
sets the call attribute for the object instance and not the Class Since SentryAsgiMiddleware.call is technically a member_descriptor and not a function, Can we do something to somehow set |
did a quick hack
and commented
in SentryAsgiMiddleware.init The app started properly with the middleware. |
seems to be working without errors |
Arggh, my bad. Missed comment #947 (comment) which already does this! Wasted quite some time on this investigation! |
On December 8th Uvicorn updated from 0.12.3 to 0.13.0. This results in an error at startup, see output with minimal example. When downgrading Uvicorn to 0.12.3 the example runs fine.
Why this error is thrown or which changes resulted in the error, I have no clue. Could you help me with this?
app.py
requirements.txt
Command to run:
Output:
The text was updated successfully, but these errors were encountered: