Skip to content

instrumentation of http{s}.request() has a few edge case issues #2044

@trentm

Description

@trentm

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))
        }
      }
  1. That iteration through all args changes the signature of http.request() such that you can pass any number of objects and URLs to it -- before and after a callback function. Not a biggie.
  2. That ensureUrl uses a formatURL 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:

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions