@@ -45,36 +45,45 @@ export class Http implements Integration {
45
45
return ;
46
46
}
47
47
48
- const handlerWrapper = createHandlerWrapper ( this . _breadcrumbs , this . _tracing ) ;
48
+ const wrappedHandlerMaker = _createWrappedHandlerMaker ( this . _breadcrumbs , this . _tracing ) ;
49
49
50
50
const httpModule = require ( 'http' ) ;
51
- fill ( httpModule , 'get' , handlerWrapper ) ;
52
- fill ( httpModule , 'request' , handlerWrapper ) ;
51
+ fill ( httpModule , 'get' , wrappedHandlerMaker ) ;
52
+ fill ( httpModule , 'request' , wrappedHandlerMaker ) ;
53
53
54
54
// NOTE: Prior to Node 9, `https` used internals of `http` module, thus we don't patch it.
55
55
// If we do, we'd get double breadcrumbs and double spans for `https` calls.
56
56
// It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
57
57
if ( NODE_VERSION . major && NODE_VERSION . major > 8 ) {
58
58
const httpsModule = require ( 'https' ) ;
59
- fill ( httpsModule , 'get' , handlerWrapper ) ;
60
- fill ( httpsModule , 'request' , handlerWrapper ) ;
59
+ fill ( httpsModule , 'get' , wrappedHandlerMaker ) ;
60
+ fill ( httpsModule , 'request' , wrappedHandlerMaker ) ;
61
61
}
62
62
}
63
63
}
64
64
65
+ type OriginalHandler = ( ) => http . ClientRequest ;
66
+ type WrappedHandler = ( options : string | http . ClientRequestArgs ) => http . ClientRequest ;
67
+ type WrappedHandlerMaker = ( originalHandler : OriginalHandler ) => WrappedHandler ;
68
+
65
69
/**
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
67
77
*/
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 {
76
84
const requestUrl = extractUrl ( options ) ;
77
85
86
+ // we don't want to record requests to Sentry as either breadcrumbs or spans, so just use the original handler
78
87
if ( isSentryRequest ( requestUrl ) ) {
79
88
return originalHandler . apply ( this , arguments ) ;
80
89
}
0 commit comments