Commit c7e88d4
authored
fix(core): Add a PromiseBuffer for incoming events on the client (#18120)
## Problem
Previously, the client would process all incoming events without any
limit, which could lead to unbounded growth of pending events/promises
in memory. This could cause performance issues and memory pressure in
high-throughput scenarios. This occurs when two conditions are met:
- when an integration with an async `processEvent` are added (e.g.
`ContextLines`, which is a defaultIntegration)
- events, e.g. `Sentry.captureException`, are called synchronously
```js
Sentry.init({ ... });
// ...
for (let i = 0; i < 5000; i++) {
Sentry.captureException(new Error());
}
```
## Solution
This PR adds a `PromiseBuffer` to the `Client` class to limit the number
of concurrent event processing operations.
- Introduced a `_promiseBuffer` in the `Client` class that limits
concurrent event processing
- The buffer size defaults to `DEFAULT_TRANSPORT_BUFFER_SIZE` (64) but
can be configured via `transportOptions.bufferSize`
- When the buffer is full, events are rejected and properly tracked as
dropped events with the `queue_overflow` reason
- Please tak
- Modified the `_process()` method to:
- Accept a task producer function instead of a promise directly (lazy
evaluation)
- Use the promise buffer to manage concurrent operations
- Track the data category for proper dropped event categorization
## Special 👀 on
- About reusing `transportOptions.bufferSize`: Not sure if this is the
best technique, but IMO both should have the same size - because if it
wouldn't it would be capped at a later stage (asking myself if the
transport still needs the promise buffer - as we have it now way earlier
in place)
- The `_process` takes now a `DataCategory`. At the time of the process
the event type is almost unknown. Not sure if I assumed the categories
correctly there, or if there is another technique of getting the type
(**edit:** a [comment by
Cursor](https://github.com/getsentry/sentry-javascript/pull/18120/files/2ee14b484d00432145d4f9a6773fbd31f92921d7#r2504259236)
helped a little and I added [a helper
function](7381a49))
- `recordDroppedEvent` is now printing it one after each other -
theoretically we can count all occurences and print the count on it. I
decided against this one, since it would delay the user feedback - this
can be challenged though1 parent 28e9cc6 commit c7e88d4
File tree
4 files changed
+112
-17
lines changed- packages/core
- src
- test
- lib
- mocks
4 files changed
+112
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
| 206 | + | |
| 207 | + | |
204 | 208 | | |
205 | 209 | | |
206 | 210 | | |
| |||
213 | 217 | | |
214 | 218 | | |
215 | 219 | | |
| 220 | + | |
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
| |||
275 | 280 | | |
276 | 281 | | |
277 | 282 | | |
278 | | - | |
279 | | - | |
280 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
281 | 288 | | |
282 | 289 | | |
283 | 290 | | |
| |||
300 | 307 | | |
301 | 308 | | |
302 | 309 | | |
303 | | - | |
304 | | - | |
| 310 | + | |
| 311 | + | |
305 | 312 | | |
306 | 313 | | |
307 | 314 | | |
308 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
309 | 319 | | |
310 | 320 | | |
311 | 321 | | |
| |||
332 | 342 | | |
333 | 343 | | |
334 | 344 | | |
| 345 | + | |
335 | 346 | | |
336 | 347 | | |
337 | | - | |
| 348 | + | |
| 349 | + | |
338 | 350 | | |
339 | 351 | | |
340 | 352 | | |
| |||
1252 | 1264 | | |
1253 | 1265 | | |
1254 | 1266 | | |
1255 | | - | |
| 1267 | + | |
1256 | 1268 | | |
1257 | 1269 | | |
1258 | 1270 | | |
| |||
1335 | 1347 | | |
1336 | 1348 | | |
1337 | 1349 | | |
1338 | | - | |
| 1350 | + | |
1339 | 1351 | | |
1340 | | - | |
| 1352 | + | |
| 1353 | + | |
1341 | 1354 | | |
1342 | 1355 | | |
1343 | 1356 | | |
1344 | 1357 | | |
1345 | 1358 | | |
1346 | 1359 | | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
1347 | 1365 | | |
1348 | 1366 | | |
1349 | 1367 | | |
| |||
1408 | 1426 | | |
1409 | 1427 | | |
1410 | 1428 | | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
1411 | 1433 | | |
1412 | 1434 | | |
1413 | 1435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | | - | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
2935 | 2936 | | |
2936 | 2937 | | |
2937 | 2938 | | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
2938 | 3001 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
| |||
0 commit comments