Repository navigation
Commit b79aabf
fix(okhttp): Capture network details only while Session Replay is recording (#6486)
* fix(okhttp): Don't block on response bodies of unknown length
Capturing a response body for session replay peeked it up front with
`Response.peekBody(MAX_NETWORK_BODY_SIZE + 1)`. OkHttp implements a peek as
`request(byteCount)`, which keeps reading until that many bytes are buffered or
the stream ends. A response with no Content-Length never satisfies either
condition, so for server-sent events, long-poll and any chunked endpoint that
stays open the interceptor never returned and the caller never received the
response at all.
Bodies with a known length still end on their own, so they keep the existing
up-front capture. Bodies of unknown length are now wrapped in a body that
copies what the application consumes into a capped buffer and reports it once
no more bytes can arrive: when the stream ends, when the application closes
the body, or when the cap is reached.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* changelog: reference the pull request
* fix(okhttp): Satisfy detekt for the streaming body capture
Split the capture wrapping into its own function to keep a single return, and
suppress TooManyFunctions on the interceptor as done elsewhere in this module.
* refactor(okhttp): Drop unnecessary locking from the capturing source
A response body has a single consumer, and neither Http1ExchangeCodec.cancel()
nor Http2ExchangeCodec.cancel() closes the body, so nothing reaches this class
from another thread. The AtomicBoolean already guarantees the capture is
reported exactly once.
* fix: Publish late response details safely
A streamed body is only known once it has been consumed, which can be after the
NetworkRequestData carrying it was handed to the scope, so the replay thread can
read it while it is still being written. Keeping the three response values
behind one volatile reference means a reader sees either nothing or the
complete set.
* test: Cover late-filled network request data
* fix(okhttp): Harden the capture of response bodies with no known length
* test(okhttp): Cover async, cancelled and HTTP/2 bodies of unknown length
* ref: Publish both sides of NetworkRequestData the same way
* fix(okhttp): Keep the bytes received before a stream breaks
* ref: Read the response details of a network breadcrumb as one snapshot
* ref(okhttp): Capture every response body through one path
* changelog
* test: Silence R8 for the okhttp types the new response body extends
* ref(okhttp): Rename NetworkBodyCapturingResponseBody to CapturedResponseBody
* ref(okhttp): Capture only the response bytes the application reads
* test(okhttp): Wait for the capture, not for the source handing bytes over
* ref: Keep the status code inside the response details
* ref(okhttp): Restore the original response flow and rethrow fatal capture errors
* ref(okhttp): Drop comments that restate the code
* ref: Drop the constructor comment on ReplayNetworkRequestOrResponse
* Address PR comments
* address PR comments
* test(replay): Pin the response body a late capture leaves out of the replay
* fix(okhttp): Capture network details only while Session Replay is recording
* changelog
---------
Co-authored-by: Carlo Marinangeli <carlo.marinangeli@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>1 parent 3d1f55e commit b79aabf
4 files changed
Lines changed: 39 additions & 6 deletions
File tree
- sentry-okhttp/src
- main/java/io/sentry/okhttp
- test/java/io/sentry/okhttp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
127 | 133 | | |
128 | 134 | | |
129 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
381 | 384 | | |
382 | 385 | | |
383 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
384 | 408 | | |
385 | 409 | | |
386 | 410 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
0 commit comments