1
- require ( './tracing' ) ;
1
+ import type * as S from '@sentry/node' ;
2
+ const Sentry = require ( '@sentry/node' ) as typeof S ;
3
+
4
+ Sentry . init ( {
5
+ environment : 'qa' , // dynamic sampling bias to keep transactions
6
+ dsn : process . env . E2E_TEST_DSN ,
7
+ integrations : [ ] ,
8
+ tracesSampleRate : 1 ,
9
+ tunnel : 'http://localhost:3031/' , // proxy server
10
+ tracePropagationTargets : [ 'http://localhost:3030' , '/external-allowed' ] ,
11
+ } ) ;
12
+
13
+ import type * as H from 'http' ;
14
+ import type * as F from 'fastify' ;
2
15
3
- const Sentry = require ( '@sentry/node' ) ;
4
- const { fastify } = require ( 'fastify' ) ;
5
- const http = require ( 'http' ) ;
16
+ // Make sure fastify is imported after Sentry is initialized
17
+ const { fastify } = require ( 'fastify' ) as typeof F ;
18
+ const http = require ( 'http' ) as typeof H ;
6
19
7
20
const app = fastify ( ) ;
8
21
const port = 3030 ;
9
22
const port2 = 3040 ;
10
23
11
24
Sentry . setupFastifyErrorHandler ( app ) ;
12
25
13
- app . get ( '/test-success' , function ( req , res ) {
26
+ app . get ( '/test-success' , function ( _req , res ) {
14
27
res . send ( { version : 'v1' } ) ;
15
28
} ) ;
16
29
17
- app . get ( '/test-param/:param' , function ( req , res ) {
30
+ app . get < { Params : { param : string } } > ( '/test-param/:param' , function ( req , res ) {
18
31
res . send ( { paramWas : req . params . param } ) ;
19
32
} ) ;
20
33
21
- app . get ( '/test-inbound-headers/:id' , function ( req , res ) {
34
+ app . get < { Params : { id : string } } > ( '/test-inbound-headers/:id' , function ( req , res ) {
22
35
const headers = req . headers ;
23
36
24
37
res . send ( { headers, id : req . params . id } ) ;
25
38
} ) ;
26
39
27
- app . get ( '/test-outgoing-http/:id' , async function ( req , res ) {
40
+ app . get < { Params : { id : string } } > ( '/test-outgoing-http/:id' , async function ( req , res ) {
28
41
const id = req . params . id ;
29
42
const data = await makeHttpRequest ( `http://localhost:3030/test-inbound-headers/${ id } ` ) ;
30
43
31
44
res . send ( data ) ;
32
45
} ) ;
33
46
34
- app . get ( '/test-outgoing-fetch/:id' , async function ( req , res ) {
47
+ app . get < { Params : { id : string } } > ( '/test-outgoing-fetch/:id' , async function ( req , res ) {
35
48
const id = req . params . id ;
36
49
const response = await fetch ( `http://localhost:3030/test-inbound-headers/${ id } ` ) ;
37
50
const data = await response . json ( ) ;
@@ -55,7 +68,7 @@ app.get('/test-error', async function (req, res) {
55
68
res . send ( { exceptionId } ) ;
56
69
} ) ;
57
70
58
- app . get ( '/test-exception/:id' , async function ( req , res ) {
71
+ app . get < { Params : { id : string } } > ( '/test-exception/:id' , async function ( req , res ) {
59
72
throw new Error ( `This is an exception with id ${ req . params . id } ` ) ;
60
73
} ) ;
61
74
@@ -101,9 +114,9 @@ app2.get('/external-disallowed', function (req, res) {
101
114
102
115
app2 . listen ( { port : port2 } ) ;
103
116
104
- function makeHttpRequest ( url ) {
117
+ function makeHttpRequest ( url : string ) {
105
118
return new Promise ( resolve => {
106
- const data = [ ] ;
119
+ const data : any [ ] = [ ] ;
107
120
108
121
http
109
122
. request ( url , httpRes => {
0 commit comments