@@ -29,6 +29,7 @@ import {
29
29
spanIsSampled ,
30
30
spanToJSON ,
31
31
startInactiveSpan ,
32
+ withScope ,
32
33
} from '@sentry/core' ;
33
34
import type { Span , StartSpanOptions } from '@sentry/core' ;
34
35
import { JSDOM } from 'jsdom' ;
@@ -1028,6 +1029,75 @@ describe('browserTracingIntegration', () => {
1028
1029
} ) ;
1029
1030
} ) ;
1030
1031
1032
+ describe ( 'enablePreviousTrace' , ( ) => {
1033
+ it ( 'registers the previous trace listener on span start by default' , ( ) => {
1034
+ const client = new BrowserClient (
1035
+ getDefaultBrowserClientOptions ( {
1036
+ tracesSampleRate : 1 ,
1037
+ integrations : [ browserTracingIntegration ( { instrumentPageLoad : false , instrumentNavigation : false } ) ] ,
1038
+ } ) ,
1039
+ ) ;
1040
+ setCurrentClient ( client ) ;
1041
+ client . init ( ) ;
1042
+
1043
+ const span1 = startInactiveSpan ( { name : 'test span 1' , forceTransaction : true } ) ;
1044
+ span1 . end ( ) ;
1045
+ const span1Json = spanToJSON ( span1 ) ;
1046
+
1047
+ expect ( span1Json . links ) . toBeUndefined ( ) ;
1048
+
1049
+ // ensure we start a new trace
1050
+ getCurrentScope ( ) . setPropagationContext ( { traceId : '123' , sampleRand : 0.2 } ) ;
1051
+
1052
+ const span2 = startInactiveSpan ( { name : 'test span 2' , forceTransaction : true } ) ;
1053
+ span2 . end ( ) ;
1054
+ const spanJson2 = spanToJSON ( span2 ) ;
1055
+
1056
+ expect ( spanJson2 . links ) . toEqual ( [
1057
+ {
1058
+ attributes : {
1059
+ 'sentry.link.type' : 'previous_trace' ,
1060
+ } ,
1061
+ sampled : true ,
1062
+ span_id : span1Json . span_id ,
1063
+ trace_id : span1Json . trace_id ,
1064
+ } ,
1065
+ ] ) ;
1066
+ } ) ;
1067
+
1068
+ it ( "doesn't register the previous trace listener on span start if disabled" , ( ) => {
1069
+ const client = new BrowserClient (
1070
+ getDefaultBrowserClientOptions ( {
1071
+ tracesSampleRate : 1 ,
1072
+ integrations : [
1073
+ browserTracingIntegration ( {
1074
+ instrumentPageLoad : false ,
1075
+ instrumentNavigation : false ,
1076
+ enablePreviousTrace : false ,
1077
+ } ) ,
1078
+ ] ,
1079
+ } ) ,
1080
+ ) ;
1081
+ setCurrentClient ( client ) ;
1082
+ client . init ( ) ;
1083
+
1084
+ const span1 = startInactiveSpan ( { name : 'test span 1' , forceTransaction : true } ) ;
1085
+ span1 . end ( ) ;
1086
+ const span1Json = spanToJSON ( span1 ) ;
1087
+
1088
+ expect ( span1Json . links ) . toBeUndefined ( ) ;
1089
+
1090
+ // ensure we start a new trace
1091
+ getCurrentScope ( ) . setPropagationContext ( { traceId : '123' , sampleRand : 0.2 } ) ;
1092
+
1093
+ const span2 = startInactiveSpan ( { name : 'test span 2' , forceTransaction : true } ) ;
1094
+ span2 . end ( ) ;
1095
+ const spanJson2 = spanToJSON ( span2 ) ;
1096
+
1097
+ expect ( spanJson2 . links ) . toBeUndefined ( ) ;
1098
+ } ) ;
1099
+ } ) ;
1100
+
1031
1101
// TODO(lforst): I cannot manage to get this test to pass.
1032
1102
/*
1033
1103
it('heartbeatInterval can be a custom value', () => {
0 commit comments