Commit ac3e6e5
authored
fix(replay): Fix re-sampled sessions after a click (#17008)
This fixes a bug where an expired session-based replay will always force
a new session-based replay after a click, regardless of the actual
recording mode.
What is happening is:
- a session-based replay is left idle
- user comes back and clicks on the page and triggers the click listener
-
[`addBreadcrumbEvent()`](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/coreHandlers/util/addBreadcrumbEvent.ts#L9)
is called which then calls
[`triggerUserActivity()`](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/coreHandlers/util/addBreadcrumbEvent.ts#L15)
because it is a click
- next, `_checkSession()` and `_refreshSession()` are called and this is
where the problem starts
Inside of `_refreshSession` we stop the current replay (because the
session is expired), [however `stop()` is async and is `await`-ed before
we
re-sample](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/replay.ts#L917-L918).
So the current replay state while `stop()` is finishing has:
- `recordingMode` = `session` (initial value)
- `isEnabled` = false
Another however, `addBreadcrumbEvent` (and everything called until
`_refreshSession`) are not async and does wait for resampling
(`initializeSampling()`) to occur. This means that the click breadcrumb
ends up causing a flush and always starting a new replay recording
because we only check that [`recordingMode` is
`buffer](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/replay.ts#L626)`.
## Solution
When we call `stop()`, reset the `recordingMode` to `buffer` (this
should be safe default as it is more restrictive behaviorally than
`session`) and in `addUpdate`, add a check to see if `isEnabled()` is
true (recording is enabled).1 parent cd041e9 commit ac3e6e5
File tree
3 files changed
+140
-42
lines changed- dev-packages/browser-integration-tests/suites/replay/sessionExpiry
- packages/replay-internal
- src
- test/integration
3 files changed
+140
-42
lines changedLines changed: 105 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | | - | |
22 | | - | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | | - | |
| 27 | + | |
25 | 28 | | |
26 | | - | |
27 | | - | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | | - | |
30 | | - | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | | - | |
38 | | - | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
43 | 46 | | |
44 | | - | |
45 | | - | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | | - | |
48 | | - | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | | - | |
| 53 | + | |
51 | 54 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | | - | |
| 59 | + | |
57 | 60 | | |
58 | | - | |
| 61 | + | |
59 | 62 | | |
60 | | - | |
61 | | - | |
| 63 | + | |
| 64 | + | |
62 | 65 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
| 395 | + | |
395 | 396 | | |
396 | 397 | | |
397 | 398 | | |
| |||
503 | 504 | | |
504 | 505 | | |
505 | 506 | | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
506 | 511 | | |
507 | 512 | | |
508 | 513 | | |
| |||
623 | 628 | | |
624 | 629 | | |
625 | 630 | | |
626 | | - | |
| 631 | + | |
627 | 632 | | |
628 | 633 | | |
629 | 634 | | |
| |||
Lines changed: 29 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
211 | 223 | | |
212 | 224 | | |
213 | 225 | | |
214 | 226 | | |
215 | | - | |
| 227 | + | |
216 | 228 | | |
217 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
218 | 243 | | |
219 | 244 | | |
220 | 245 | | |
| |||
224 | 249 | | |
225 | 250 | | |
226 | 251 | | |
227 | | - | |
| 252 | + | |
228 | 253 | | |
229 | 254 | | |
230 | 255 | | |
| |||
0 commit comments