-
Notifications
You must be signed in to change notification settings - Fork 232
Closed
Labels
8.7-candidateagent-nodejsMake available for APM Agents project planning.Make available for APM Agents project planning.
Description
In lib/instrumentation/http-shared.js the traceOutgoingRequest
function that handles instrumenting http.request
and https.request
has a few issues:
var options = {}
var newArgs = [options]
for (const arg of args) {
if (typeof arg === 'function') {
newArgs.push(arg)
} else {
Object.assign(options, ensureUrl(arg))
}
}
- That iteration through all
args
changes the signature ofhttp.request()
such that you can pass any number of objects and URLs to it -- before and after a callback function. Not a biggie. - That
ensureUrl
uses aformatURL
function that is meant to be (or should be) an equivalent to node core's handling (https://github.com/nodejs/node/blob/8d9d8236b79ea91640f973cc8c1423603694b482/lib/internal/url.js#L1288-L1311) but misses a few things:
- it doesn't restore options.auth, so users of APM and
http.request
and HTTP Basic auth in a first URL arg are being broken - it handles "port" slightly differently that could surprise, I think
- it doesn't have changes for a couple node core issues over the years: url: handle quasi-WHATWG URLs in urlToOptions() nodejs/node#26226 url: make urlToOptions() handle IPv6 literals nodejs/node#19720
I wonder if it would be possible to avoid full processing of the original args, only try to sniff out and update an "options.headers" object. Then the agent doesn't have to try to track change made to node's internal "urlToHttpOptions" handling.
One side-effect of ^^ is that the potential handling for extracting the "url", see #2039, may have to change to handle inspecting those original args
itself. I believe that would be preferable to changing the behaviour of http.request
.
Metadata
Metadata
Assignees
Labels
8.7-candidateagent-nodejsMake available for APM Agents project planning.Make available for APM Agents project planning.