-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsessiontiming.ts
35 lines (30 loc) · 1.12 KB
/
sessiontiming.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
import { defineIntegration } from '../integration';
import type { IntegrationFn } from '../types-hoist';
import { timestampInSeconds } from '../utils-hoist/time';
const INTEGRATION_NAME = 'SessionTiming';
const _sessionTimingIntegration = (() => {
const startTime = timestampInSeconds() * 1000;
return {
name: INTEGRATION_NAME,
processEvent(event) {
const now = timestampInSeconds() * 1000;
return {
...event,
extra: {
...event.extra,
['session:start']: startTime,
['session:duration']: now - startTime,
['session:end']: now,
},
};
},
};
}) satisfies IntegrationFn;
/**
* This function adds duration since the sessionTimingIntegration was initialized
* till the time event was sent.
*
* @deprecated This integration is deprecated and will be removed in the next major version of the SDK.
* To capture session durations alongside events, use [Context](https://docs.sentry.io/platforms/javascript/enriching-events/context/) (`Sentry.setContext()`).
*/
export const sessionTimingIntegration = defineIntegration(_sessionTimingIntegration);