Skip to content

Support passing a custom HTTP agent instance to HTTP exporters #5711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
raphael-theriault-swi opened this issue May 26, 2025 · 0 comments · May be fixed by #5719
Open

Support passing a custom HTTP agent instance to HTTP exporters #5711

raphael-theriault-swi opened this issue May 26, 2025 · 0 comments · May be fixed by #5719

Comments

@raphael-theriault-swi
Copy link
Member

raphael-theriault-swi commented May 26, 2025

NB: Before opening a feature request against this repo, consider whether the feature should/could be implemented in the other OpenTelemetry client libraries. If so, please open an issue on opentelemetry-specification first.

Is your feature request related to a problem? Please describe.

The exporter transports are currently not particularly extensible. This isn't as true for gRPC given the JS implementation does support a bunch of environment variables, but for HTTP it's not possible to do something like support an HTTP proxy.

Describe the solution you'd like

Support providing an instance of http.Agent to the HTTP exporters. This would make it possible for vendors to support things like HTTP proxying with little to no extra complexity for SDK maintainers. We could either let the httpAgentOptions parameter also accept an agent instance, or add a new parameter.

The first option does require some kind of check to differentiate between agent options and agent instance. We can't use instanceof because the http module shouldn't be loaded before it's instrumented (in CJS). Node internally checks for an addRequest method which we could replicate. I don't have strong feelings either way.

Describe alternatives you've considered

This is motivated mostly by our need to support HTTP CONNECT proxying (which is already supported by gRPC), and I initially opened #5054 implementing it directly in the SDK. However this is a good chunk of code to maintain for something that hasn't really been requested much, and it wouldn't help with supporting

Additional context

The docs would need to mention that importing the http module to instantiate an agent before it is instrumented causes issues in CJS code. I was initially under the impression that this wasn't an issue for core modules (see #5220 (review)) but after playing with an example realized this is because our setup code is all ESM. cc @pichlermarc

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

Successfully merging a pull request may close this issue.

1 participant