-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathresetReplayIdOnDynamicSamplingContext.ts
More file actions
38 lines (34 loc) · 1.25 KB
/
resetReplayIdOnDynamicSamplingContext.ts
File metadata and controls
38 lines (34 loc) · 1.25 KB
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
import type { DynamicSamplingContext } from '@sentry/core';
import { getActiveSpan, getCurrentScope, getDynamicSamplingContextFromSpan } from '@sentry/core';
/**
* Reset the `replay_id` field on the DSC.
*/
export function resetReplayIdOnDynamicSamplingContext(): void {
// Reset DSC on the current scope, if there is one
const dsc = getCurrentScope().getPropagationContext().dsc;
if (dsc) {
delete dsc.replay_id;
}
// Clear it from frozen DSC on the active span
const activeSpan = getActiveSpan();
if (activeSpan) {
const dsc = getDynamicSamplingContextFromSpan(activeSpan);
delete (dsc as Partial<DynamicSamplingContext>).replay_id;
}
}
/**
* Set the `replay_id` field on the cached DSC.
* The cached DSC on the scope (set by browserTracingIntegration) persists across
* session boundaries, and `createDsc` won't fire when a cached DSC already exists.
*/
export function setReplayIdOnDynamicSamplingContext(replayId: string): void {
const dsc = getCurrentScope().getPropagationContext().dsc;
if (dsc) {
dsc.replay_id = replayId;
}
const activeSpan = getActiveSpan();
if (activeSpan) {
const dsc = getDynamicSamplingContextFromSpan(activeSpan);
(dsc as Partial<DynamicSamplingContext>).replay_id = replayId;
}
}