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 11import { get } from 'http' ;
2+ import { getActiveSpan , getClient , spanToJSON } from '@sentry/nextjs' ;
23import { NextApiRequest , NextApiResponse } from 'next' ;
34
45export default ( _req : NextApiRequest , res : NextApiResponse ) => {
6+ const as = getActiveSpan ( ) ;
7+ console . log ( 'route active span' , as && spanToJSON ( as ) ) ;
58 // make an outgoing request in order to test that the `Http` integration creates a span
69 get ( 'http://example.com/' , message => {
710 message . on ( 'data' , ( ) => {
811 // Noop consuming some data so that request can close :)
912 } ) ;
1013
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+
1121 message . on ( 'close' , ( ) => {
22+ console . log ( 'close hit' ) ;
23+ } ) ;
24+
25+ message . on ( 'error' , ( ) => {
26+ console . log ( 'error hit' ) ;
1227 res . status ( 200 ) . json ( { } ) ;
1328 } ) ;
1429 } ) ;
You can’t perform that action at this time.
0 commit comments