fix(starlette): Stop eagerly consuming request bodies for streamed spans - #6282
Merged
alexander-alderman-webb merged 22 commits intoJun 9, 2026
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Only attach cached request bodies to streamed spans to avoid relying on an eagerly consumed request body. Use the
_jsonand_formattributes instead ofjson()andform()accessors to ensure that the request body is not consumed by the SDK.Note: by using
_jsonand_formdirectly we can no longer distinguish between raw data payloads and payloads that were not cached on theRequestobject. The attribute is therefore omitted if the request body is not cached, since the endpoint may not have accessed it.The integration can still cause application hangs if middleware or handlers deprive the
receive()callable instead of using Starlette accessors. Reliance on the overly ambitious request body access is only eliminated for streamed spans (and only persists for errors with the change).test_request_body_data_does_not_scrub_pii_span_streaming()sincetest_formdata_request_body()already asserts that fields in the request body are not scrubbed.test_request_body_data_annotated_value_top_level_span_streaming()because the attribute is no longer set if the request body is not JSON or FormData.Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)