File tree 2 files changed +74
-0
lines changed
dev-packages/node-integration-tests/suites/tracing/meta-tags-twp-errors
2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ const { loggingTransport } = require ( '@sentry-internal/node-integration-tests' ) ;
2
+ const Sentry = require ( '@sentry/node' ) ;
3
+
4
+ Sentry . init ( {
5
+ dsn :
'https://[email protected] /1337' ,
6
+ transport : loggingTransport ,
7
+ } ) ;
8
+
9
+ // express must be required after Sentry is initialized
10
+ const express = require ( 'express' ) ;
11
+ const { startExpressServerAndSendPortToRunner } = require ( '@sentry-internal/node-integration-tests' ) ;
12
+
13
+ const app = express ( ) ;
14
+
15
+ app . get ( '/test' , ( _req , res ) => {
16
+ Sentry . captureException ( new Error ( 'This is a test error' ) ) ;
17
+ Sentry . getClient ( ) . on ( 'beforeEnvelope' , envelope => {
18
+ const event = envelope [ 1 ] [ 0 ] [ 1 ] ;
19
+ if ( event . exception . values [ 0 ] . value === 'This is a test error' ) {
20
+ res . send ( {
21
+ traceData : Sentry . getTraceData ( ) ,
22
+ traceMetaTags : Sentry . getTraceMetaTags ( ) ,
23
+ errorTraceContext : event . contexts . trace ,
24
+ } ) ;
25
+ }
26
+ } ) ;
27
+ } ) ;
28
+
29
+ Sentry . setupExpressErrorHandler ( app ) ;
30
+
31
+ startExpressServerAndSendPortToRunner ( app ) ;
Original file line number Diff line number Diff line change
1
+ import { cleanupChildProcesses , createRunner } from '../../../utils/runner' ;
2
+
3
+ describe ( 'errors in Tracing without Performance mode' , ( ) => {
4
+ afterAll ( ( ) => {
5
+ cleanupChildProcesses ( ) ;
6
+ } ) ;
7
+
8
+ test ( 'error has the same traceId as obtained via getTraceData()/getTraceMetaTags()' , async ( ) => {
9
+ const runner = createRunner ( __dirname , 'server.js' ) . start ( ) ;
10
+
11
+ const response = await runner . makeRequest ( 'get' , '/test' ) ;
12
+
13
+ console . log ( 'response: ' , response ) ;
14
+
15
+ const { traceData, traceMetaTags, errorTraceContext } = response as {
16
+ traceData : Record < string , string > ;
17
+ traceMetaTags : string ;
18
+ errorTraceContext : {
19
+ trace_id : string ;
20
+ span_id : string ;
21
+ } ;
22
+ } ;
23
+
24
+ const traceId = errorTraceContext ?. trace_id ;
25
+ const spanId = errorTraceContext ?. span_id ;
26
+
27
+ expect ( traceId ) . toMatch ( / ^ [ a - f 0 - 9 ] { 32 } $ / ) ;
28
+ expect ( spanId ) . toMatch ( / ^ [ a - f 0 - 9 ] { 16 } $ / ) ;
29
+
30
+ expect ( errorTraceContext ) . toEqual ( {
31
+ trace_id : traceId ,
32
+ span_id : spanId ,
33
+ } ) ;
34
+
35
+ expect ( traceData ) . toEqual ( {
36
+ 'sentry-trace' : `${ traceId } -${ spanId } ` ,
37
+ baggage : expect . stringContaining ( `sentry-trace_id=${ traceId } ` ) ,
38
+ } ) ;
39
+
40
+ expect ( traceMetaTags ) . toContain ( `content="${ traceId } -${ spanId } "/>\n` ) ;
41
+ expect ( traceMetaTags ) . toContain ( `sentry-trace_id=${ traceId } ` ) ;
42
+ } ) ;
43
+ } ) ;
You can’t perform that action at this time.
0 commit comments