@@ -101,21 +101,25 @@ export class Http implements Integration {
101
101
// and we will no longer have to do this optional merge, we can just pass `this._tracing` directly.
102
102
const tracingOptions = this . _tracing ? { ...clientOptions , ...this . _tracing } : undefined ;
103
103
104
- const wrappedHandlerMaker = _createWrappedRequestMethodFactory ( this . _breadcrumbs , tracingOptions ) ;
105
-
106
104
// eslint-disable-next-line @typescript-eslint/no-var-requires
107
105
const httpModule = require ( 'http' ) ;
108
- fill ( httpModule , 'get' , wrappedHandlerMaker ) ;
109
- fill ( httpModule , 'request' , wrappedHandlerMaker ) ;
106
+ const wrappedHttpHandlerMaker = _createWrappedRequestMethodFactory ( this . _breadcrumbs , tracingOptions , httpModule ) ;
107
+ fill ( httpModule , 'get' , wrappedHttpHandlerMaker ) ;
108
+ fill ( httpModule , 'request' , wrappedHttpHandlerMaker ) ;
110
109
111
110
// NOTE: Prior to Node 9, `https` used internals of `http` module, thus we don't patch it.
112
111
// If we do, we'd get double breadcrumbs and double spans for `https` calls.
113
112
// It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
114
113
if ( NODE_VERSION . major && NODE_VERSION . major > 8 ) {
115
114
// eslint-disable-next-line @typescript-eslint/no-var-requires
116
115
const httpsModule = require ( 'https' ) ;
117
- fill ( httpsModule , 'get' , wrappedHandlerMaker ) ;
118
- fill ( httpsModule , 'request' , wrappedHandlerMaker ) ;
116
+ const wrappedHttpsHandlerMaker = _createWrappedRequestMethodFactory (
117
+ this . _breadcrumbs ,
118
+ tracingOptions ,
119
+ httpsModule ,
120
+ ) ;
121
+ fill ( httpsModule , 'get' , wrappedHttpsHandlerMaker ) ;
122
+ fill ( httpsModule , 'request' , wrappedHttpsHandlerMaker ) ;
119
123
}
120
124
}
121
125
}
@@ -137,6 +141,7 @@ type WrappedRequestMethodFactory = (original: OriginalRequestMethod) => WrappedR
137
141
function _createWrappedRequestMethodFactory (
138
142
breadcrumbsEnabled : boolean ,
139
143
tracingOptions : TracingOptions | undefined ,
144
+ httpModule : typeof http | typeof https ,
140
145
) : WrappedRequestMethodFactory {
141
146
// We're caching results so we don't have to recompute regexp every time we create a request.
142
147
const createSpanUrlMap = new LRUMap < string , boolean > ( 100 ) ;
@@ -172,11 +177,8 @@ function _createWrappedRequestMethodFactory(
172
177
} ;
173
178
174
179
return function wrappedRequestMethodFactory ( originalRequestMethod : OriginalRequestMethod ) : WrappedRequestMethod {
175
- return function wrappedMethod ( this : typeof http | typeof https , ...args : RequestMethodArgs ) : http . ClientRequest {
176
- // eslint-disable-next-line @typescript-eslint/no-this-alias
177
- const httpModule = this ;
178
-
179
- const requestArgs = normalizeRequestArgs ( this , args ) ;
180
+ return function wrappedMethod ( this : unknown , ...args : RequestMethodArgs ) : http . ClientRequest {
181
+ const requestArgs = normalizeRequestArgs ( httpModule , args ) ;
180
182
const requestOptions = requestArgs [ 0 ] ;
181
183
const requestUrl = extractUrl ( requestOptions ) ;
182
184
0 commit comments