sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Fix(V6): Implement fallback system to screens that aren't reporting on the native layer the time to display. #4042

Open lucas-zimerman opened this issue 1 year ago • 5 comments

This is a port of https://github.com/getsentry/sentry-react-native/pull/4042 to V6

Tested on Android/iOS: https://sentry-sdks.sentry.io/performance/trace/b0125a1564324d17b42156b5edbd4555/?dataset=transactions&field=title&field=project&field=user.display&field=timestamp&field=replayId&field=transaction.duration&fov=0%2C1910.000244140625&id=21705&name=&node=txn-ccda2e67a35c486d801315ad5c5020d9&node=txn-48c53c8b7b4a4335a12082cd81adba27&project=5428561&query=&queryDataset=transaction-like&sort=-timestamp&source=discover&statsPeriod=24h&timestamp=1729179000&topEvents=5&yAxis=count%28%29

https://sentry-sdks.sentry.io/performance/trace/514b002f17874570b2f016f0f78b9953/?dataset=transactions&field=title&field=project&field=user.display&field=timestamp&field=replayId&fov=0%2C75.13809204101562&id=21705&name=&node=span-87836929b3543124&node=txn-400cebc647684a688c5355197859dd40&project=5428561&query=&queryDataset=transaction-like&sort=-timestamp&source=discover&statsPeriod=1h&timestamp=1729198686&topEvents=5&yAxis=count%28%29

:loudspeaker: Type of change

  • [x] Bugfix
  • [ ] New feature
  • [ ] Enhancement
  • [ ] Refactoring

:scroll: Description

Context: the current native implementation doesn't always emit the required event in order to track the required time to display to be set on the time to display span.

To fix that, I introduced an additional fallback emitter, in short, it reuses the same flow by emitting the original event when the fallback emitter received the notification that the page was rendered and the original emitter didn't emit any event on the following 3 seconds.

With those changes, we have the following benefits:

  • Support for React Native web by also having the JavaScript fallback of requestAnimationFrame.
  • Greatly reduces the wrong time to display end timestamp by having a fallback when the original implementation doesn't return any event.
  • Fallback to the JavaScript implementation in case both Native emitters fail.

:bulb: Motivation and Context

Close #3934, https://github.com/getsentry/sentry-react-native/issues/3809

:green_heart: How did you test it?

The playground tab on our sample is a good case for testing, since it doesn't use navigation stack on it, the events on this condition are limited, not generating and required event by us in order to track the time to display.

I used it and other tabs to compare the difference between the original implementation and also requestAnimationFrame, and the time difference between each other was quite low:

1St Tab JS: requestAnimationFrame, "newFrameTimestampInSeconds" is 1724293664.8300002 Original: InitAsync Event received {"newFrameTimestampInSeconds":1724293664.8179998}

2Nd Tab JS: requestAnimationFrame, "newFrameTimestampInSeconds" is 1724293761.688 Original: InitAsync Event received {"newFrameTimestampInSeconds":1724293761.689}

3Rd Tab JS: requestAnimationFrame, "newFrameTimestampInSeconds" is 1724293824.887 Original: Android didn't emit an event for this page so it wasn't measured

Before this change on the playground screen: https://sentry-sdks.sentry.io/performance/trace/10bd4bf28052404592f408f3cf58175a/?dataset=transactions&field=title&field=event.type&field=project&field=user.display&field=timestamp&field=replayId&fov=0%2C15046.88916015625&id=21705&name=&node=trace-root&project=5428561&query=&queryDataset=transaction-like&sort=-timestamp&source=discover&statsPeriod=1h&timestamp=1724358725&topEvents=5&yAxis=count%28%29

After this change on the playground screen: https://sentry-sdks.sentry.io/performance/trace/8cb478b4370e444fa4a7b9be778d51ab/?dataset=transactions&field=title&field=event.type&field=project&field=user.display&field=timestamp&field=replayId&fov=0%2C235&id=21705&name=&node=txn-b5a8ba18aa254fe79743133baf9071b2&project=5428561&query=&queryDataset=transaction-like&sort=-timestamp&source=discover&statsPeriod=1h&timestamp=1724359145&topEvents=5&yAxis=count%28%29

:pencil: Checklist

  • [x] I reviewed submitted code
  • [x] I added tests to verify changes
  • [x] No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • [ ] All tests passing
  • [x] No breaking changes

:crystal_ball: Next steps

lucas-zimerman avatar Oct 17 '24 20:10 lucas-zimerman

iOS (legacy) Performance metrics :rocket:

  Plain With Sentry Diff
Startup time 1215.88 ms 1220.04 ms 4.16 ms
Size 2.36 MiB 3.08 MiB 736.68 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
42973249f25bb547cf943daec67008271e93c69c+dirty 1230.27 ms 1232.53 ms 2.27 ms
e73f4eddcecda26c0380795bce5ba97e1f11b91f+dirty 1243.27 ms 1244.52 ms 1.25 ms
3ffcddd6248046202afca78f6b9af8e3f591202c+dirty 1244.47 ms 1264.14 ms 19.67 ms
a989877aa578d652ec0683764d802bb6bb6cbd2e+dirty 1228.56 ms 1227.71 ms -0.85 ms
27ef4ee6faa6d5229b16fca7b728ca6b689ab916+dirty 1293.52 ms 1296.08 ms 2.56 ms
fe135918376819714679fec8bf2bb2e1f07ec64b+dirty 1208.25 ms 1219.53 ms 11.28 ms
e540498478edf6f59bd7e731809a3ea6409dcc1c+dirty 1220.61 ms 1212.93 ms -7.68 ms
5a22220fafc6352a2e07e20943dda325a4cf67f5+dirty 1209.49 ms 1220.94 ms 11.45 ms
e5c9b8b6d5ce209fa4b3a77aa9de65bd590fa727+dirty 1258.57 ms 1267.32 ms 8.75 ms
f06c879d164a5bd44945c6e000e25ce3f7c14172+dirty 1252.64 ms 1259.66 ms 7.02 ms

App size

Revision Plain With Sentry Diff
42973249f25bb547cf943daec67008271e93c69c+dirty 2.36 MiB 3.08 MiB 735.61 KiB
e73f4eddcecda26c0380795bce5ba97e1f11b91f+dirty 2.36 MiB 2.82 MiB 469.44 KiB
3ffcddd6248046202afca78f6b9af8e3f591202c+dirty 2.36 MiB 2.84 MiB 489.60 KiB
a989877aa578d652ec0683764d802bb6bb6cbd2e+dirty 2.36 MiB 3.10 MiB 752.40 KiB
27ef4ee6faa6d5229b16fca7b728ca6b689ab916+dirty 2.36 MiB 2.85 MiB 500.03 KiB
fe135918376819714679fec8bf2bb2e1f07ec64b+dirty 2.36 MiB 3.10 MiB 752.40 KiB
e540498478edf6f59bd7e731809a3ea6409dcc1c+dirty 2.36 MiB 3.14 MiB 793.34 KiB
5a22220fafc6352a2e07e20943dda325a4cf67f5+dirty 2.36 MiB 2.92 MiB 570.21 KiB
e5c9b8b6d5ce209fa4b3a77aa9de65bd590fa727+dirty 2.36 MiB 2.87 MiB 520.43 KiB
f06c879d164a5bd44945c6e000e25ce3f7c14172+dirty 2.36 MiB 2.88 MiB 530.42 KiB

Previous results on branch: fix/v6-fallback-main

Startup times

Revision Plain With Sentry Diff
f0651d78a10c9c770b3808769913f5cc31540998+dirty 1234.42 ms 1231.63 ms -2.79 ms
505e5727f37a28ccd55899c2cfb3c9eb621b4482+dirty 1226.98 ms 1231.87 ms 4.90 ms
c67f1b123040031140e51b05ade529512ddd0cb6+dirty 1224.20 ms 1236.57 ms 12.37 ms
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a+dirty 1225.41 ms 1231.35 ms 5.94 ms

App size

Revision Plain With Sentry Diff
f0651d78a10c9c770b3808769913f5cc31540998+dirty 2.36 MiB 3.08 MiB 736.71 KiB
505e5727f37a28ccd55899c2cfb3c9eb621b4482+dirty 2.36 MiB 3.10 MiB 753.25 KiB
c67f1b123040031140e51b05ade529512ddd0cb6+dirty 2.36 MiB 3.10 MiB 753.96 KiB
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a+dirty 2.36 MiB 3.10 MiB 753.98 KiB

github-actions[bot] avatar Oct 17 '24 20:10 github-actions[bot]

iOS (new) Performance metrics :rocket:

  Plain With Sentry Diff
Startup time 1239.18 ms 1249.51 ms 10.33 ms
Size 2.92 MiB 3.64 MiB 742.58 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
42973249f25bb547cf943daec67008271e93c69c+dirty 1240.86 ms 1232.04 ms -8.81 ms
e73f4eddcecda26c0380795bce5ba97e1f11b91f+dirty 1282.90 ms 1309.30 ms 26.40 ms
3ffcddd6248046202afca78f6b9af8e3f591202c+dirty 1272.22 ms 1273.98 ms 1.76 ms
a989877aa578d652ec0683764d802bb6bb6cbd2e+dirty 1222.90 ms 1219.89 ms -3.00 ms
27ef4ee6faa6d5229b16fca7b728ca6b689ab916+dirty 1236.41 ms 1244.90 ms 8.49 ms
fe135918376819714679fec8bf2bb2e1f07ec64b+dirty 1250.69 ms 1246.27 ms -4.43 ms
e540498478edf6f59bd7e731809a3ea6409dcc1c+dirty 1254.92 ms 1247.21 ms -7.71 ms
5a22220fafc6352a2e07e20943dda325a4cf67f5+dirty 1246.18 ms 1249.61 ms 3.43 ms
e5c9b8b6d5ce209fa4b3a77aa9de65bd590fa727+dirty 1276.90 ms 1280.92 ms 4.02 ms
f06c879d164a5bd44945c6e000e25ce3f7c14172+dirty 1285.14 ms 1285.86 ms 0.72 ms

App size

Revision Plain With Sentry Diff
42973249f25bb547cf943daec67008271e93c69c+dirty 2.92 MiB 3.64 MiB 741.22 KiB
e73f4eddcecda26c0380795bce5ba97e1f11b91f+dirty 2.92 MiB 3.38 MiB 475.71 KiB
3ffcddd6248046202afca78f6b9af8e3f591202c+dirty 2.92 MiB 3.40 MiB 494.39 KiB
a989877aa578d652ec0683764d802bb6bb6cbd2e+dirty 2.92 MiB 3.66 MiB 757.66 KiB
27ef4ee6faa6d5229b16fca7b728ca6b689ab916+dirty 2.92 MiB 3.41 MiB 503.72 KiB
fe135918376819714679fec8bf2bb2e1f07ec64b+dirty 2.92 MiB 3.66 MiB 757.71 KiB
e540498478edf6f59bd7e731809a3ea6409dcc1c+dirty 2.92 MiB 3.69 MiB 794.14 KiB
5a22220fafc6352a2e07e20943dda325a4cf67f5+dirty 2.92 MiB 3.48 MiB 575.81 KiB
e5c9b8b6d5ce209fa4b3a77aa9de65bd590fa727+dirty 2.92 MiB 3.43 MiB 524.50 KiB
f06c879d164a5bd44945c6e000e25ce3f7c14172+dirty 2.92 MiB 3.44 MiB 533.24 KiB

Previous results on branch: fix/v6-fallback-main

Startup times

Revision Plain With Sentry Diff
f0651d78a10c9c770b3808769913f5cc31540998+dirty 1217.56 ms 1222.71 ms 5.15 ms
505e5727f37a28ccd55899c2cfb3c9eb621b4482+dirty 1244.94 ms 1244.90 ms -0.04 ms
c67f1b123040031140e51b05ade529512ddd0cb6+dirty 1240.98 ms 1235.49 ms -5.49 ms
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a+dirty 1234.55 ms 1239.44 ms 4.89 ms

App size

Revision Plain With Sentry Diff
f0651d78a10c9c770b3808769913f5cc31540998+dirty 2.92 MiB 3.64 MiB 742.52 KiB
505e5727f37a28ccd55899c2cfb3c9eb621b4482+dirty 2.92 MiB 3.66 MiB 758.51 KiB
c67f1b123040031140e51b05ade529512ddd0cb6+dirty 2.92 MiB 3.66 MiB 759.19 KiB
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a+dirty 2.92 MiB 3.66 MiB 759.18 KiB

github-actions[bot] avatar Oct 17 '24 20:10 github-actions[bot]

Android (legacy) Performance metrics :rocket:

  Plain With Sentry Diff
Startup time 430.18 ms 411.72 ms -18.46 ms
Size 17.74 MiB 20.08 MiB 2.34 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
f06c879d164a5bd44945c6e000e25ce3f7c14172 408.41 ms 424.54 ms 16.13 ms
0ebca778ff7a525ecc959a1782619de87ce443b3 414.93 ms 444.49 ms 29.56 ms
e2b64fed057d4b01cf7ad79eb19eb3c8b8002a82 316.88 ms 330.23 ms 13.35 ms
148f9248007774c638943e03dc044cf71dec0c3d 492.65 ms 500.28 ms 7.63 ms
d7401ac44acf524fe4d9a6a525f2cc13c70ce9e5+dirty 375.20 ms 383.51 ms 8.31 ms
34aba0802bf802288f91fada55c0b133252fe67f 328.10 ms 342.84 ms 14.74 ms
62a750bd050f26dbf2553deb01e3f453f272de2c 395.96 ms 423.36 ms 27.41 ms
1c653243e2e4fd64d6c98a843b9aeccf235ba198 426.37 ms 460.36 ms 33.99 ms
86d6d2c81bc42209de70f7f3b97a1fbbde04025f+dirty 332.90 ms 352.45 ms 19.55 ms
e73d82f5e34d416eca0eb58c76599fb625345e48 475.82 ms 506.55 ms 30.73 ms

App size

Revision Plain With Sentry Diff
f06c879d164a5bd44945c6e000e25ce3f7c14172 17.73 MiB 19.85 MiB 2.12 MiB
0ebca778ff7a525ecc959a1782619de87ce443b3 17.73 MiB 19.95 MiB 2.21 MiB
e2b64fed057d4b01cf7ad79eb19eb3c8b8002a82 17.73 MiB 19.80 MiB 2.07 MiB
148f9248007774c638943e03dc044cf71dec0c3d 17.73 MiB 19.94 MiB 2.21 MiB
d7401ac44acf524fe4d9a6a525f2cc13c70ce9e5+dirty 17.73 MiB 19.75 MiB 2.02 MiB
34aba0802bf802288f91fada55c0b133252fe67f 17.73 MiB 19.80 MiB 2.07 MiB
62a750bd050f26dbf2553deb01e3f453f272de2c 17.73 MiB 19.93 MiB 2.20 MiB
1c653243e2e4fd64d6c98a843b9aeccf235ba198 17.73 MiB 19.95 MiB 2.21 MiB
86d6d2c81bc42209de70f7f3b97a1fbbde04025f+dirty 17.73 MiB 20.04 MiB 2.31 MiB
e73d82f5e34d416eca0eb58c76599fb625345e48 17.73 MiB 20.07 MiB 2.33 MiB

Previous results on branch: fix/v6-fallback-main

Startup times

Revision Plain With Sentry Diff
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a 476.64 ms 463.39 ms -13.25 ms
c67f1b123040031140e51b05ade529512ddd0cb6 463.83 ms 451.12 ms -12.70 ms
f0651d78a10c9c770b3808769913f5cc31540998 520.06 ms 512.24 ms -7.82 ms
505e5727f37a28ccd55899c2cfb3c9eb621b4482 442.88 ms 455.37 ms 12.49 ms

App size

Revision Plain With Sentry Diff
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a 17.74 MiB 20.08 MiB 2.34 MiB
c67f1b123040031140e51b05ade529512ddd0cb6 17.74 MiB 20.08 MiB 2.34 MiB
f0651d78a10c9c770b3808769913f5cc31540998 17.74 MiB 20.08 MiB 2.34 MiB
505e5727f37a28ccd55899c2cfb3c9eb621b4482 17.74 MiB 20.07 MiB 2.34 MiB

github-actions[bot] avatar Oct 17 '24 22:10 github-actions[bot]

Android (new) Performance metrics :rocket:

  Plain With Sentry Diff
Startup time 370.89 ms 420.86 ms 49.96 ms
Size 7.15 MiB 8.35 MiB 1.20 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
b1e87125f5dbad623a4e4293384e68e8f702cc19+dirty 322.55 ms 331.84 ms 9.29 ms
70e6261eb7fdf57e3aba1f72d12c3eb518bcad99+dirty 395.08 ms 408.12 ms 13.04 ms
2ec71da2fbe36565c59c20f960c72fc75737275c+dirty 375.64 ms 431.59 ms 55.95 ms
c2a4e9b9386a596d6e84a9d857c77418388c0e5f+dirty 392.94 ms 474.55 ms 81.61 ms
80b2ce3d0ebe86bf1196944a2036912f6670295c+dirty 271.29 ms 316.47 ms 45.18 ms
d7401ac44acf524fe4d9a6a525f2cc13c70ce9e5+dirty 373.98 ms 394.08 ms 20.10 ms
31fcca2b37834863733f6f21677efb4b7a490aa8+dirty 366.64 ms 395.78 ms 29.14 ms
42973249f25bb547cf943daec67008271e93c69c+dirty 385.33 ms 435.68 ms 50.35 ms
e2b64fed057d4b01cf7ad79eb19eb3c8b8002a82+dirty 258.82 ms 304.26 ms 45.44 ms
86d6d2c81bc42209de70f7f3b97a1fbbde04025f+dirty 267.21 ms 325.24 ms 58.04 ms

App size

Revision Plain With Sentry Diff
b1e87125f5dbad623a4e4293384e68e8f702cc19+dirty 7.15 MiB 8.04 MiB 912.27 KiB
70e6261eb7fdf57e3aba1f72d12c3eb518bcad99+dirty 7.15 MiB 8.21 MiB 1.07 MiB
2ec71da2fbe36565c59c20f960c72fc75737275c+dirty 7.15 MiB 8.38 MiB 1.23 MiB
c2a4e9b9386a596d6e84a9d857c77418388c0e5f+dirty 7.15 MiB 8.34 MiB 1.19 MiB
80b2ce3d0ebe86bf1196944a2036912f6670295c+dirty 7.15 MiB 8.04 MiB 911.02 KiB
d7401ac44acf524fe4d9a6a525f2cc13c70ce9e5+dirty 7.15 MiB 8.04 MiB 910.85 KiB
31fcca2b37834863733f6f21677efb4b7a490aa8+dirty 7.15 MiB 8.18 MiB 1.03 MiB
42973249f25bb547cf943daec67008271e93c69c+dirty 7.15 MiB 8.35 MiB 1.20 MiB
e2b64fed057d4b01cf7ad79eb19eb3c8b8002a82+dirty 7.15 MiB 8.07 MiB 947.16 KiB
86d6d2c81bc42209de70f7f3b97a1fbbde04025f+dirty 7.15 MiB 8.09 MiB 962.69 KiB

Previous results on branch: fix/v6-fallback-main

Startup times

Revision Plain With Sentry Diff
505e5727f37a28ccd55899c2cfb3c9eb621b4482+dirty 379.47 ms 394.30 ms 14.83 ms
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a+dirty 351.96 ms 396.51 ms 44.55 ms
c67f1b123040031140e51b05ade529512ddd0cb6+dirty 369.84 ms 399.76 ms 29.92 ms
f0651d78a10c9c770b3808769913f5cc31540998+dirty 399.62 ms 479.52 ms 79.90 ms

App size

Revision Plain With Sentry Diff
505e5727f37a28ccd55899c2cfb3c9eb621b4482+dirty 7.15 MiB 8.35 MiB 1.20 MiB
a8d3643f9e1d4f56c826cbcaf3743ce7e8d6719a+dirty 7.15 MiB 8.35 MiB 1.20 MiB
c67f1b123040031140e51b05ade529512ddd0cb6+dirty 7.15 MiB 8.35 MiB 1.20 MiB
f0651d78a10c9c770b3808769913f5cc31540998+dirty 7.15 MiB 8.35 MiB 1.20 MiB

github-actions[bot] avatar Oct 17 '24 23:10 github-actions[bot]

moving to draft until CI is fixed

lucas-zimerman avatar Oct 18 '24 02:10 lucas-zimerman

Too bad yarn lint gives unuseful information offline but CI is now passing

Executing: npx google-java-format --set-exit-if-changed --glob='samples/react-native/android/app/src/**/*.java'
Executing: npx google-java-format --set-exit-if-changed --glob='packages/core/android/**/*.java'
Error: google-java-format exited with exit code 1.
    at errorFromExitCode (/run/media/mario/bda233cc-061c-4aa4-af24-cbb92451e918/Dev/Sentry/sentry-react-native/node_modules/google-java-format/index.js:19:10)
    at ChildProcess.<anonymous> (/run/media/mario/bda233cc-061c-4aa4-af24-cbb92451e918/Dev/Sentry/sentry-react-native/node_modules/google-java-format/index.js:111:40)
    at ChildProcess.emit (node:events:519:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)
Command failed: npx google-java-format --set-exit-if-changed --glob='packages/core/android/**/*.java'
Executing: npx google-java-format --set-exit-if-changed --glob='performance-tests/TestAppPlain/android/app/src/**/*.java'
Executing: npx google-java-format --set-exit-if-changed --glob='performance-tests/TestAppSentry/android/app/src/**/*.java'
One or more commands failed.
ERROR: "java:format lint" exited with 1.
ERROR: "lint:android" exited with 1.

lucas-zimerman avatar Oct 23 '24 14:10 lucas-zimerman

Too bad yarn lint gives unuseful information offline but CI is now passing

Yeah, sadly the google formater doesn't include any output. You can run fix and than check git on what changed.

In CI we print the changed automatically.

krystofwoldrich avatar Oct 30 '24 16:10 krystofwoldrich