Skip to content

Conversation

@antonis
Copy link
Contributor

@antonis antonis commented Oct 7, 2025

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Leaves captureReplay logic to the native implementation

💡 Motivation and Context

Fixes #5074

When replaysSessionSampleRate: 0.0, and with the steps below, I always got no recording attached to the event though I should have given that replaysOnErrorSampleRate: 1.0. I wasn't able to associate this behavior with the reactNavigationIntegration as the above issue states but the fix seems to make the the SR recording more reliable.

💚 How did you test it?

  1. Set replaysSessionSampleRate: 0.0 in the sample app. Leave replaysOnErrorSampleRate: 1.0
  2. Tap the Uncaught Thrown Error
  3. Notice that a replay is attached to the crash

📝 Checklist

  • I added tests to verify 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.
  • All tests passing
  • No breaking changes

🔮 Next steps

@antonis antonis requested a review from romtsn October 7, 2025 11:17
@antonis
Copy link
Contributor Author

antonis commented Oct 7, 2025

@romtsn I took the liberty of adding you as a reviewer on this one since you might have more context on how things work on the native side or a suggestion for a better approach 🙏

@antonis antonis marked this pull request as ready for review October 7, 2025 11:19
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 399.00 ms 424.56 ms 25.56 ms
Size 17.75 MiB 19.70 MiB 1.95 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
c7f264b 434.98 ms 452.96 ms 17.98 ms
bfe454a+dirty 573.44 ms 579.46 ms 6.02 ms
534ba8c 484.00 ms 499.93 ms 15.93 ms
0b64753+dirty 448.67 ms 474.61 ms 25.94 ms
64cd15c 439.02 ms 427.63 ms -11.39 ms
459a438+dirty 417.09 ms 406.52 ms -10.57 ms
d751a5d+dirty 434.24 ms 486.08 ms 51.84 ms
955f2eb+dirty 422.74 ms 410.19 ms -12.55 ms
8d89cc9+dirty 537.83 ms 536.02 ms -1.81 ms
a0b15d6 423.06 ms 437.77 ms 14.71 ms

App size

Revision Plain With Sentry Diff
c7f264b 17.75 MiB 19.68 MiB 1.94 MiB
bfe454a+dirty 17.75 MiB 19.69 MiB 1.94 MiB
534ba8c 17.75 MiB 20.15 MiB 2.41 MiB
0b64753+dirty 17.75 MiB 19.70 MiB 1.95 MiB
64cd15c 17.75 MiB 20.15 MiB 2.41 MiB
459a438+dirty 17.75 MiB 19.70 MiB 1.95 MiB
d751a5d+dirty 17.75 MiB 19.68 MiB 1.94 MiB
955f2eb+dirty 17.75 MiB 19.70 MiB 1.95 MiB
8d89cc9+dirty 17.75 MiB 19.68 MiB 1.94 MiB
a0b15d6 17.75 MiB 20.15 MiB 2.41 MiB

Previous results on branch: antonis/crash-sr

Startup times

Revision Plain With Sentry Diff
0aa0974+dirty 451.98 ms 482.13 ms 30.15 ms

App size

Revision Plain With Sentry Diff
0aa0974+dirty 17.75 MiB 19.70 MiB 1.95 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 364.96 ms 395.88 ms 30.92 ms
Size 7.15 MiB 8.43 MiB 1.27 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
c1573b3+dirty 355.65 ms 448.82 ms 93.17 ms
818a608+dirty 350.29 ms 397.38 ms 47.09 ms
d916aa3+dirty 411.72 ms 451.76 ms 40.03 ms
a0b15d6+dirty 414.33 ms 448.85 ms 34.52 ms
bfe454a+dirty 372.42 ms 424.52 ms 52.10 ms
af9331b+dirty 374.42 ms 425.68 ms 51.26 ms
0b64753+dirty 358.55 ms 429.16 ms 70.61 ms
c9e95bd+dirty 339.32 ms 401.24 ms 61.92 ms
459a438+dirty 359.50 ms 390.53 ms 31.03 ms
d751a5d+dirty 341.61 ms 403.06 ms 61.45 ms

App size

Revision Plain With Sentry Diff
c1573b3+dirty 7.15 MiB 8.42 MiB 1.27 MiB
818a608+dirty 7.15 MiB 8.41 MiB 1.26 MiB
d916aa3+dirty 7.15 MiB 8.42 MiB 1.27 MiB
a0b15d6+dirty 7.15 MiB 8.42 MiB 1.27 MiB
bfe454a+dirty 7.15 MiB 8.42 MiB 1.26 MiB
af9331b+dirty 7.15 MiB 8.41 MiB 1.26 MiB
0b64753+dirty 7.15 MiB 8.42 MiB 1.27 MiB
c9e95bd+dirty 7.15 MiB 8.41 MiB 1.26 MiB
459a438+dirty 7.15 MiB 8.42 MiB 1.27 MiB
d751a5d+dirty 7.15 MiB 8.41 MiB 1.26 MiB

Previous results on branch: antonis/crash-sr

Startup times

Revision Plain With Sentry Diff
0aa0974+dirty 382.29 ms 423.90 ms 41.60 ms

App size

Revision Plain With Sentry Diff
0aa0974+dirty 7.15 MiB 8.43 MiB 1.27 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1222.40 ms 1231.63 ms 9.24 ms
Size 3.19 MiB 4.55 MiB 1.36 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
7be1f99+dirty 1222.43 ms 1217.15 ms -5.28 ms
eb07ba3+dirty 1214.49 ms 1221.59 ms 7.10 ms
5c16cdc+dirty 1235.67 ms 1241.18 ms 5.51 ms
69602ce+dirty 1230.59 ms 1230.84 ms 0.24 ms
8a4ce6f+dirty 1232.80 ms 1223.80 ms -9.00 ms
95aaf8a+dirty 1206.83 ms 1213.65 ms 6.81 ms
98f632c+dirty 1221.38 ms 1229.26 ms 7.88 ms
3e0a5f9+dirty 1233.65 ms 1239.10 ms 5.45 ms
ba75c7c+dirty 1236.14 ms 1240.69 ms 4.55 ms
276d348+dirty 1222.10 ms 1229.02 ms 6.92 ms

App size

Revision Plain With Sentry Diff
7be1f99+dirty 3.19 MiB 4.38 MiB 1.19 MiB
eb07ba3+dirty 3.19 MiB 4.38 MiB 1.19 MiB
5c16cdc+dirty 3.19 MiB 4.53 MiB 1.34 MiB
69602ce+dirty 3.19 MiB 4.48 MiB 1.29 MiB
8a4ce6f+dirty 3.19 MiB 4.53 MiB 1.34 MiB
95aaf8a+dirty 3.19 MiB 4.44 MiB 1.25 MiB
98f632c+dirty 3.19 MiB 4.38 MiB 1.19 MiB
3e0a5f9+dirty 3.19 MiB 4.38 MiB 1.19 MiB
ba75c7c+dirty 3.19 MiB 4.38 MiB 1.19 MiB
276d348+dirty 3.19 MiB 4.54 MiB 1.36 MiB

Previous results on branch: antonis/crash-sr

Startup times

Revision Plain With Sentry Diff
0aa0974+dirty 1224.33 ms 1246.14 ms 21.81 ms

App size

Revision Plain With Sentry Diff
0aa0974+dirty 3.19 MiB 4.55 MiB 1.36 MiB

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1213.83 ms 1230.12 ms 16.29 ms
Size 2.63 MiB 3.98 MiB 1.35 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
7be1f99+dirty 1226.69 ms 1217.76 ms -8.93 ms
eb07ba3+dirty 1222.46 ms 1220.37 ms -2.08 ms
5c16cdc+dirty 1209.32 ms 1210.67 ms 1.35 ms
69602ce+dirty 1235.65 ms 1230.82 ms -4.83 ms
8a4ce6f+dirty 1221.31 ms 1219.84 ms -1.47 ms
95aaf8a+dirty 1234.78 ms 1241.94 ms 7.16 ms
98f632c+dirty 1236.40 ms 1241.62 ms 5.22 ms
3e0a5f9+dirty 1226.94 ms 1230.02 ms 3.08 ms
ba75c7c+dirty 1235.86 ms 1226.45 ms -9.41 ms
276d348+dirty 1224.22 ms 1227.38 ms 3.16 ms

App size

Revision Plain With Sentry Diff
7be1f99+dirty 2.63 MiB 3.81 MiB 1.18 MiB
eb07ba3+dirty 2.63 MiB 3.81 MiB 1.18 MiB
5c16cdc+dirty 2.63 MiB 3.96 MiB 1.33 MiB
69602ce+dirty 2.63 MiB 3.91 MiB 1.28 MiB
8a4ce6f+dirty 2.63 MiB 3.96 MiB 1.33 MiB
95aaf8a+dirty 2.63 MiB 3.87 MiB 1.24 MiB
98f632c+dirty 2.63 MiB 3.81 MiB 1.18 MiB
3e0a5f9+dirty 2.63 MiB 3.81 MiB 1.18 MiB
ba75c7c+dirty 2.63 MiB 3.81 MiB 1.18 MiB
276d348+dirty 2.63 MiB 3.98 MiB 1.34 MiB

Previous results on branch: antonis/crash-sr

Startup times

Revision Plain With Sentry Diff
0aa0974+dirty 1213.43 ms 1233.92 ms 20.48 ms

App size

Revision Plain With Sentry Diff
0aa0974+dirty 2.63 MiB 3.98 MiB 1.35 MiB

Copy link
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

LGTM!


const recordingReplayId = NATIVE.getCurrentReplayId();
if (recordingReplayId) {
if (!hardCrash && recordingReplayId) {
Copy link
Member

Choose a reason for hiding this comment

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

nice find! I'm actually not even sure if we need this if altogether.. When I look at the native implementations, it seems that they take care of not doing anything if the replay is running in session mode (=replay_id is on the scope).

iOS - https://github.com/getsentry/sentry-cocoa/blob/80538ca6089b2bb1c0c23efc78b62043454ee013/Sources/Swift/Integrations/SessionReplay/SentrySessionReplay.swift#L148-L152

Android - https://github.com/getsentry/sentry-java/blob/bdbe1f4058e77d9a8b9d11482a8aaec9b56ac0c2/sentry-android-replay/src/main/java/io/sentry/android/replay/capture/SessionCaptureStrategy.kt#L64-L72

Perhaps we should just rely on the native SDKs handling that here?

Copy link
Member

@romtsn romtsn Oct 7, 2025

Choose a reason for hiding this comment

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

the only important thing we have to make sure is that isHardCrash actually returns true when the program is about to terminate - this is needed on Android so we don't try to send anything and potentially lose segments due to the termination

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback @romtsn 🙇

Perhaps we should just rely on the native SDKs handling that here?

Good point 👍 I've removed the unneeded RN logic with c467718. Only kept the if statements to keep the logging consistent with the previous versions. As expected I didn't notice any change in behavior with this change.

the only important thing we have to make sure is that isHardCrash actually returns true when the program is about to terminate

The function uses a bit of a heuristic approach but it worked as expected in my tests and it seems to have served us well till now.

@antonis antonis changed the title fix(session-replay): Always try to record replay for hard crashes fix(session-replay): Leave captureReplay logic to the native implementation Oct 7, 2025
Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

nice!

@antonis antonis merged commit 3099014 into main Oct 8, 2025
142 of 150 checks passed
@antonis antonis deleted the antonis/crash-sr branch October 8, 2025 08:59
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.

Unable to get replay session when integrating both reactNavigationIntegration() & mobileReplayIntegration()

4 participants