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(sdk-metrics): deprecate MeterProvider.addMetricReader() in favor of 'readers' constructor option #4427

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Jan 18, 2024

Which problem is this PR solving?

Currently a MetricReader is added to a MeterProvider via addMetricReader(). As Meters (and through it instruments) can be created before adding a MetricReader. This gives the false impression that the order of calls does not matter. This PR deprecates the addMetricReader() method in favor of a constructor option as it is the case for most SDKs:

  • see Java
    • does not allow adding a MetricReader after building the MeterProvider
  • see Python
    • does not allow adding a MetricReader after building the MeterProvider
  • see C++
    • the comment there seems to indicate that they are in a similar situation as we are (only meter data created after adding the MetricReader is respected.
  • see .NET [1] [2]
    • similar to Java, they have a builder that allows it, but adding it after building the MeterProvider is not possible

An alternative would be to allow adding a MetricReader like in the current interface, but re-configuring all instruments, their aggregations, assocaited views and their temporality. This however, is not required by the spec and would drastically increase complexity of an already very complex Metrics SDK.

References #4112, open-telemetry/opentelemetry-js-contrib#1900

Removal of addMetricReader for 2.0: #4419

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Adapted unit tests

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Merging #4427 (b1af2c3) into main (43e598e) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4427      +/-   ##
==========================================
+ Coverage   92.19%   92.21%   +0.01%     
==========================================
  Files         336      336              
  Lines        9511     9515       +4     
  Branches     2016     2017       +1     
==========================================
+ Hits         8769     8774       +5     
+ Misses        742      741       -1     
Files Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 92.80% <100.00%> (+0.05%) ⬆️
packages/sdk-metrics/src/MeterProvider.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@david-luna
Copy link
Contributor

LGTM


if (options?.readers != null && options.readers.length > 0) {
for (const metricReader of options.readers) {
this.addMetricReader(metricReader);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the intention for addMetricReader method?

  • to change its access to private?
  • to delete it

I'm inclined to completely remove it to avoid people using the private method anyway (because the method would be exposed in the JS class instances). If that's the case I'd suggest to add here the method logic so it will be easier to remove the method in the future

Copy link
Member

Choose a reason for hiding this comment

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

To avoid breakage, it will be removed in the SDK v2.0 (#4419).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it will be removed. I've kept the code in addMetricReader() for now to avoid duplication.

@@ -261,8 +261,9 @@ describe('PrometheusExporter', () => {

beforeEach(done => {
exporter = new PrometheusExporter({}, () => {
meterProvider = new MeterProvider();
meterProvider.addMetricReader(exporter);
meterProvider = new MeterProvider({
Copy link
Member

Choose a reason for hiding this comment

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

This looks weird to me that we have to create a MeterProvider in the callback of a PrometheusExporter.

I submitted a follow-up at #4431.

@pichlermarc pichlermarc merged commit 0f6518d into open-telemetry:main Jan 24, 2024
20 checks passed
@pichlermarc pichlermarc deleted the feat/deprecate-addmetricreader branch January 24, 2024 13:30
Zirak pushed a commit to Zirak/opentelemetry-js that referenced this pull request Sep 14, 2024
… of 'readers' constructor option (open-telemetry#4427)

* feat(sdk-metrics): add 'readers' constructor option, deprecate MeterProvider.addMetricReader()

* fix(changelog): update changelog entry, fix format
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.

3 participants