File tree 4 files changed +40
-0
lines changed
4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -430,6 +430,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
430
430
/** @inheritdoc */
431
431
public on ( hook : 'createDsc' , callback : ( dsc : DynamicSamplingContext , rootSpan ?: Span ) => void ) : ( ) => void ;
432
432
433
+ /** @inheritdoc */
434
+ public on ( hook : 'useFrozenDsc' , callback : ( dsc : Partial < DynamicSamplingContext > , rootSpan : Span ) => void ) : ( ) => void ;
435
+
433
436
/** @inheritdoc */
434
437
public on (
435
438
hook : 'beforeSendFeedback' ,
@@ -527,6 +530,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
527
530
/** @inheritdoc */
528
531
public emit ( hook : 'createDsc' , dsc : DynamicSamplingContext , rootSpan ?: Span ) : void ;
529
532
533
+ /** @inheritdoc */
534
+ public emit ( hook : 'useFrozenDsc' , dsc : Partial < DynamicSamplingContext > , rootSpan : Span ) : void ;
535
+
530
536
/** @inheritdoc */
531
537
public emit ( hook : 'beforeSendFeedback' , feedback : FeedbackEvent , options ?: { includeReplay : boolean } ) : void ;
532
538
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
72
72
// For core implementation, we freeze the DSC onto the span as a non-enumerable property
73
73
const frozenDsc = ( rootSpan as SpanWithMaybeDsc ) [ FROZEN_DSC_FIELD ] ;
74
74
if ( frozenDsc ) {
75
+ client . emit ( 'useFrozenDsc' , frozenDsc , rootSpan ) ;
75
76
return frozenDsc ;
76
77
}
77
78
@@ -83,6 +84,7 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
83
84
const dscOnTraceState = traceStateDsc && baggageHeaderToDynamicSamplingContext ( traceStateDsc ) ;
84
85
85
86
if ( dscOnTraceState ) {
87
+ client . emit ( 'useFrozenDsc' , dscOnTraceState , rootSpan ) ;
86
88
return dscOnTraceState ;
87
89
}
88
90
Original file line number Diff line number Diff line change @@ -47,6 +47,26 @@ export function addGlobalListeners(replay: ReplayContainer): void {
47
47
}
48
48
} ) ;
49
49
50
+ // If a frozen DSC is used from a span, we want to make sure to remove the replay ID
51
+ // if the session has expired in the meanwhile
52
+ client . on ( 'useFrozenDsc' , ( dsc : Partial < DynamicSamplingContext > ) => {
53
+ if ( ! dsc . replay_id ) {
54
+ return ;
55
+ }
56
+
57
+ const replayId = replay . getSessionId ( ) ;
58
+ if (
59
+ ! replayId ||
60
+ ! replay . isEnabled ( ) ||
61
+ // We do not want to set the DSC when in buffer mode, as that means the replay has not been sent (yet)
62
+ replay . recordingMode !== 'session' ||
63
+ // This returns false if the session has expired in the meanwhile
64
+ ! replay . checkAndHandleExpiredSession ( )
65
+ ) {
66
+ delete dsc . replay_id ;
67
+ }
68
+ } ) ;
69
+
50
70
client . on ( 'spanStart' , span => {
51
71
replay . lastActiveSpan = span ;
52
72
} ) ;
Original file line number Diff line number Diff line change @@ -262,6 +262,12 @@ export interface Client<O extends ClientOptions = ClientOptions> {
262
262
*/
263
263
on ( hook : 'createDsc' , callback : ( dsc : DynamicSamplingContext , rootSpan ?: Span ) => void ) : ( ) => void ;
264
264
265
+ /**
266
+ * Register a callback to be used whenever a frozen DSC is used.
267
+ * @returns A function that, when executed, removes the registered callback.
268
+ */
269
+ on ( hook : 'useFrozenDsc' , callback : ( dsc : Partial < DynamicSamplingContext > , rootSpan : Span ) => void ) : ( ) => void ;
270
+
265
271
/**
266
272
* Register a callback when a Feedback event has been prepared.
267
273
* This should be used to mutate the event. The options argument can hint
@@ -366,6 +372,12 @@ export interface Client<O extends ClientOptions = ClientOptions> {
366
372
*/
367
373
emit ( hook : 'createDsc' , dsc : DynamicSamplingContext , rootSpan ?: Span ) : void ;
368
374
375
+ /**
376
+ * Fire a hook for when a frozen DSC (Dynamic Sampling Context) from a span is used.
377
+ * Expects the DSC as second argument, and the root span as third.
378
+ */
379
+ emit ( hook : 'useFrozenDsc' , dsc : Partial < DynamicSamplingContext > , rootSpan : Span ) : void ;
380
+
369
381
/**
370
382
* Fire a hook event for after preparing a feedback event. Events to be given
371
383
* a feedback event as the second argument, and an optional options object as
You can’t perform that action at this time.
0 commit comments