Repository navigation
Commit b4352d6
authored
fix(profiling): Drive the native UI profiler from JS (#6916)
* fix(profiling): Drive the native UI profiler from JS
UI profiling never ran after app start. React Native turns off native
tracing, so the native trace lifecycle never sees a sampled
transaction. Also, no API let JS start or stop the native profiler, so
the manual lifecycle could not work either.
Add the startProfiler and stopProfiler bridge methods. On Android, they
call Sentry.startProfiler() and Sentry.stopProfiler(), and
startProfiler returns the profiler id. On iOS, they call SentrySDK.
sentry-cocoa has no public API for the profiler id, so iOS returns nil.
Always set the manual lifecycle on the native side, because both
native SDKs refuse manual calls in trace mode. A new default
integration, ProfilingIntegration, now chooses when the profiler runs.
In trace mode, it runs while a sampled root span is active. In manual
mode, it follows Sentry.profiler.startProfiler() and stopProfiler(),
which are now exported. The integration waits for native init, stops
an app start profile that is no longer needed, and adds the profiler
id to transactions so that they link to the profile.
* docs(changelog): Add the PR link for the UI profiler fix
Replace the PR number placeholder in the CHANGELOG entry with #6916.
* fix(profiling): Link profiles per session and delay the trace stop
Warden found two problems with the profiler id. The integration kept
one id for all transactions, so transactions that ran after the
profile stopped still got the id of the stopped profile. Also, the id
arrived asynchronously and was dropped when the root span ended before
the native start call resolved.
Each start call now creates a session that holds the promise of the
native start call. Each sampled root span that is active while a
session runs is mapped to that session, and processEvent waits for the
promise before it adds the id. A transaction now gets only the id of a
profile that ran during its root span.
In trace mode, the integration now waits one 60 second chunk after the
last root span ends before it calls stop. The native SDKs ignore a
start call that comes before a requested stop takes effect at the end
of the chunk, so back-to-back root spans lost their profile after the
chunk ended.
* feat(profiling): Add the native JS thread id to spans
Sentry opens the profile of a span on the thread from the span's
thread.id. React Native spans had no thread.id, so the profile opened
on the main thread, and the JS work was in another, unnamed thread.
Add the getCurrentThreadId bridge method. It runs synchronously on the
JS thread and returns the thread id in the format of the native
profiler: the Linux thread id on Android and the Mach thread port on
iOS. The UI profiling integration reads it once and sets thread.id on
every span that does not have one.
* fix(profiling): Keep the first session of a root span and stop on unsampled roots
Warden found two more problems in the UI profiling integration.
In manual mode, a new session overwrote the session of root spans that
started under an earlier session. A transaction could then get the id
of a later profile. A root span now keeps the session that was running
when it started.
In trace mode with startOnAppStart, unsampled root spans were not
tracked, so their end never cleared the pending app start profile.
With tracesSampleRate: 0, the profiler then ran for the whole session.
The end of any root span now ends the app start profile.
* fix(profiling): Link root spans that start before native init to the app start profile
With startOnAppStart, the native SDK starts the profile before JS runs.
Root spans that started and ended before native init had no session,
so their transactions got no profiler id. Also, the afterInit handler
then saw nothing to run and stopped the app start profile at once,
without the delay that trace mode uses.
The integration now creates the app start session in setup. Root spans
that start before native init map to it, and its id resolves when
native init completes. After that, the normal logic decides when the
profiler stops. The session resolves without an id if the client
closes before native init, so no transaction waits forever.
* feat(profiling): Export uiProfilingIntegration for defaultIntegrations: false
With defaultIntegrations: false, the UI profiling integration was not
installed and could not be added, because it was not exported. The
native SDK still received profilingOptions, so trace mode never ran,
Sentry.profiler did nothing, and with startOnAppStart nothing ever
stopped the app start profile.
Export uiProfilingIntegration. It now reads profilingOptions from the
client options, so users add it without arguments. If profilingOptions
is set but the integration is not installed, the client logs a warning
and does not send profilingOptions to the native SDK.1 parent 45b07b7 commit b4352d6
24 files changed
Lines changed: 839 additions & 106 deletions
File tree
- packages/core
- RNSentryAndroidTester/app/src/test/java/io/sentry/react
- RNSentryCocoaTester/RNSentryCocoaTesterTests
- android/src
- main/java/io/sentry/react
- newarch/java/io/sentry/react
- oldarch/java/io/sentry/react
- etc
- ios
- src/js
- integrations
- profiling
- test
- integrations
- profiling
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
| 40 | + | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
| |||
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | 61 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 62 | + | |
98 | 63 | | |
99 | 64 | | |
100 | 65 | | |
| |||
172 | 137 | | |
173 | 138 | | |
174 | 139 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 140 | | |
194 | 141 | | |
195 | 142 | | |
| |||
207 | 154 | | |
208 | 155 | | |
209 | 156 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | 157 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
644 | 644 | | |
645 | 645 | | |
646 | 646 | | |
647 | | - | |
| 647 | + | |
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| |||
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
676 | | - | |
| 676 | + | |
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
556 | 557 | | |
557 | 558 | | |
558 | 559 | | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
559 | 586 | | |
560 | 587 | | |
561 | 588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
| 321 | + | |
| 322 | + | |
337 | 323 | | |
338 | 324 | | |
339 | 325 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
237 | 252 | | |
238 | 253 | | |
239 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
237 | 252 | | |
238 | 253 | | |
239 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| |||
826 | 827 | | |
827 | 828 | | |
828 | 829 | | |
| 830 | + | |
| 831 | + | |
829 | 832 | | |
830 | 833 | | |
831 | 834 | | |
| |||
1276 | 1279 | | |
1277 | 1280 | | |
1278 | 1281 | | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
1279 | 1285 | | |
1280 | 1286 | | |
1281 | 1287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
1216 | 1217 | | |
1217 | 1218 | | |
1218 | 1219 | | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
1219 | 1251 | | |
1220 | 1252 | | |
1221 | 1253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 49 | + | |
| 50 | + | |
60 | 51 | | |
61 | 52 | | |
62 | 53 | | |
| |||
0 commit comments