-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathaddBreadcrumbEvent.ts
39 lines (34 loc) · 1.21 KB
/
addBreadcrumbEvent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { EventType } from '@sentry-internal/rrweb';
import { normalize } from '@sentry/core';
import type { Breadcrumb } from '@sentry/core';
import type { ReplayContainer } from '../../types';
/**
* Add a breadcrumb event to replay.
*/
export function addBreadcrumbEvent(replay: ReplayContainer, breadcrumb: Breadcrumb): void {
if (breadcrumb.category === 'sentry.transaction') {
return;
}
if (['ui.click', 'ui.input'].includes(breadcrumb.category as string)) {
replay.triggerUserActivity();
} else {
replay.checkAndHandleExpiredSession();
}
replay.addUpdate(() => {
// This should never reject
// eslint-disable-next-line @typescript-eslint/no-floating-promises
replay.throttledAddEvent({
type: EventType.Custom,
// TODO: We were converting from ms to seconds for breadcrumbs, spans,
// but maybe we should just keep them as milliseconds
timestamp: (breadcrumb.timestamp || 0) * 1000,
data: {
tag: 'breadcrumb',
// normalize to max. 10 depth and 1_000 properties per object
payload: normalize(breadcrumb, 10, 1_000),
},
});
// Do not flush after console log messages
return breadcrumb.category === 'console';
});
}