Skip to content

fix(otlp-exporter-base): honor env proxy settings#6660

Open
cyphercodes wants to merge 1 commit into
open-telemetry:mainfrom
cyphercodes:fix-otlp-http-env-proxy-6638
Open

fix(otlp-exporter-base): honor env proxy settings#6660
cyphercodes wants to merge 1 commit into
open-telemetry:mainfrom
cyphercodes:fix-otlp-http-env-proxy-6638

Conversation

@cyphercodes
Copy link
Copy Markdown

Which problem is this PR solving?

Fixes #6638.

Short description of the changes

Pass Node's proxyEnv agent option when env proxy settings are present so OTLP HTTP exporters honor HTTP_PROXY / HTTPS_PROXY / NO_PROXY without dropping existing agent options such as keepAlive.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • npm run compile in experimental/packages/otlp-exporter-base
  • npm test in experimental/packages/otlp-exporter-base
  • npm run lint in experimental/packages/otlp-exporter-base
  • local HTTPS proxy smoke test verifying the agent routes through HTTPS_PROXY

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated (changelog)

@cyphercodes cyphercodes requested a review from a team as a code owner May 1, 2026 03:32
Signed-off-by: cyphercodes <cyphercodes@users.noreply.github.com>
@cyphercodes cyphercodes force-pushed the fix-otlp-http-env-proxy-6638 branch from 9289f34 to 8a164e5 Compare May 1, 2026 03:33
Copy link
Copy Markdown
Member

@raphael-theriault-swi raphael-theriault-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I'll let @pichlermarc take a look

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.52%. Comparing base (568ce1b) to head (8a164e5).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6660   +/-   ##
=======================================
  Coverage   95.51%   95.52%           
=======================================
  Files         372      372           
  Lines       12361    12375   +14     
  Branches     2836     2843    +7     
=======================================
+ Hits        11807    11821   +14     
  Misses        554      554           
Files with missing lines Coverage Δ
.../src/configuration/otlp-node-http-configuration.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pichlermarc pichlermarc self-assigned this May 13, 2026
function hasEnvProxyConfiguration(): boolean {
return (
process.env.NODE_USE_ENV_PROXY === '1' ||
hasEnvProxyEnvVar('HTTP_PROXY') ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node's process.env values are always strings (https://nodejs.org/api/process.html#processenv), e.g.:

> process.env.FOO = 42
42
> process.env.FOO
'42'

so these hasEnvProxyEnvVar usages can be:

Suggested change
hasEnvProxyEnvVar('HTTP_PROXY') ||
process.env.HTTP_PROXY ||

as Node.js core is doing: https://github.com/nodejs/node/blob/9fe7634c12a6ee7491729dc1e0a8c2020f87f8c4/lib/internal/process/pre_execution.js#L201-L204


function hasEnvProxyConfiguration(): boolean {
return (
process.env.NODE_USE_ENV_PROXY === '1' ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process.env.NODE_USE_ENV_PROXY === '1' ||

This env var is for a user to tell node to read proxy-related envvars, if there are any. This isn't an indication that there is proxy-related env.

Comment on lines +57 to +59
// `proxyEnv` is used by Node.js' HTTP agents to honor HTTP(S)_PROXY
// while preserving exporter-specific agent options such as keepAlive.
return { proxyEnv: process.env };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we could pass in the full process.env, I don't think we should. The Node.js docs for proxyEnv suggest only the well-known 5 values are used: https://nodejs.org/api/http.html#new-agentoptions

Perhaps:

Suggested change
// `proxyEnv` is used by Node.js' HTTP agents to honor HTTP(S)_PROXY
// while preserving exporter-specific agent options such as keepAlive.
return { proxyEnv: process.env };
return {
proxyEnv: {
HTTP_PROXY: process.env.HTTP_PROXY,
HTTPS_PROXY: process.env.HTTPS_PROXY,
NO_PROXY: process.env.NO_PROXY,
http_proxy: process.env.http_proxy,
https_proxy: process.env.https_proxy,
no_proxy: process.env.no_proxy,
}
};

I suppose a fair argument is that passing in process.env works, and avoid creating another object.

Comment on lines +82 to +90
it('passes proxyEnv to agents when NODE_USE_ENV_PROXY is enabled', async function () {
process.env.NODE_USE_ENV_PROXY = '1';
const factory = httpAgentFactoryFromOptions({ keepAlive: true });

const agent = (await factory('https:')) as https.Agent;

assert.strictEqual(agentOptions(agent).keepAlive, true);
assert.strictEqual(agentOptions(agent).proxyEnv, process.env);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this test, assuming agreement with dropping using NODE_USE_ENV_PROXY above.

Comment on lines +80 to +85
...envProxyAgentOptions,
} as http.AgentOptions);
}
return new Agent(options);
return new Agent({
...options,
...envProxyAgentOptions,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should envProxyAgentOptions be applied before the passed in options? That would allow the caller of httpAgentFactoryFromOptions to specify its own custom proxyEnv.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@opentelemetry/otlp-exporter-base createHttpAgent() ignores HTTPS_PROXY env / EnvHttpProxyAgent — silent telemetry loss for users behind env-proxies

4 participants