sentry-java
sentry-java copied to clipboard
fix: improve network body parsing and truncation handling
:scroll: Description
This PR refactors the NetworkBody class and improves how network request/response bodies are parsed and handled, particularly for large or truncated content.
Key changes:
- Simplified
NetworkBodyfrom an interface with multiple implementations to a single class with abodyfield and optionalwarningslist - Added
NetworkBodyWarningenum to communicate parsing issues (JSON_TRUNCATED, TEXT_TRUNCATED, INVALID_JSON, BODY_PARSE_ERROR) - Improved truncation handling in
NetworkBodyParserto properly detect and mark truncated content - Switched from
JsonObjectReaderto vendorJsonReaderfor more robust JSON parsing - Updated
SentryOkHttpInterceptorto peek at the correct amount of bytes to detect truncation
:bulb: Motivation and Context
Previously, the network body parsing had issues with:
- Inconsistent handling of truncated content
- No way to communicate parse warnings to consumers
- Less robust JSON parsing
This change provides a cleaner API and better error/warning reporting.
:green_heart: How did you test it?
- Existing tests should pass
- Manual testing with large response bodies
:pencil: Checklist
- [ ] I added GH Issue ID & Linear ID
- [ ] I added tests to verify the changes.
- [x] No new PII added or SDK only sends newly added PII if
sendDefaultPIIis enabled. - [ ] I updated the docs if needed.
- [ ] I updated the wizard if needed.
- [ ] Review from the native team if needed.
- [x] No breaking change or entry added to the changelog.
- [x] No breaking change for hybrid SDKs or communicated to hybrid SDKs.
:crystal_ball: Next steps
🤖 Generated with Claude Code
Performance metrics :rocket:
| Plain | With Sentry | Diff | |
|---|---|---|---|
| Startup time | 292.30 ms | 347.96 ms | 55.66 ms |
| Size | 1.58 MiB | 2.13 MiB | 559.07 KiB |
Baseline results on branch: main
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| dba088c465439af6142917dc884a1919ff042722 | 321.78 ms | 364.59 ms | 42.82 ms |
| fcec2f233b744694bffee41e58e5a706e032ef51 | 328.91 ms | 387.75 ms | 58.84 ms |
| 3998a959439d3be2d0fb349aa7155194c4831c28 | 415.94 ms | 478.54 ms | 62.60 ms |
| f634d01652b3f4ddf21398daf541b63620228184 | 359.58 ms | 433.88 ms | 74.30 ms |
| fc5ccaf5844ae029d93c566b6fd1b4f5c2e4da83 | 322.49 ms | 405.25 ms | 82.76 ms |
| 9fbb1127f2d985a834f669b39d88441f21bdbf8c | 404.51 ms | 475.65 ms | 71.14 ms |
| ee747ae50ffec79f1ea20d100ea98e8520ab4ed4 | 405.43 ms | 485.70 ms | 80.28 ms |
| 951caf72e161c0854233d20019ce53b1f0ca9f15 | 323.66 ms | 392.82 ms | 69.16 ms |
| ee747ae50ffec79f1ea20d100ea98e8520ab4ed4 | 358.21 ms | 389.41 ms | 31.20 ms |
| f634d01652b3f4ddf21398daf541b63620228184 | 375.06 ms | 420.04 ms | 44.98 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| dba088c465439af6142917dc884a1919ff042722 | 1.58 MiB | 2.13 MiB | 558.99 KiB |
| fcec2f233b744694bffee41e58e5a706e032ef51 | 1.58 MiB | 2.12 MiB | 551.50 KiB |
| 3998a959439d3be2d0fb349aa7155194c4831c28 | 1.58 MiB | 2.10 MiB | 532.96 KiB |
| f634d01652b3f4ddf21398daf541b63620228184 | 1.58 MiB | 2.10 MiB | 533.40 KiB |
| fc5ccaf5844ae029d93c566b6fd1b4f5c2e4da83 | 1.58 MiB | 2.13 MiB | 557.54 KiB |
| 9fbb1127f2d985a834f669b39d88441f21bdbf8c | 1.58 MiB | 2.11 MiB | 539.18 KiB |
| ee747ae50ffec79f1ea20d100ea98e8520ab4ed4 | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| 951caf72e161c0854233d20019ce53b1f0ca9f15 | 1.58 MiB | 2.13 MiB | 558.77 KiB |
| ee747ae50ffec79f1ea20d100ea98e8520ab4ed4 | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| f634d01652b3f4ddf21398daf541b63620228184 | 1.58 MiB | 2.10 MiB | 533.40 KiB |
Previous results on branch: fix/network-request-response-body-parsing
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8287b45a37e7056aa744cb79816f8da330ba442d | 308.53 ms | 359.32 ms | 50.79 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8287b45a37e7056aa744cb79816f8da330ba442d | 1.58 MiB | 2.13 MiB | 559.07 KiB |