opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

feat(exporter-trace-otlp-http): allow dynamic http headers

Open ianhomer opened this issue 1 year ago • 13 comments

Which problem is this PR solving?

Allow headers to by dynamically set per request

Fixes #2903

Short description of the changes

Allow headers in the OTLPTraceExporter configuration to be provided as function returning headers as well as static headers.

Type of change

Please delete options that are not relevant.

  • [x] New feature (non-breaking change which adds functionality)
  • [x] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [x] Unit test
  • [x] Tested on a local React application and verified that a dynamic header is regenerated on every trace post
  import uuidv4 from "utils/uuid";

  const exporter = new OTLPTraceExporter({
    url: window.API_URL + "/v1/trace",
    headers: () => ({ "X-RANDOM": uuidv4() }),
  });

Checklist:

  • [x] Followed the style guidelines of this project
  • [x] Unit tests have been added
  • [x] Documentation has been updated

ianhomer avatar Mar 08 '23 16:03 ianhomer

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.65%. Comparing base (ecc88a3) to head (a8ea308). Report is 50 commits behind head on main.

:exclamation: Current head a8ea308 differs from pull request most recent head 368df4b

Please upload reports for the commit 368df4b to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3662      +/-   ##
==========================================
+ Coverage   91.04%   93.65%   +2.61%     
==========================================
  Files          89      277     +188     
  Lines        1954     8465    +6511     
  Branches      416     1758    +1342     
==========================================
+ Hits         1779     7928    +6149     
- Misses        175      537     +362     
Files Coverage Δ
...kages/otlp-exporter-base/src/platform/node/util.ts 64.48% <100.00%> (ø)
...erimental/packages/otlp-exporter-base/src/types.ts 16.66% <ø> (ø)
...ter-base/src/platform/node/OTLPExporterNodeBase.ts 50.00% <50.00%> (ø)

... and 229 files with indirect coverage changes

codecov[bot] avatar Mar 08 '23 18:03 codecov[bot]

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: ianhomer / name: Ian Homer (f2f7a617abe5ce6a1978954485db9ae580ae4f9f, ccc8431d41b578de1463e0584867281cef0d06cd, 0f1b34d6f8d5e6e6dc2eb5747f8c1044240f6df2, e97703000c02cbabb1a649705f9485923e3ac844, 4b9295f349fa3af37c3ebf8b16c92679a3de9bfb, 9425b7a53507314c1df40485c8618863ab8022f6, 14cbb48f33d0d783c5c751ce1d3c1cbcce988d7f, 8336a065c3c56e319f6f32eb6de9d38d64449614, 6a7bdf76f5e8be459a15535a741323420d504ef2, b4773dca3242b109d54b33cd284805b3e52476a0, 3ec6b488fe22b2cb96fca1d198cfa38558e6a67a, 1f4470596faf24df5fd2c832c7e31b1274f59df3, 858aee5dd15d82846bf8952551eebc3d2399e187, f03903125a5d25536436053c155bc7043fa46c75, abf886ff32e53274d23d93289d7ac5a6c155feda, b7085c87b33fefe9d8b26b770bb5bb45868165ce, d375835925baf93483463d7845b11a16b8df4a2e, a0275d115c129c9a54af6df3f23a41115e287bd3, 368df4b9f4a0c5b3653881669945d0566d2ee827, e3ec55968b2a35f57d30e115a5af4ae11025eb42, b9ae3bb480cf73bb9ed6eb611a5cfc6314934f35, 8d362f1719ea287f8d6b5089af9a8b4922a81a9f, af747fbd469b753228a37525cb50bdb27653c326, 19efd2403338cc47b79f772d72c72200ca26725d)

Sorry the CLA check prevented me from reviewing this and it fell off my radar. I'll look today.

dyladan avatar May 17 '23 13:05 dyladan

When will be this merged in? We are waiting for weeks to start using it.

adros avatar Jun 30 '23 09:06 adros

@ianhomer Hi, Can you please fix the conflict so we can merge this PR?

haddasbronfman avatar Jul 04 '23 13:07 haddasbronfman

@haddasbronfman This isn't my PR, but would really like to have this functionality!

I opened a new clone of this PR, just rebased on main. Please let me know if I can help this along 😄🙏

mars avatar Aug 04 '23 21:08 mars

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Feb 19 '24 06:02 github-actions[bot]

I also really need this PR to set the bearer token which is valid only for a short time. Currently I'm using this workaround: (exporter as any)._headers[key] = value;

alaingiller avatar Feb 29 '24 12:02 alaingiller

I was wondering if there are some pending action item(s) that is/are blocking this PR from being merged ?

psx95 avatar Apr 22 '24 16:04 psx95

Sorry for not noticing this was still pending. I've resolved conflict, moved change log to the right place to allow it to be reconsidered.

ianhomer avatar Apr 22 '24 19:04 ianhomer

Thx @aabmass for your comments much appreciated. I've synced with latest code and addressed a couple of your suggestions. I think the sinon.restore() within the test is OK (albeit unusual).

Only point I'm not sure about is the breaking change on the headers no longer being a Partial - I think its not a breaking change, based on comment "Partial is unnecessary here as the Record<> type didn't add any required-key constraints." - however not 100% sure on that. I could move the change log entry to the "Breaking change" section and be explicit about this if it helps.

ianhomer avatar Jun 23 '24 23:06 ianhomer

@ianhomer thanks for working on this. We do realize that this is an important feature to have, however, we're currently in the process of re-writing the exporters for them to be more maintainable. With the re-write we aim for feature-parity with what's currently available, so we don't plan to add this feature at this time to avoid scope-creep. Once we've completed the re-write we'll add this feature.

We're also currently in the process of defining focus areas of work that we fast-track, and the exporter re-write ranks high on this list, as it is blocking quite a lot of features like this one here. With that we hope to accelerate the rate of reviews on PRs associated with the re-write which has been a main factor in the delay of getting this done.

Thanks for your patience.

pichlermarc avatar Aug 01 '24 11:08 pichlermarc

@pichlermarc thanks for the update. Sounds like a good plan, and always happy to help. Looks forward seeing these re-writes of the exporters coming in.

ianhomer avatar Aug 02 '24 19:08 ianhomer