Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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: [new Sentry.Integrations.Http({ tracing: true })],
tracesSampleRate: 1.0,
})
Steps to Reproduce
const Sentry = require('@sentry/node')
require('@sentry/tracing')
const HttpsProxyAgent = require('https-proxy-agent')
Sentry.init({
integrations: [new Sentry.Integrations.Http({ tracing: true })],
tracesSampleRate: 1.0,
})
const get = require('https').get
get({
agent: new HttpsProxyAgent.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.
const agent = new HttpsProxyAgent.HttpsProxyAgent('http://localhost:8080')
agent.protocol = 'https:'