-
Notifications
You must be signed in to change notification settings - Fork 825
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ export interface MeterProviderOptions { | |
/** Resource associated with metric telemetry */ | ||
resource?: IResource; | ||
views?: View[]; | ||
readers?: MetricReader[]; | ||
} | ||
|
||
/** | ||
|
@@ -54,6 +55,12 @@ export class MeterProvider implements IMeterProvider { | |
this._sharedState.viewRegistry.addView(view); | ||
} | ||
} | ||
|
||
if (options?.readers != null && options.readers.length > 0) { | ||
for (const metricReader of options.readers) { | ||
this.addMetricReader(metricReader); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the intention for
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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, it will be removed. I've kept the code in |
||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -77,7 +84,13 @@ export class MeterProvider implements IMeterProvider { | |
* Register a {@link MetricReader} to the meter provider. After the | ||
* registration, the MetricReader can start metrics collection. | ||
* | ||
* <p> NOTE: {@link MetricReader} instances MUST be added before creating any instruments. | ||
* A {@link MetricReader} instance registered later may receive no or incomplete metric data. | ||
* | ||
* @param metricReader the metric reader to be registered. | ||
* | ||
* @deprecated This method will be removed in SDK 2.0. Please use | ||
* {@link MeterProviderOptions.readers} via the {@link MeterProvider} constructor instead | ||
*/ | ||
addMetricReader(metricReader: MetricReader) { | ||
const collector = new MetricCollector(this._sharedState, metricReader); | ||
|
There was a problem hiding this comment.
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.