Skip to content

fix(replay): Link errors to manual replays - #4078

Merged
buenaflor merged 15 commits into
mainfrom
fix/manual-replay-error-linking
Oct 15, 2026
Merged

buenaflor merged 15 commits into
mainfrom
fix/manual-replay-error-linking

Conversation

@buenaflor

@buenaflor buenaflor commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Error envelopes now use the scope's current replay ID, and omit empty IDs.
  • On Android, replay.flush() now waits until the buffered replay is promoted and the scope has its ID, so an error captured right after await flush() is linked. Each flush passes its own ReplayFlushListener to native.
  • flushReplay was already FutureOr<void> on the native binding, and iOS already awaited native. Android's implementation no longer completes immediately.

binding.dart and proguard-rules.pro are regenerated.

Fixes #4070

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

🟒 Patch (bug fixes)

πŸ“‹ Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Features

  • Session Replays on iOS now include trace IDs, so they can be found by searching for a trace ID in Sentry by antonis in #4083

Fixes

Android

  • Deobfuscate the Java frames of Dart-captured PlatformException events on Android by attaching the ProGuard debug image, and keep existing debug images when loading native ones. by xelarich in #4081
  • πŸ€– Generated with Claude Code by xelarich in #4081

Other

  • (app-start) Keep builds and deduplicate TTFD by buenaflor in #4079
  • (replay) Link errors to manual replays by buenaflor in #4078

Dependencies

Deps

  • chore(deps): update Native SDK to v0.17.3 by github-actions in #4082
  • chore(deps): update Native SDK to v0.17.2 by github-actions in #4031
  • chore(deps): update Cocoa SDK to v9.30.1 by github-actions in #4075
  • chore(deps): Update Android SDK to v8.60.0 by github-actions in #4077

Internal Changes

  • Remove Collect App Metrics jobs by buenaflor in #4091

πŸ€– This preview updates automatically when you update the PR.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 88.77%. Comparing base (86cc3b5) to head (5822983).
⚠️ Report is 3 commits behind head on main.
βœ… All tests successful. No failed tests found.

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           
Flag Coverage Ξ”
sentry 88.74% <100.00%> (+<0.01%) ⬆️
sentry_dio 97.95% <ΓΈ> (ΓΈ)
sentry_drift 93.63% <ΓΈ> (ΓΈ)
sentry_file 64.41% <ΓΈ> (ΓΈ)
sentry_firebase_remote_config 100.00% <ΓΈ> (ΓΈ)
sentry_flutter 92.62% <ΓΈ> (ΓΈ)
sentry_grpc 99.11% <ΓΈ> (ΓΈ)
sentry_hive 76.37% <ΓΈ> (ΓΈ)
sentry_isar 73.88% <ΓΈ> (ΓΈ)
sentry_link 22.04% <ΓΈ> (ΓΈ)
sentry_logging 97.01% <ΓΈ> (ΓΈ)
sentry_sqflite 88.88% <ΓΈ> (ΓΈ)
sentry_supabase 97.48% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

iOS Performance metrics πŸš€

Β  Plain With Sentry Diff
Startup time 1243.35 ms 1244.87 ms 1.52 ms
Size 5.91 MiB 6.35 MiB 450.21 KiB

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Android Performance metrics πŸš€

Β  Plain With Sentry Diff
Startup time 360.31 ms 354.92 ms -5.39 ms
Size 14.77 MiB 16.08 MiB 1.31 MiB

@buenaflor
buenaflor marked this pull request as ready for review October 12, 2026 15:48
Copilot AI balanced review requested due to automatic review settings October 12, 2026 15:48
@buenaflor
buenaflor requested a review from denrase as a code owner October 12, 2026 15:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟑 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.

@github-actions

Copy link
Copy Markdown
Contributor

🚨 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:

  • packages/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt

@denrase denrase left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

buenaflor and others added 10 commits October 15, 2026 09:44
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>
@buenaflor
buenaflor force-pushed the fix/manual-replay-error-linking branch from 26450bc to 479f03e Compare October 15, 2026 08:14
@buenaflor
buenaflor requested a review from denrase October 15, 2026 08:16
@buenaflor

Copy link
Copy Markdown
Contributor Author

@denrase

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.

buenaflor and others added 3 commits October 15, 2026 11:20
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>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

buenaflor and others added 2 commits October 15, 2026 13:48
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>
@buenaflor
buenaflor enabled auto-merge (squash) October 15, 2026 12:20
@buenaflor
buenaflor merged commit 746f8ec into main Oct 15, 2026
139 checks passed
@buenaflor
buenaflor deleted the fix/manual-replay-error-linking branch October 15, 2026 12:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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;
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in CursorΒ Fix in Web

Reviewed by Cursor Bugbot for commit 5822983. Configure here.

// ignore: invalid_use_of_internal_member
s.replayId = _replayId;
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in CursorΒ Fix in Web

Reviewed by Cursor Bugbot for commit 5822983. Configure here.

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.

Errors captured during a manually started replay (SentryFlutter.replay.start()) are not reliably linked to the replay

3 participants