@@ -113,7 +113,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
113
113
stealthWrap ( moduleExports . Server . prototype , 'emit' , this . _getPatchIncomingRequestFunction ( ) ) ;
114
114
115
115
// Patch outgoing requests for breadcrumbs
116
- const patchedRequest = stealthWrap ( moduleExports , 'request' , this . _getPatchOutgoingRequestFunction ( ) ) ;
116
+ const patchedRequest = stealthWrap ( moduleExports , 'request' , this . _getPatchOutgoingRequestFunction ( 'http' ) ) ;
117
117
stealthWrap ( moduleExports , 'get' , this . _getPatchOutgoingGetFunction ( patchedRequest ) ) ;
118
118
119
119
return moduleExports ;
@@ -134,7 +134,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
134
134
stealthWrap ( moduleExports . Server . prototype , 'emit' , this . _getPatchIncomingRequestFunction ( ) ) ;
135
135
136
136
// Patch outgoing requests for breadcrumbs
137
- const patchedRequest = stealthWrap ( moduleExports , 'request' , this . _getPatchOutgoingRequestFunction ( ) ) ;
137
+ const patchedRequest = stealthWrap ( moduleExports , 'request' , this . _getPatchOutgoingRequestFunction ( 'https' ) ) ;
138
138
stealthWrap ( moduleExports , 'get' , this . _getPatchOutgoingGetFunction ( patchedRequest ) ) ;
139
139
140
140
return moduleExports ;
@@ -211,7 +211,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
211
211
/**
212
212
* Patch the outgoing request function for breadcrumbs.
213
213
*/
214
- private _getPatchOutgoingRequestFunction ( ) : (
214
+ private _getPatchOutgoingRequestFunction ( component : 'http' | 'https' ) : (
215
215
// eslint-disable-next-line @typescript-eslint/no-explicit-any
216
216
original : ( ...args : any [ ] ) => http . ClientRequest ,
217
217
) => ( options : URL | http . RequestOptions | string , ...args : unknown [ ] ) => http . ClientRequest {
@@ -226,10 +226,21 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
226
226
// so that it matches what Otel instrumentation passes to `ignoreOutgoingRequestHook`.
227
227
// @see https://github.com/open-telemetry/opentelemetry-js/blob/7293e69c1e55ca62e15d0724d22605e61bd58952/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L756-L789
228
228
const requestArgs = [ ...args ] as RequestArgs ;
229
- const options = requestArgs [ 0 ] ;
229
+
230
+ let options = requestArgs [ 0 ] ;
231
+
232
+ // Make sure correct fallback attributes are set on the options object for https before we pass them to the vendored getRequestInfo function.
233
+ // Ref: https://github.com/open-telemetry/opentelemetry-js/blob/887ff1cd6e3f795f703e40a9fbe89b3cba7e88c3/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L390
234
+ if ( component === 'https' && typeof options === 'object' && options ?. constructor ?. name !== 'URL' ) {
235
+ options = Object . assign ( { } , options ) ;
236
+ options . protocol = options . protocol || 'https:' ;
237
+ options . port = options . port || 443 ;
238
+ }
239
+
230
240
const extraOptions = typeof requestArgs [ 1 ] === 'object' ? requestArgs [ 1 ] : undefined ;
231
241
232
242
const { optionsParsed, origin, pathname } = getRequestInfo ( instrumentation . _diag , options , extraOptions ) ;
243
+
233
244
const url = getAbsoluteUrl ( origin , pathname ) ;
234
245
235
246
addSentryHeadersToRequestOptions ( url , optionsParsed , instrumentation . _propagationDecisionMap ) ;
0 commit comments