Skip to content

Node HTTP integration missing protocol in breadcrumbs #3948

@thomaspurchas

Description

@thomaspurchas

Package + Version

  • @sentry/node

Version:

16.12.0

Description

The node HTTP integration occasionally misses the protocol from URL when it does argument normalisation. This is issue is caused by assuming that the arguments passed to http.request or https.request will always contain a protocol. However when making direct calls to https.request and http.request the protocol argument is optional, with the protocol default being set by the class being called.

A number of libraries seem to make use of this feature including Microsoft's Application Insights and the deprecated request library. The end result is requests originating from libraries like this end up with their protocols striped and invalid URL's being created (according to the WHATWG URL API).

The fix would be make the wrapper functions support the default values for the protocol argument, and better match the underlying Node API. I think a possible approach to extract the default protocol is to look a the modules globalAgent or the agent passed in the arguments done before extractUrl is called, something like:

if (requestArgs.protocol === undefined) {
  let protocol = this.globalAgent.protocol;
  if (requestArgs.agent instanceof this.Agent) {
    protocol = requestArgs.agent.protocol || ''
  } else if (requestArgs.agent === false) {
    protocol = new this.Agent().protocol
  }
  requestArgs.protocol = protocol
}

Screenshot 2021-09-01 at 10 15 26

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions