@@ -108,6 +108,10 @@ function ensureUrl (v) {
108
108
}
109
109
}
110
110
111
+ function getSafeHost ( res ) {
112
+ return res . getHeader ? res . getHeader ( 'Host' ) : res . _headers . host
113
+ }
114
+
111
115
exports . traceOutgoingRequest = function ( agent , moduleName , method ) {
112
116
var spanType = 'ext.' + moduleName + '.http'
113
117
var ins = agent . _instrumentation
@@ -146,17 +150,17 @@ exports.traceOutgoingRequest = function (agent, moduleName, method) {
146
150
var req = orig . apply ( this , newArgs )
147
151
if ( ! span ) return req
148
152
149
- if ( req . _headers . host === agent . _conf . serverHost ) {
153
+ if ( getSafeHost ( req ) === agent . _conf . serverHost ) {
150
154
agent . logger . debug ( 'ignore %s request to intake API %o' , moduleName , { id : id } )
151
155
return req
152
156
} else {
153
157
var protocol = req . agent && req . agent . protocol
154
- agent . logger . debug ( 'request details: %o' , { protocol : protocol , host : req . _headers . host , id : id } )
158
+ agent . logger . debug ( 'request details: %o' , { protocol : protocol , host : getSafeHost ( req ) , id : id } )
155
159
}
156
160
157
161
ins . bindEmitter ( req )
158
162
159
- span . name = req . method + ' ' + req . _headers . host + parsers . parseUrl ( req . path ) . pathname
163
+ span . name = req . method + ' ' + getSafeHost ( req ) + parsers . parseUrl ( req . path ) . pathname
160
164
161
165
// TODO: Research if it's possible to add this to the prototype instead.
162
166
// Or if it's somehow preferable to listen for when a `response` listener
0 commit comments