Skip to content

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Oct 8, 2025

Which problem is this PR solving?

Implements dynamic headers for the HTTP-based exporters. The current internal implementation was already prepared for synchronous dynamic headers. A synchronous approach had two downsides that would've just limited its usefulness to end-users:

  • to refresh an OAuth token (the most common use-case for this feature) an async call is almost always necessary. Any token refreshes would've been flaky at best without that, since refresh and export timing would be de-coupled from one another.
  • Another downside of the synchronous approach was that dynamic import calls were impossible to use. Delaying the loading of any libraries so that the can be instrumented, was only possible in CJS, not ESM.

To circumvent these issues, this PR makes the internal function used to obtain headers async and also allows the end-user to pass it to the exporter. There is still some potential of this feature being a footgun due to possible load-order issues, however, with the approach from this PR we can provide guidance on how to do this safely without causing issues. If needed, we can also provide a utility class to reduce friction later.

Almost all of the code was already tested since #5179 switched to factory functions internally to prepare for this change (see coverage report on this PR). These tests simply changed in this PR from sync to async.

Other potential issues not tackled in this PR:

  • we don't have any hooks to react to 401 or 403 so one HAS to do proactive token refresh.
    • if this becomes a problem that users run into we could solve this by having 401 and 403 be retryable. I've opted not to do this right now as I'd like to see if the current solution is "good enough"

Closes #5756
Closes #2903

@pichlermarc pichlermarc changed the title Feat/dynamic headers http feat(otlp-exporter-base): allow passing a function to headers option Oct 8, 2025
Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.00%. Comparing base (471b411) to head (7cde170).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5994   +/-   ##
=======================================
  Coverage   94.99%   95.00%           
=======================================
  Files         313      314    +1     
  Lines        8775     8780    +5     
  Branches     1884     1885    +1     
=======================================
+ Hits         8336     8341    +5     
  Misses        439      439           
Files with missing lines Coverage Δ
...e/src/configuration/convert-legacy-http-options.ts 100.00% <100.00%> (ø)
.../configuration/convert-legacy-node-http-options.ts 100.00% <100.00%> (ø)
...-base/src/configuration/otlp-http-configuration.ts 100.00% <100.00%> (ø)
...ter-base/src/configuration/shared-configuration.ts 100.00% <100.00%> (ø)
...rter-base/src/transport/http-exporter-transport.ts 96.00% <100.00%> (+0.16%) ⬆️
...xporter-base/src/transport/http-transport-utils.ts 100.00% <100.00%> (ø)
...perimental/packages/otlp-exporter-base/src/util.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 changed the title feat(otlp-exporter-base): allow passing a function to headers option feat(otlp-exporter-base)!: allow passing a function to headers option Oct 9, 2025
@pichlermarc pichlermarc changed the title feat(otlp-exporter-base)!: allow passing a function to headers option feat(otlp-exporter-base)!: allow passing an async function to headers option Oct 9, 2025
@pichlermarc pichlermarc force-pushed the feat/dynamic-headers-http branch from fb742e6 to 2eb5cdb Compare October 9, 2025 12:23
@pichlermarc pichlermarc marked this pull request as ready for review October 14, 2025 15:55
@pichlermarc pichlermarc requested a review from a team as a code owner October 14, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable to use a function for headers in exporters Dynamic Header for OTLPTraceExporter - Package @opentelemetry/exporter-trace-otlp-http

1 participant