Problem accessing to the request body after configure Sentry in FastAPI
See original GitHub issueSteps to Reproduce
- Create a Middleware to log the request body like https://stackoverflow.com/questions/70134618/why-does-fastapi-hang-when-adding-a-middleware-to-print-the-http-request-body
- The previous step works before configuring the Sentry SDK
- Configure the Sentry as defined in https://docs.sentry.io/platforms/python/guides/fastapi/
- When try to access to the test URL, the application hangs because the request body was already accessed by the Sentry integration
Expected Result
Simplified middleware example
@app.middleware("http")
async def logging_middleware(request: Request, call_next):
start_time = time.time()
body = await request.body()
print(body)
response = await call_next(request)`
return response
Actual Result
When the Sentry implementation is active, the body = await request.body()
line hangs and never response.
Additional Info
This answer has more information related to the problem https://stackoverflow.com/a/71811390/11030205
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Troubleshooting for FastAPI
The short answer to those: check if your contextvars work and you clone the hub where needed. Addressing Concurrency Issues. Python supports several...
Read more >Handling Errors - FastAPI
In this example, when the client requests an item by an ID that doesn't exist, ... a clean error, with an HTTP status...
Read more >FastAPI JSON List in body raises 'There was an error ...
I'm using python 3.10 on a linux ubuntu 22.04 vm with an ampere ARM processor if it matters... I've also tried the following...
Read more >tiangolo/fastapi - Gitter
Trying to enable the ASGI middleware.. and im not understanding the problem. import sentry_sdk from sentry_sdk.integrations.asgi import SentryAsgiMiddleware ...
Read more >Integrate Sentry to FastAPI - Phil Girard - Medium
All the exceptions that can happen during a request are catch in a general handler · A sentry context is created with additional...
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
Thanks for submitting this issue @LuisMlopez.
Our FastAPI integration is still in alpha so this feedback is very valuable! We will look into this in about two weeks time.
In that case we just ignore the request body, because we can not be sure to not break the users code when accessing it.