Skip to content

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Oct 8, 2025

Important

DRAFT - do not review, I'll be working through the issues listed below before taking it out of draft.

  • I used AI to generate the example. it may be slop and I need to double-check.

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, 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 (see added documentation for an idea how that utility could look like).

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

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.20%. Comparing base (0b720f6) to head (419e89e).

Files with missing lines Patch % Lines
...e/src/configuration/convert-legacy-http-options.ts 83.33% 1 Missing ⚠️
...-base/src/configuration/otlp-http-configuration.ts 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5994      +/-   ##
==========================================
- Coverage   95.23%   95.20%   -0.03%     
==========================================
  Files         311      312       +1     
  Lines        8596     8601       +5     
  Branches     1799     1800       +1     
==========================================
+ Hits         8186     8189       +3     
- Misses        410      412       +2     
Files with missing lines Coverage Δ
.../configuration/convert-legacy-node-http-options.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%> (ø)
...e/src/configuration/convert-legacy-http-options.ts 83.33% <83.33%> (ø)
...-base/src/configuration/otlp-http-configuration.ts 96.42% <85.71%> (-3.58%) ⬇️
🚀 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
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