(options: NodeTransportOptions)
| 44 | * Creates a Transport that uses native the native 'http' and 'https' modules to send events to Sentry. |
| 45 | */ |
| 46 | export function makeNodeTransport(options: NodeTransportOptions): Transport { |
| 47 | let urlSegments: URL; |
| 48 | |
| 49 | try { |
| 50 | urlSegments = new URL(options.url); |
| 51 | } catch (_e) { |
| 52 | consoleSandbox(() => { |
| 53 | // eslint-disable-next-line no-console |
| 54 | console.warn( |
| 55 | '[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.', |
| 56 | ); |
| 57 | }); |
| 58 | return createTransport(options, () => Promise.resolve({})); |
| 59 | } |
| 60 | |
| 61 | const isHttps = urlSegments.protocol === 'https:'; |
| 62 | |
| 63 | // Proxy prioritization: http => `options.proxy` | `process.env.http_proxy` |
| 64 | // Proxy prioritization: https => `options.proxy` | `process.env.https_proxy` | `process.env.http_proxy` |
| 65 | const proxy = applyNoProxyOption( |
| 66 | urlSegments, |
| 67 | options.proxy || (isHttps ? process.env.https_proxy : undefined) || process.env.http_proxy, |
| 68 | ); |
| 69 | |
| 70 | const nativeHttpModule = isHttps ? https : http; |
| 71 | const keepAlive = options.keepAlive === undefined ? false : options.keepAlive; |
| 72 | |
| 73 | // TODO(v11): Evaluate if we can set keepAlive to true. This would involve testing for memory leaks in older node |
| 74 | // versions(>= 8) as they had memory leaks when using it: #2555 |
| 75 | const agent = proxy |
| 76 | ? (new HttpsProxyAgent(proxy) as http.Agent) |
| 77 | : new nativeHttpModule.Agent({ keepAlive, maxSockets: 30, timeout: 2000 }); |
| 78 | |
| 79 | const requestExecutor = createRequestExecutor(options, options.httpModule ?? nativeHttpModule, agent); |
| 80 | return createTransport(options, requestExecutor); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Honors the `no_proxy` env variable with the highest priority to allow for hosts exclusion. |
no test coverage detected