Problem accessing to the request body after configure Sentry in FastAPI · Issue #1573 · getsentry/sentry-python · GitHub
Skip to content

Problem accessing to the request body after configure Sentry in FastAPI #1573

Description

@LuisMlopez

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions