Skip to content

Conversation

alexander-alderman-webb
Copy link
Contributor

Description

Ensure endpoint handler runs before the FastAPI or Starlette integrations read the request body.

As the integrations previously called high-level Starlette Request methods early, the underlying ASGI receive stream was consumed before the user's handler or middleware ran. While the Request object caches the request body, any handler or middleware that relies on low-level stream access still failed.

Issues

Closes #4764
Closes #4827
Closes PY-1851
Closes PY-1831

Reminders

@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner September 22, 2025 06:56
Copy link

codecov bot commented Sep 22, 2025

Codecov Report

❌ Patch coverage is 95.23810% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.83%. Comparing base (7ae6866) to head (f66bcd6).
⚠️ Report is 31 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/starlette.py 90.62% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4832      +/-   ##
==========================================
+ Coverage   84.58%   84.83%   +0.25%     
==========================================
  Files         158      158              
  Lines       16521    16595      +74     
  Branches     2867     2877      +10     
==========================================
+ Hits        13974    14079     +105     
+ Misses       1703     1670      -33     
- Partials      844      846       +2     
Files with missing lines Coverage Δ
sentry_sdk/integrations/fastapi.py 89.41% <100.00%> (+0.38%) ⬆️
sentry_sdk/integrations/graphene.py 90.12% <100.00%> (+0.37%) ⬆️
sentry_sdk/integrations/starlette.py 85.37% <90.62%> (+0.35%) ⬆️

... and 39 files with indirect coverage changes

@alexander-alderman-webb alexander-alderman-webb marked this pull request as draft September 22, 2025 07:03
if should_send_default_pii():
request_info = event.setdefault("request", {})
request_info["api_target"] = "graphql"
request_info["data"] = {"query": source}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need to change because the value associated with event["request"]["data"] was previously subject to request body size limits.

@alexander-alderman-webb
Copy link
Contributor Author

Closing for the reasons in #4764 (comment)

@alexander-alderman-webb
Copy link
Contributor Author

Reopening because there may be the option of changing data fields on transactions in a minor version.

Users with our FastAPI integration are facing empty receive streams when using fastapi_mcp or a custom middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sentry FastAPI middleware hangs if user middleware raises an exception Requests to fastapi-mcp hangs if Sentry is enabled
1 participant