question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem accessing to the request body after configure Sentry in FastAPI

See original GitHub issue

Steps to Reproduce

  1. 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
  2. The previous step works before configuring the Sentry SDK
  3. Configure the Sentry as defined in https://docs.sentry.io/platforms/python/guides/fastapi/
  4. 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vladanpaunoviccommented, Aug 19, 2022

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.

0reactions
antonpirkercommented, Oct 3, 2022

In that case we just ignore the request body, because we can not be sure to not break the users code when accessing it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found