Documentation for FastAPI/Starlette ASGI not correct
See original GitHub issueEnvironment
How do you use Sentry? Sentry SaaS (sentry.io)
Which SDK and version? python sentry-sdk==1.4.3 via pipenv
Steps to Reproduce
- Followed the installation instructions in an FastAPI app
- Run a HTTP request against the API
Expected Result
Sentry logging errors
Actual Result
AttributeError: 'SentryAsgiMiddleware' object has no attribute 'add_middleware'
Analysis
I think the issue can be fixed by changing the way the middleware is added:
app = FastAPI()
app.add_middleware(SentryAsgiMiddleware)
That being said, I am not getting errors logged when I call a route that runs raise HTTPException(status_code=500, detail="Test")
. So I think the middleware is still not working.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Advanced Middleware - FastAPI
As FastAPI is based on Starlette and implements the ASGI specification, you can use any ASGI middleware. A middleware doesn't have to be...
Read more >Starlette
Starlette is a lightweight ASGI framework/toolkit, which is ideal for building async web services in Python. It is production-ready, and gives you the ......
Read more >Middleware - Starlette
An abstract class that allows you to write ASGI middleware against a request/response interface. Usage. To implement a middleware class using BaseHTTPMiddleware ...
Read more >Responses - Starlette
Responses. Starlette includes a few response classes that handle sending back the appropriate ASGI messages on the send channel.
Read more >Static Files - Starlette
Defaults to True . You can combine this ASGI application with Starlette's routing to provide comprehensive static file serving.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for raising an issue. You’ll need to use the ASGI middleware in conjugation with
app.exception_handler
. We have to improve our documentation here - and in general have a better story around FastAPI.For the future, we probably should just monkey patch the
exception_handler
so we take care of this out of the box.so if create an exception that isn’t caught by FastAPI (f.e.
raise ValueError("nope")
) it seems to log it properly. So am I wrong to assume that HTTPException should be converted or does this indeed just show that the middleware isn’t properly installed?