Skip to content
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

feat(otlp-exporter-base): internally accept a http header provider function only #5179

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Nov 19, 2024

Which problem is this PR solving?

Changes internal code to always expect a header provider function, instead of a direct object. This enables us to implement #2903 later.

This does not fully implement #2903 as I want to migrate the current way of constructing an OTLP exporter to a factory function. That factory function will have a slightly different options to the existing OTLP exporters. Goal of introducing the factory function with a different interface is to:

  • reduce the public API (hide private properties and avoid that users can inherit from exporters - offering them a composition-based approach instead)
  • move to a single way of setting options (like keepAlive, or inheaders in this case)
    • a single case to handle makes the underlying code simpler and makes setup code more consistent across users, which should aid in hunting down bugs

The changes in this PR are currently non-breaking as it's not part of the public API in any released version. So it's just internally breaking if we merge it before we release the changes from #5031.

Enables #2903

Short description of the changes

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • existing unit tests
  • adapted unit tests

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.56%. Comparing base (91b9abd) to head (909666f).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5179      +/-   ##
==========================================
- Coverage   94.57%   94.56%   -0.01%     
==========================================
  Files         314      314              
  Lines        7956     7966      +10     
  Branches     1600     1601       +1     
==========================================
+ Hits         7524     7533       +9     
- Misses        432      433       +1     
Files with missing lines Coverage Δ
.../configuration/convert-legacy-node-http-options.ts 100.00% <100.00%> (ø)
...-base/src/configuration/otlp-http-configuration.ts 100.00% <100.00%> (ø)
...e/src/configuration/otlp-http-env-configuration.ts 95.83% <100.00%> (+0.08%) ⬆️
...ter-base/src/configuration/shared-configuration.ts 100.00% <100.00%> (ø)
...xporter-base/src/transport/http-transport-utils.ts 100.00% <ø> (ø)
...perimental/packages/otlp-exporter-base/src/util.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

---- 🚨 Try these New Features:

@pichlermarc pichlermarc changed the title feat(otlp-exporter-base)!: internally accept a http header provider function only feat(otlp-exporter-base): internally accept a http header provider function only Nov 19, 2024
Comment on lines +10 to +18
* feat(otlp-exporter-base)!: collapse base classes into one [#5031](https://github.com/open-telemetry/opentelemetry-js/pull/5031) @pichlermarc
* `OTLPExporterNodeBase` has been removed in favor of a platform-agnostic implementation (`OTLPExporterBase`)
* `OTLPExporterBrowserBase` has been removed in favor of a platform-agnostic implementation (`OTLPExporterBase`)
* `ExportServiceError` was intended for internal use and has been dropped from exports
* `validateAndNormalizeHeaders` was intended for internal use and has been dropped from exports
* `OTLPExporterBase` all properties are now private, the constructor now takes an `IOTLPExportDelegate`, the type parameter for config type has been dropped.
* This type is scheduled for removal in a future version of this package, please treat all exporters as `SpanExporter`, `PushMetricExporter` or `LogRecordExporter`, based on their respective type.
* feat(otlp-grpc-exporter-base)!: collapse base classes into one [#5031](https://github.com/open-telemetry/opentelemetry-js/pull/5031) @pichlermarc
* `OTLPGRPCExporterNodeBase` has been removed in favor of a platform-agnostic implementation (`OTLPExporterBase` from `@opentelemetry/otlp-exporter-base`)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: this was in the wrong spot earlier, so moved it up here.

@pichlermarc pichlermarc marked this pull request as ready for review November 19, 2024 16:23
@pichlermarc pichlermarc requested a review from a team as a code owner November 19, 2024 16:23
@@ -27,32 +27,34 @@ import type * as https from 'https';

export interface OtlpHttpConfiguration extends OtlpSharedConfiguration {
url: string;
headers: Record<string, string>;
headers: () => Record<string, string>;

Choose a reason for hiding this comment

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

Hi @pichlermarc, I have done a similar pr about that for string or function support #5118
What do you think??

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @bozzelliandrea - I'd prefer having only one option internally (as my PR here proposes) to avoid the code becoming too complex. By only dealing with provider functions internally we can handle both static and dynamic use-cases via the same code-path.

Choose a reason for hiding this comment

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

Hi @pichlermarc, do you have any idea when the team will release the version with this commit? thanks

@pichlermarc pichlermarc added this pull request to the merge queue Nov 20, 2024
Merged via the queue into open-telemetry:main with commit dd5b5fb Nov 20, 2024
20 of 21 checks passed
@pichlermarc pichlermarc deleted the feat/dynamic-http-headers branch November 20, 2024 16:26
@bozzelliandrea
Copy link

Hi @pichlermarc I've tested this commit locally but it's not enough for the dynamically headers support, the base exporter configuration interface expect a Record<string,string> and not a function.

So this feat seems only for internal purpose and not exposed externally.

@pichlermarc
Copy link
Member Author

Hi @pichlermarc I've tested this commit locally but it's not enough for the dynamically headers support, the base exporter configuration interface expect a Record<string,string> and not a function.

So this feat seems only for internal purpose and not exposed externally.

@bozzelliandrea yes, this is on purpose. We're restructuring the exporters. Legacy config is not intended to be modified since it leads to churn while we do it and delays other features - I will introduce a new interface that will expose this feature eventually. See the PR description where I already explained this.

We have asked users to avoid opening PRs for exporters while we work on it. See #5149 for the reasoning behind that.

@bozzelliandrea
Copy link

@pichlermarc thanks for the reply, I've actually already open a pr for the dynamic header support on legacy exporter, #5221 (I hadn't seen the issue #5149 before). the change doesn't have a big impact and ensures backwards compatibility, can we consider making the feature available for legacy classes too?

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.

4 participants