Skip to content

Http integration with proxy enabled throws ERR_INVALID_PROTOCOL error #4080

@s0rthak

Description

@s0rthak

Package + Version

  • @sentry/node: 6.13.0+

Description

When https requests behind an http proxy are made, @sentry/node versions 6.13.0+ causes the following error:

TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
    at new ClientRequest (_http_client.js:155:11)
    at Object.request (https.js:313:10)
    at Object.wrappedMethod [as request] (/Users/.../sentry-test/node_modules/@sentry/node/dist/integrations/http.js:91:18)
    at Object.<anonymous> (/Users/.../sentry-test/index.js:20:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Based on the stack-trace, it seems to be a problem with the http integration

Demo Code:

const Sentry = require("@sentry/node");
const https = require("https");
const HttpsProxyAgent = require("https-proxy-agent");

Sentry.init({
  dsn: "<DSN_HERE>",
});

const proxy = "http://<PROXY_URL>:3128"; // Please setup a http proxy server for this
const agent = new HttpsProxyAgent(proxy);

const options = {
  hostname: "example.com",
  port: 443,
  path: "/todos",
  method: "GET",
  agent,
};

const req = https.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`);
  res.on("data", (d) => {
    process.stdout.write(d);
  });
});

req.on("error", (error) => {
  console.error(error);
});

req.end();

Notes

  1. This is not a problem if proxy is disabled.
  2. This is not a problem in @sentry/node 6.12.0. Downgrading to that version resolves the issue.
  3. This is a problem with the http integration. Filtering out the http integration, resolves the issue:
Sentry.init({
  dsn: "<DSN_HERE>",
  integrations: (defaults) =>
    defaults.filter((integration) => integration.name !== "Http"),
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions