Skip to content

Commit 1883e34

Browse files
colthreepvQard
authored andcommitted
chore(http): workaround(s) to suppress DEP0066 warnings (#1417)
1 parent 4e2ceca commit 1883e34

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/instrumentation/http-shared.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ function ensureUrl (v) {
110110
}
111111
}
112112

113+
function getSafeHost (res) {
114+
return res.getHeader ? res.getHeader('Host') : res._headers.host
115+
}
116+
113117
exports.traceOutgoingRequest = function (agent, moduleName, method) {
114118
var ins = agent._instrumentation
115119

@@ -147,17 +151,17 @@ exports.traceOutgoingRequest = function (agent, moduleName, method) {
147151
var req = orig.apply(this, newArgs)
148152
if (!span) return req
149153

150-
if (req._headers.host === agent._conf.serverHost) {
154+
if (getSafeHost(req) === agent._conf.serverHost) {
151155
agent.logger.debug('ignore %s request to intake API %o', moduleName, { id: id })
152156
return req
153157
} else {
154158
var protocol = req.agent && req.agent.protocol
155-
agent.logger.debug('request details: %o', { protocol: protocol, host: req._headers.host, id: id })
159+
agent.logger.debug('request details: %o', { protocol: protocol, host: getSafeHost(req), id: id })
156160
}
157161

158162
ins.bindEmitter(req)
159163

160-
span.name = req.method + ' ' + req._headers.host + parseUrl(req.path).pathname
164+
span.name = req.method + ' ' + getSafeHost(req) + parseUrl(req.path).pathname
161165

162166
// TODO: Research if it's possible to add this to the prototype instead.
163167
// Or if it's somehow preferable to listen for when a `response` listener

lib/instrumentation/modules/http.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
var httpShared = require('../http-shared')
44
var shimmer = require('../shimmer')
55

6+
function getSafeHeaders (res) {
7+
return res.getHeaders ? res.getHeaders() : res._headers
8+
}
9+
610
module.exports = function (http, agent, { enabled }) {
711
if (agent._conf.instrumentIncomingHTTPRequests) {
812
agent.logger.debug('shimming http.Server.prototype.emit function')
@@ -25,7 +29,7 @@ module.exports = function (http, agent, { enabled }) {
2529
function wrapWriteHead (original) {
2630
return function wrappedWriteHead () {
2731
var headers = arguments.length === 1
28-
? this._headers // might be because of implicit headers.
32+
? getSafeHeaders(this) // might be because of implicit headers.
2933
: arguments[arguments.length - 1]
3034

3135
var result = original.apply(this, arguments)

0 commit comments

Comments
 (0)