@@ -24,7 +24,7 @@ type ServerEmit = typeof Server.prototype.emit;
2424
2525type StartSpanCallback = ( next : ( ) => boolean ) => boolean ;
2626type RequestWithOptionalStartSpanCallback = IncomingMessage & {
27- _startSpanCallback ?: StartSpanCallback ;
27+ _startSpanCallback ?: WeakRef < StartSpanCallback > ;
2828} ;
2929
3030const HTTP_SERVER_INSTRUMENTED_KEY = createContextKey ( 'sentry_http_server_instrumented' ) ;
@@ -88,7 +88,7 @@ export interface HttpServerIntegrationOptions {
8888 * The callback will receive the next function to continue processing the request.
8989 */
9090export function addStartSpanCallback ( request : RequestWithOptionalStartSpanCallback , callback : StartSpanCallback ) : void {
91- addNonEnumerableProperty ( request , '_startSpanCallback' , callback ) ;
91+ addNonEnumerableProperty ( request , '_startSpanCallback' , new WeakRef ( callback ) ) ;
9292}
9393
9494const _httpServerIntegration = ( ( options : HttpServerIntegrationOptions = { } ) => {
@@ -222,7 +222,7 @@ function instrumentServer(
222222 // This is used (optionally) by the httpServerSpansIntegration to attach _startSpanCallback to the request object
223223 client . emit ( 'httpServerRequest' , request , response , normalizedRequest ) ;
224224
225- const callback = ( request as RequestWithOptionalStartSpanCallback ) . _startSpanCallback ;
225+ const callback = ( request as RequestWithOptionalStartSpanCallback ) . _startSpanCallback ?. deref ( ) ;
226226 if ( callback ) {
227227 return callback ( ( ) => target . apply ( thisArg , args ) ) ;
228228 }
0 commit comments