@@ -45,36 +45,45 @@ export class Http implements Integration {
4545 return ;
4646 }
4747
48- const handlerWrapper = createHandlerWrapper ( this . _breadcrumbs , this . _tracing ) ;
48+ const wrappedHandlerMaker = _createWrappedHandlerMaker ( this . _breadcrumbs , this . _tracing ) ;
4949
5050 const httpModule = require ( 'http' ) ;
51- fill ( httpModule , 'get' , handlerWrapper ) ;
52- fill ( httpModule , 'request' , handlerWrapper ) ;
51+ fill ( httpModule , 'get' , wrappedHandlerMaker ) ;
52+ fill ( httpModule , 'request' , wrappedHandlerMaker ) ;
5353
5454 // NOTE: Prior to Node 9, `https` used internals of `http` module, thus we don't patch it.
5555 // If we do, we'd get double breadcrumbs and double spans for `https` calls.
5656 // It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
5757 if ( NODE_VERSION . major && NODE_VERSION . major > 8 ) {
5858 const httpsModule = require ( 'https' ) ;
59- fill ( httpsModule , 'get' , handlerWrapper ) ;
60- fill ( httpsModule , 'request' , handlerWrapper ) ;
59+ fill ( httpsModule , 'get' , wrappedHandlerMaker ) ;
60+ fill ( httpsModule , 'request' , wrappedHandlerMaker ) ;
6161 }
6262 }
6363}
6464
65+ type OriginalHandler = ( ) => http . ClientRequest ;
66+ type WrappedHandler = ( options : string | http . ClientRequestArgs ) => http . ClientRequest ;
67+ type WrappedHandlerMaker = ( originalHandler : OriginalHandler ) => WrappedHandler ;
68+
6569/**
66- * Wrapper function for internal `request` and `get` calls within `http` and `https` modules
70+ * Function which creates a function which creates wrapped versions of internal `request` and `get` calls within `http`
71+ * and `https` modules. (NB: Not a typo - this is a creator^2!)
72+ *
73+ * @param breadcrumbsEnabled Whether or not to record outgoing requests as breadcrumbs
74+ * @param tracingEnabled Whether or not to record outgoing requests as tracing spans
75+ *
76+ * @returns A function which accepts the exiting handler and returns a wrapped handler
6777 */
68- function createHandlerWrapper (
69- breadcrumbsEnabled : boolean ,
70- tracingEnabled : boolean ,
71- ) : ( originalHandler : ( ) => http . ClientRequest ) => ( options : string | http . ClientRequestArgs ) => http . ClientRequest {
72- return function handlerWrapper (
73- originalHandler : ( ) => http . ClientRequest ,
74- ) : ( options : string | http . ClientRequestArgs ) => http . ClientRequest {
75- return function ( this : typeof http | typeof https , options : string | http . ClientRequestArgs ) : http . ClientRequest {
78+ function _createWrappedHandlerMaker ( breadcrumbsEnabled : boolean , tracingEnabled : boolean ) : WrappedHandlerMaker {
79+ return function wrappedHandlerMaker ( originalHandler : OriginalHandler ) : WrappedHandler {
80+ return function wrappedHandler (
81+ this : typeof http | typeof https ,
82+ options : string | http . ClientRequestArgs ,
83+ ) : http . ClientRequest {
7684 const requestUrl = extractUrl ( options ) ;
7785
86+ // we don't want to record requests to Sentry as either breadcrumbs or spans, so just use the original handler
7887 if ( isSentryRequest ( requestUrl ) ) {
7988 return originalHandler . apply ( this , arguments ) ;
8089 }
0 commit comments