@@ -5,7 +5,7 @@ describe('getTraceMetaTags', () => {
5
5
cleanupChildProcesses ( ) ;
6
6
} ) ;
7
7
8
- test ( 'injects sentry tracing <meta> tags' , async ( ) => {
8
+ test ( 'injects <meta> tags with trace from incoming headers ' , async ( ) => {
9
9
const traceId = 'cd7ee7a6fe3ebe7ab9c3271559bc203c' ;
10
10
const parentSpanId = '100ff0980e7a4ead' ;
11
11
@@ -22,4 +22,53 @@ describe('getTraceMetaTags', () => {
22
22
expect ( html ) . toMatch ( / < m e t a n a m e = " s e n t r y - t r a c e " c o n t e n t = " c d 7 e e 7 a 6 f e 3 e b e 7 a b 9 c 3 2 7 1 5 5 9 b c 2 0 3 c - [ a - z 0 - 9 ] { 16 } - 1 " \/ > / ) ;
23
23
expect ( html ) . toContain ( '<meta name="baggage" content="sentry-environment=production"/>' ) ;
24
24
} ) ;
25
+
26
+ test ( 'injects <meta> tags with new trace if no incoming headers' , async ( ) => {
27
+ const runner = createRunner ( __dirname , 'server.js' ) . start ( ) ;
28
+
29
+ const response = await runner . makeRequest ( 'get' , '/test' ) ;
30
+
31
+ // @ts -ignore - response is defined, types just don't reflect it
32
+ const html = response ?. response as unknown as string ;
33
+
34
+ const traceId = html . match ( / < m e t a n a m e = " s e n t r y - t r a c e " c o n t e n t = " ( [ a - z 0 - 9 ] { 32 } ) - [ a - z 0 - 9 ] { 16 } - 1 " \/ > / ) ?. [ 1 ] ;
35
+ expect ( traceId ) . not . toBeUndefined ( ) ;
36
+
37
+ expect ( html ) . toContain ( '<meta name="baggage"' ) ;
38
+ expect ( html ) . toContain ( `sentry-trace_id=${ traceId } ` ) ;
39
+ } ) ;
40
+
41
+ test ( 'injects <meta> tags with negative sampling decision if tracesSampleRate is 0' , async ( ) => {
42
+ const runner = createRunner ( __dirname , 'server-tracesSampleRate-zero.js' ) . start ( ) ;
43
+
44
+ const response = await runner . makeRequest ( 'get' , '/test' ) ;
45
+
46
+ // @ts -ignore - response is defined, types just don't reflect it
47
+ const html = response ?. response as unknown as string ;
48
+
49
+ const traceId = html . match ( / < m e t a n a m e = " s e n t r y - t r a c e " c o n t e n t = " ( [ a - z 0 - 9 ] { 32 } ) - [ a - z 0 - 9 ] { 16 } - 0 " \/ > / ) ?. [ 1 ] ;
50
+ expect ( traceId ) . not . toBeUndefined ( ) ;
51
+
52
+ expect ( html ) . toContain ( '<meta name="baggage"' ) ;
53
+ expect ( html ) . toContain ( `sentry-trace_id=${ traceId } ` ) ;
54
+ expect ( html ) . toContain ( 'sentry-sampled=false' ) ;
55
+ } ) ;
56
+
57
+ test ( "doesn't inject sentry tracing <meta> tags if SDK is disabled" , async ( ) => {
58
+ const traceId = 'cd7ee7a6fe3ebe7ab9c3271559bc203c' ;
59
+ const parentSpanId = '100ff0980e7a4ead' ;
60
+
61
+ const runner = createRunner ( __dirname , 'server-sdk-disabled.js' ) . start ( ) ;
62
+
63
+ const response = await runner . makeRequest ( 'get' , '/test' , {
64
+ 'sentry-trace' : `${ traceId } -${ parentSpanId } -1` ,
65
+ baggage : 'sentry-environment=production' ,
66
+ } ) ;
67
+
68
+ // @ts -ignore - response is defined, types just don't reflect it
69
+ const html = response ?. response as unknown as string ;
70
+
71
+ expect ( html ) . not . toContain ( '"sentry-trace"' ) ;
72
+ expect ( html ) . not . toContain ( '"baggage"' ) ;
73
+ } ) ;
25
74
} ) ;
0 commit comments