Skip to content

feat(fastapi): Capture request body on segment span under streaming#6136

Open
ericapisani wants to merge 3 commits intoep/py-2362-2mwfrom
py-2322-port-event-processor-data-to-span-first-rme79
Open

feat(fastapi): Capture request body on segment span under streaming#6136
ericapisani wants to merge 3 commits intoep/py-2362-2mwfrom
py-2322-port-event-processor-data-to-span-first-rme79

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented Apr 24, 2026

Capture the request body as http.request.body.data on the streaming segment span for FastAPI requests, matching the behavior already in place for Starlette.

FastAPI runs its own request-body extraction path, so it was bypassing the data-capture logic that lives in the Starlette integration. This extracts that logic into a shared helper in the Starlette integration and invokes it from FastAPI's request handler once the body has been read.

Stacked on top of #6123.

Refs PY-2322
Fixes #6020

FastAPI runs its own request-body extraction and was missing the same logic
as that which exists in the Starlette integration. Extract the logic that writes
`http.request.body.data` on the streaming segment into a shared helper in
the Starlette integration, and call it from FastAPI's request handler
once the body has been read.
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 24, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Codecov Results 📊

142 passed | Total: 142 | Pass Rate: 100% | Execution Time: 21.25s

All tests are passing successfully.

❌ Patch coverage is 8.33%. Project has 13973 uncovered lines.

Files with missing lines (2)
File Patch % Lines
starlette.py 5.68% ⚠️ 365 Missing
fastapi.py 16.48% ⚠️ 76 Missing

Generated by Codecov Action

@ericapisani
Copy link
Copy Markdown
Member Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 793e2f7. Configure here.

FastAPI 0.79.1 pulls in Starlette 0.19.1, whose `TestClient` is built on
`requests` and does not accept the `content` kwarg. Match the skipif
already in place for the analogous Starlette test so CI on older
FastAPI versions passes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ericapisani ericapisani marked this pull request as ready for review April 24, 2026 17:09
@ericapisani ericapisani requested a review from a team as a code owner April 24, 2026 17:09
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.

1 participant