Repository navigation
fix(replay): Link errors to manual replays - #4078
Conversation
Semver Impact of This PRπ’ Patch (bug fixes) π Changelog PreviewThis is how your changes will appear in the changelog. Features
FixesAndroid
Other
DependenciesDeps
Internal Changes
π€ This preview updates automatically when you update the PR. |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4078 +/- ##
=======================================
Coverage 88.77% 88.77%
=======================================
Files 348 348
Lines 12589 12591 +2
=======================================
+ Hits 11176 11178 +2
Misses 1413 1413
Flags with carried forward coverage won't be shown. Click here to find out more. β View full report in Codecov by Harness. |
iOS Performance metrics π
|
Android Performance metrics π
|
There was a problem hiding this comment.
π‘ Changes recommended
Empty replay IDs can still be serialized when an active span supplies the trace context.
1 open finding
What changed in this PR
Updates replay metadata so error envelopes use the current scope replay ID rather than stale baggage.
Changes:
- Refreshes replay IDs in event trace contexts.
- Adds lifecycle and empty-ID unit tests.
- Adds mobile manual-replay integration coverage.
| File | Description |
|---|---|
packages/βdart/βlib/βsrc/βsentry_client.dart |
Refreshes replay metadata from scope. |
packages/βdart/βtest/βsentry_client_test.dart |
Tests replay lifecycle metadata. |
packages/βflutter/βexample/βintegration_test/βreplay_test.dart |
Tests manual replay linking on mobile. |
π§ Review effort: Balanced
π‘ Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
π¨ Detected changes in high risk code π¨High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:
|
denrase
left a comment
There was a problem hiding this comment.
Does this also work on iOS when buffering has been running for a while?
// Both replay sample rates are set to 0.
await SentryFlutter.replay.startBuffering();
await Future.delayed(const Duration(seconds: 3));
await SentryFlutter.replay.flush();
await Sentry.captureException(Exception('boom'));Flushing keeps the same replay ID, but the iOS screenshot callback only updates the scope when that ID changes. Wouldnβt scope.replayId stay null here, leaving the error unlinked? The new test flushes immediately, so it might miss this case.
Use the current scope replay ID when building event trace context from cached propagation baggage. Cover replay start, stop, and restart, including the manual replay error path on mobile. Fixes #4070 Co-Authored-By: Codex <noreply@openai.com>
Normalize empty scope replay IDs to null when refreshing event trace context from baggage. Cover fresh baggage and cached replay metadata so rejected sampling cannot attach an all-zero replay ID. Refs #4070 Co-Authored-By: Codex <noreply@openai.com>
Refs #4070 Co-Authored-By: Codex <noreply@openai.com>
Complete manual flush only after native buffer promotion updates the Dart replay scope, so errors captured immediately afterward retain the replay ID. Cover cached metadata, concurrent flushes, and shutdown. Refs #4070 Co-Authored-By: Codex <noreply@openai.com>
Use a generation-guarded JNI callback and per-request completion IDs to await replay scope synchronization. Settle pending flushes on shutdown and return when native Replay is unavailable. Refs #4070 Co-Authored-By: Codex <noreply@openai.com>
Pass a ReplayFlushListener to privateSentryFlushReplay instead of a request ID routed through the shared replay callbacks. Each flush owns its completer, so the pending-flush map, the closed flag, and the close-time settling are no longer needed. The listener is async, so a completion after a hot restart is dropped instead of calling into the old isolate. Refs #4070 Co-Authored-By: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Assign the scope's current replay ID once for both legacy spans and cached baggage instead of in two branches. Refs #4070 Co-Authored-By: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the mode and baggage matrices with focused cases: manual session and buffer linking, a busy Android main looper, concurrent flushes, unavailable native replay, and closing during a flush. Refs #4070 Co-Authored-By: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Refs #4070 Co-Authored-By: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Keep Dart scope synchronized with Cocoa promotion and ignore stale flush replies after stop. Cover delayed buffering, overlapping stop, restart, and immediate error linkage. Co-Authored-By: Codex <noreply@openai.com>
26450bc to
479f03e
Compare
|
updated. I added your 3 second buffering case with both sample rates set to zero, capturing the exception immediately after await flush(). The regression test passes on the iOS simulator. |
Reject missing, non-numeric, or negative delay values before acknowledging the method call. Verify the example stays responsive after invalid arguments. Co-Authored-By: Codex <noreply@openai.com>
Flutter 3.50 beta requires AGP 9.1.1, beyond the example toolchain. Skip Android beta builds and native integration tests until the example is upgraded. Keep Android stable and other beta targets. Co-Authored-By: Codex <noreply@openai.com>
Clear replay IDs on stop to reject queued flush promotion updates. Contain posted scope lookup failures while completing the listener. Cover stop/flush overlap and exception recovery on Android. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
β Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5822983. Configure here.
| // ignore: invalid_use_of_internal_member | ||
| s.replayId = _replayId; | ||
| }); | ||
| } |
There was a problem hiding this comment.
Flush can restore ID after stop
Medium Severity
flushReplay only snapshots _replayGeneration at start, while stopReplay increments it before awaiting native stop. A flush that begins during that window shares the new generation, so after stop clears _replayId and scope.replayId, the flush still applies the native response and can relink a stopped replay.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 5822983. Configure here.
| // ignore: invalid_use_of_internal_member | ||
| s.replayId = _replayId; | ||
| }); | ||
| } |
There was a problem hiding this comment.
Screenshot can clear ID after flush
Medium Severity
flushReplay now sets scope.replayId without waiting for screenshots, while captureReplayScreenshot still forces scope.replayId to null when replayIsBuffering is true. An in-flight buffering screenshot processed after await flush() can clear the ID that flush just wrote, so an error captured immediately afterward is not linked.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 5822983. Configure here.



Errors weren't reliably linked to manually started replays: the replay ID came from baggage cached on the first event, so it was missing after
replay.start()and stale after a stop or restart.replay.flush()now waits until the buffered replay is promoted and the scope has its ID, so an error captured right afterawait flush()is linked. Each flush passes its ownReplayFlushListenerto native.flushReplaywas alreadyFutureOr<void>on the native binding, and iOS already awaited native. Android's implementation no longer completes immediately.binding.dartandproguard-rules.proare regenerated.Fixes #4070