feat(actix): capture HTTP request body#731
Merged
lcian merged 18 commits intogetsentry:masterfrom Feb 14, 2025
Merged
Conversation
Add MaxRequestBodySize enum to control request body capture with options: - None: Don't capture request body (default) - Small: Capture up to 1000 bytes - Medium: Capture up to 10000 bytes - Always: Capture entire body Add max_request_body_size field to ClientOptions struct with default value of None
Add support for capturing request bodies in the Sentry middleware for Actix-Web. This includes: - Configurable request body size limits (Small/Medium/Always) - Support for JSON and form-urlencoded content types - Body capture and restoration logic to maintain request integrity - Additional span data enrichment Updates dependencies: - Add serde_json, actix-http, futures dependencies
Swatinem
reviewed
Feb 4, 2025
Contributor
|
Another question would be: Is the intention to capture up to the configured limit, or to discard any payloads that exceed the limit. |
lcian
reviewed
Feb 4, 2025
Member
The goal here is to discard payloads that exceed the limit. In some SDKs (e.g. Python) there is some more complex logic to handle payloads that exceed the max but in others (e.g. PHP) it's simply discarded. |
Implements a method to validate request body sizes against predefined limits: - None: Don't capture request bodies (default) - Small: Capture up to 1000 bytes - Medium: Capture up to 10000 bytes - Always: Capture entire body
- Add chunked transfer encoding check to prevent capturing chunked requests - Add strict content-type validation for JSON and form-urlencoded - Implement content length validation against size limits
Add new `Explicit(usize)` variant to `MaxRequestBodySize` enum, allowing users to specify custom maximum request body size limits for event capture.
Swatinem
reviewed
Feb 6, 2025
loewenheim
reviewed
Feb 6, 2025
It's already handle by the is_within_size_limit.
lcian
approved these changes
Feb 10, 2025
Member
|
Setting the option to |
Member
|
@pacifistes thanks for the contribution! 😄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Summary
This PR adds the ability to capture HTTP request bodies in the Sentry Actix middleware, allowing for better debugging and error tracking capabilities. The feature is configurable through the
max_request_body_sizeoption inClientOptions.Changes
MaxRequestBodySizeenum to control request body capture behavior:None: Don't capture request bodies (default)Small: Capture up to 1000 bytesMedium: Capture up to 10000 bytesAlways: Capture entire bodyJSONandform-urlencodedcontent typesImplementation Details
application/jsonandapplication/x-www-form-urlencodedmax_request_body_sizeoption