@@ -45,12 +45,13 @@ function captureServeError(e: unknown): void {
4545 } ) ;
4646}
4747
48- // A user hook that throws must not fail the request or leave the span open.
49- function callHook ( name : string , hook : ( ) => void ) : void {
48+ // A user callback that throws must not fail the request or leave the span open.
49+ function callUserCallback < T > ( name : string , callback : ( ) => T , fallback : T ) : T {
5050 try {
51- hook ( ) ;
51+ return callback ( ) ;
5252 } catch ( e ) {
53- debug . warn ( `Error in the Deno.serve ${ name } hook.` , e ) ;
53+ debug . error ( `Error in the Deno.serve ${ name } callback.` , e ) ;
54+ return fallback ;
5455 }
5556}
5657
@@ -66,7 +67,11 @@ function shouldCreateSpan(
6667 if ( integration ?. ignoreStaticAssets && request . method === 'GET' && isStaticAssetRequest ( urlPath ) ) {
6768 return false ;
6869 }
69- return ! integration ?. ignoreIncomingRequests ?.( urlPath , request ) ;
70+ const ignoreIncomingRequests = integration ?. ignoreIncomingRequests ;
71+ return ! (
72+ ignoreIncomingRequests &&
73+ callUserCallback ( 'ignoreIncomingRequests' , ( ) => ignoreIncomingRequests ( urlPath , request ) , false )
74+ ) ;
7075}
7176
7277const assignIfSet = < T extends Record < string , unknown > , K extends keyof T > (
@@ -156,10 +161,12 @@ export const wrapDenoRequestHandler = <Addr extends Deno.Addr = Deno.Addr>(
156161
157162 const effectiveBodySize =
158163 integration ?. maxRequestBodySize ?? ( dataCollection . httpBodies . includes ( 'incomingRequest' ) ? 'medium' : 'none' ) ;
164+ const ignoreRequestBody = integration ?. ignoreRequestBody ;
159165 if (
160166 request . method !== 'GET' &&
161167 effectiveBodySize !== 'none' &&
162- ! integration ?. ignoreRequestBody ?.( request . url , request )
168+ // If the filter throws, skip the body so it cannot leak data the filter was meant to hide.
169+ ! ( ignoreRequestBody && callUserCallback ( 'ignoreRequestBody' , ( ) => ignoreRequestBody ( request . url , request ) , true ) )
163170 ) {
164171 await captureBodyFromWinterCGRequest ( request , isolationScope , effectiveBodySize ) ;
165172 }
@@ -189,7 +196,7 @@ export const wrapDenoRequestHandler = <Addr extends Deno.Addr = Deno.Addr>(
189196 return startSpanManual ( { name, attributes } , async span => {
190197 const { onSpanCreated, onSpanEnd } = integration ?? { } ;
191198 if ( onSpanCreated ) {
192- callHook ( 'onSpanCreated' , ( ) => onSpanCreated ( span , request ) ) ;
199+ callUserCallback ( 'onSpanCreated' , ( ) => onSpanCreated ( span , request ) , undefined ) ;
193200 }
194201 let res : Response ;
195202
@@ -211,7 +218,7 @@ export const wrapDenoRequestHandler = <Addr extends Deno.Addr = Deno.Addr>(
211218 return streamResponse (
212219 span ,
213220 res ,
214- onSpanEnd && ( ( ) => callHook ( 'onSpanEnd' , ( ) => onSpanEnd ( span , request , res ) ) ) ,
221+ onSpanEnd && ( ( ) => callUserCallback ( 'onSpanEnd' , ( ) => onSpanEnd ( span , request , res ) , undefined ) ) ,
215222 ) ;
216223 } ) ;
217224 } ,
0 commit comments