File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed
packages/next/src/server/api-utils Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change 1- import type { IncomingMessage } from 'http'
1+ import type { IncomingMessage , ServerResponse } from 'http'
22import type { BaseNextRequest } from '../base-http'
33import type { CookieSerializeOptions } from 'next/dist/compiled/cookie'
44import type { NextApiResponse } from '../../shared/lib/utils'
@@ -20,19 +20,33 @@ export type __ApiPreviewProps = {
2020 previewModeSigningKey : string
2121}
2222
23- export function wrapApiHandler < T extends ( ...args : any [ ] ) => any > (
24- page : string ,
25- handler : T
26- ) : T {
23+ export function wrapApiHandler <
24+ T extends (
25+ ...args : [ req : IncomingMessage , res : ServerResponse , ...any [ ] ]
26+ ) => any ,
27+ > ( page : string , handler : T ) : T {
2728 return ( ( ...args ) => {
2829 getTracer ( ) . setRootSpanAttribute ( 'next.route' , page )
2930 // Call API route method
3031 return getTracer ( ) . trace (
3132 NodeSpan . runHandler ,
3233 {
3334 spanName : `executing api route (pages) ${ page } ` ,
35+ manualSpanEnd : true ,
3436 } ,
35- ( ) => handler ( ...args )
37+ ( span ) => {
38+ if ( span ) {
39+ const res = args [ 1 ]
40+ res . end = new Proxy ( res . end , {
41+ apply ( target , thisArg , argArray ) {
42+ span . end ( )
43+ return target . apply ( thisArg , argArray as any )
44+ } ,
45+ } )
46+ }
47+
48+ return handler ( ...args )
49+ }
3650 )
3751 } ) as T
3852}
You can’t perform that action at this time.
0 commit comments