File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
dev-packages/e2e-tests/test-applications/nextjs-app-dir/pages/api Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { get } from 'http' ;
2
+ import { getActiveSpan , getClient , spanToJSON } from '@sentry/nextjs' ;
2
3
import { NextApiRequest , NextApiResponse } from 'next' ;
3
4
4
5
export default ( _req : NextApiRequest , res : NextApiResponse ) => {
6
+ const as = getActiveSpan ( ) ;
7
+ console . log ( 'route active span' , as && spanToJSON ( as ) ) ;
5
8
// make an outgoing request in order to test that the `Http` integration creates a span
6
9
get ( 'http://example.com/' , message => {
7
10
message . on ( 'data' , ( ) => {
8
11
// Noop consuming some data so that request can close :)
9
12
} ) ;
10
13
14
+ getClient ( ) ?. on ( 'spanEnd' , span => {
15
+ console . log ( 'onCloseSpan' , spanToJSON ( span ) ) ;
16
+ if ( spanToJSON ( span ) . description === 'GET http://example.com/' ) {
17
+ res . status ( 200 ) . json ( { } ) ;
18
+ }
19
+ } ) ;
20
+
11
21
message . on ( 'close' , ( ) => {
22
+ console . log ( 'close hit' ) ;
23
+ } ) ;
24
+
25
+ message . on ( 'error' , ( ) => {
26
+ console . log ( 'error hit' ) ;
12
27
res . status ( 200 ) . json ( { } ) ;
13
28
} ) ;
14
29
} ) ;
You can’t perform that action at this time.
0 commit comments