Skip to content

fix(replay): Fix network detail response body size being unknown for gzip-compressed responses#5592

Open
romtsn wants to merge 4 commits into
mainfrom
rz/fix/replay-network-body-size
Open

fix(replay): Fix network detail response body size being unknown for gzip-compressed responses#5592
romtsn wants to merge 4 commits into
mainfrom
rz/fix/replay-network-body-size

Conversation

@romtsn

@romtsn romtsn commented Jun 22, 2026

Copy link
Copy Markdown
Member

📜 Description

For gzip-compressed responses, OkHttp strips the Content-Length header during transparent decompression, so response.body.contentLength() returns -1. This caused NetworkRequestData.responseBodySize to always be unknown for replay network details on such responses.

This PR adds originalByteCount to NetworkBody, populated from the actual byte array length in NetworkBodyParser.fromBytes. NetworkDetailCaptureUtils.createRequestOrResponseInternal now uses this as a fallback when the passed bodySize is null or -1.

The fix piggybacks on the existing peekBody call — no additional network I/O. For responses larger than the peek limit (MAX_NETWORK_BODY_SIZE), the capped byte count is reported (lower bound) instead of unknown.

Example replay: https://sentry-sdks.sentry.io/explore/replays/95bf32448ef94fafb41b5164ccde5d19

Screenshot 2026-06-22 17 04 56

💡 Motivation and Context

Session replay network details show response body size. For gzip-compressed HTTP responses (common for JSON APIs), OkHttp's transparent decompression strips Content-Length, making the size always unknown (-1). The Sentry UI shows "It is possible the network transfer size is smaller due to compression", so reporting the decompressed size is the correct behavior.

Fixes SDK-1006

💚 How did you test it?

  • Added unit tests for NetworkBodyParser covering originalByteCount for both truncated and non-truncated bodies
  • Added unit tests for NetworkDetailCaptureUtils covering the bodySize fallback logic (unknown → uses byte count, explicit → preserved, body capture off → unchanged)
  • Verified existing tests pass

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

romtsn and others added 2 commits June 22, 2026 15:29
…Length is unknown

For gzip-compressed responses, OkHttp strips the Content-Length header
during transparent decompression, so response.body.contentLength() returns
-1. This caused NetworkRequestData.responseBodySize to be unknown for
replay network details.

Add originalByteCount to NetworkBody, set it from the actual byte array
in NetworkBodyParser.fromBytes, and use it as a fallback in
NetworkDetailCaptureUtils when the passed bodySize is null or -1. This
piggybacks on the existing peekBody call with no additional I/O.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sentry

sentry Bot commented Jun 22, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.44.1 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 314.33 ms 376.04 ms 61.71 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
18c0bc2 306.73 ms 349.77 ms 43.03 ms
0eaac1e 316.82 ms 357.34 ms 40.52 ms
d15471f 303.49 ms 439.08 ms 135.59 ms
fc5ccaf 276.52 ms 370.46 ms 93.93 ms
e2dce0b 308.96 ms 360.10 ms 51.14 ms
5b1a06b 352.27 ms 413.70 ms 61.43 ms
37ec571 366.04 ms 424.28 ms 58.23 ms
9fbb112 361.43 ms 427.57 ms 66.14 ms
bbc35bb 324.88 ms 425.73 ms 100.85 ms
ff8eea4 313.42 ms 337.08 ms 23.66 ms

App size

Revision Plain With Sentry Diff
18c0bc2 1.58 MiB 2.13 MiB 557.33 KiB
0eaac1e 1.58 MiB 2.19 MiB 619.17 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
e2dce0b 0 B 0 B 0 B
5b1a06b 0 B 0 B 0 B
37ec571 0 B 0 B 0 B
9fbb112 1.58 MiB 2.11 MiB 539.18 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB
ff8eea4 1.58 MiB 2.28 MiB 718.64 KiB

Previous results on branch: rz/fix/replay-network-body-size

Startup times

Revision Plain With Sentry Diff
614bb16 313.93 ms 353.38 ms 39.44 ms

App size

Revision Plain With Sentry Diff
614bb16 0 B 0 B 0 B

@linear-code

linear-code Bot commented Jun 22, 2026

Copy link
Copy Markdown

SDK-1006

@romtsn romtsn changed the title fix(replay): Derive response body size from peeked bytes when contentLength is unknown fix(replay): Fix network detail response body size being unknown for gzip-compressed responses Jun 22, 2026
@romtsn romtsn marked this pull request as ready for review June 22, 2026 15:06
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