@@ -24,7 +24,7 @@ type ServerEmit = typeof Server.prototype.emit;
24
24
25
25
type StartSpanCallback = ( next : ( ) => boolean ) => boolean ;
26
26
type RequestWithOptionalStartSpanCallback = IncomingMessage & {
27
- _startSpanCallback ?: StartSpanCallback ;
27
+ _startSpanCallback ?: WeakRef < StartSpanCallback > ;
28
28
} ;
29
29
30
30
const HTTP_SERVER_INSTRUMENTED_KEY = createContextKey ( 'sentry_http_server_instrumented' ) ;
@@ -88,7 +88,7 @@ export interface HttpServerIntegrationOptions {
88
88
* The callback will receive the next function to continue processing the request.
89
89
*/
90
90
export function addStartSpanCallback ( request : RequestWithOptionalStartSpanCallback , callback : StartSpanCallback ) : void {
91
- addNonEnumerableProperty ( request , '_startSpanCallback' , callback ) ;
91
+ addNonEnumerableProperty ( request , '_startSpanCallback' , new WeakRef ( callback ) ) ;
92
92
}
93
93
94
94
const _httpServerIntegration = ( ( options : HttpServerIntegrationOptions = { } ) => {
@@ -222,7 +222,7 @@ function instrumentServer(
222
222
// This is used (optionally) by the httpServerSpansIntegration to attach _startSpanCallback to the request object
223
223
client . emit ( 'httpServerRequest' , request , response , normalizedRequest ) ;
224
224
225
- const callback = ( request as RequestWithOptionalStartSpanCallback ) . _startSpanCallback ;
225
+ const callback = ( request as RequestWithOptionalStartSpanCallback ) . _startSpanCallback ?. deref ( ) ;
226
226
if ( callback ) {
227
227
return callback ( ( ) => target . apply ( thisArg , args ) ) ;
228
228
}
0 commit comments