Skip to content

Http Integration + HttpsProxyAgent with http: url + calling https.get with global this = TypeError #7130

Description

@wereHamster

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g. bundle.tracing.min.js) in your SDK setup.

@sentry/node

SDK Version

7.36.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

Sentry.init({integrations: [newSentry.Integrations.Http({tracing: true})],tracesSampleRate: 1.0,})

Steps to Reproduce

constSentry=require('@sentry/node')require('@sentry/tracing')constHttpsProxyAgent=require('https-proxy-agent')Sentry.init({integrations: [newSentry.Integrations.Http({tracing: true})],tracesSampleRate: 1.0,})constget=require('https').getget({agent: newHttpsProxyAgent.HttpsProxyAgent('http://localhost:8080'),hostname: 'apple.com',})

Expected Result

no crash

Actual Result

Crash

TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
at new NodeError (node:internal/errors:393:5)
at new ClientRequest (node:_http_client:186:11)
at request (node:https:360:10)
at get (node:https:394:15)
at wrappedMethod (…/node_modules/@sentry/node/cjs/integrations/http.js:208:10)
at Object.<anonymous> (…/test.cjs:12:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)

The issue that the code that's hooking into https.get expects this to be the https module but due to how the function is called this is the globalThis.

With this being the https module, the code in normalizeRequestArgs() will initialize protocol correctly (this.globalAgent.protocol). But with this being global scope globalThis.globalAgent does not exist, so the function uses requestOptions.agent.protocol which in my code is http:.

Workaround

Setting the protocol of the agent explicitly to https: seems to make it work.

constagent=newHttpsProxyAgent.HttpsProxyAgent('http://localhost:8080')agent.protocol='https:'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions