feat(sdk-metrics): add MeterConfigurator support - #7018
Conversation
Signed-off-by: Ayush kumar gupta <ag5510362@gmail.com>
|
|
|
Welcome, contributor! Thank you for your contribution to opentelemetry-js. Important reminders:
|
Pull request dashboard statusWaiting on reviewers · refreshed 2026-08-22 08:02 UTC Review the latest changes. Status above doesn't look right?
|
Fixes #6952
sdk-metricscurrently has no way to configure per-meter behavior atruntime — the
MeterConfiguratorconcept described in the metrics SDKspec
is not implemented.
sdk-logsalready implements the equivalentLoggerConfigurator(#5991); this PR ports that pattern tosdk-metrics.Short description of the changes
MeterConfig(packages/sdk-metrics/src/MeterConfig.ts): currentlya single
disabled?: booleanfield, matching the spec's minimalMeterConfigdefinition.MeterConfiguratortype andcreateMeterConfigurator()helper(
packages/sdk-metrics/src/MeterConfigurator.ts): builds a configuratorfrom an ordered list of
{ name, config }conditions, matching meternames by exact string or
*-wildcard pattern (first match wins).MeterProviderSharedStatenow accepts an optionalmeterConfiguratorand computes the
MeterConfigfor a scope ingetMeterSharedState().MeterSharedState's constructor now accepts and forwards thatMeterConfigtoMeter.Meterstores the resolved config and, whendisabled: true, returnsthe no-op instrument (
createNoopMeter()) from everycreate*instrument method and no-ops
addBatchObservableCallback, instead ofregistering real storage.
MeterProviderOptions.meterConfigurator(already present on theinterface) is now actually passed through to
MeterProviderSharedState— previously it was accepted but silently ignored.
MeterConfig,MeterConfigurator,MeterConfiguratorCondition,and
createMeterConfiguratorfrom the package's publicindex.ts.test/MeterConfigurator.test.tscovering:conditions, and no-match →
nullMeterProviderconfigured with a disabled patternproduces no recorded data points for matching meters while unrelated
meters record normally.
Type of change
functionality to not work as expected)
How Has This Been Tested?
npx tsc -p tsconfig.json --noEmit— passes with no errors.npx nx run sdk-metrics:lint— passes.npx nx run sdk-metrics:test— newMeterConfigurator.test.tssuitepasses alongside the existing
sdk-metricstest suite.MeterProviderwithout ameterConfiguratorbehaves identically to before (backward compatible —
meterConfigdefaults to
undefined→DEFAULT_METER_CONFIG→disabled: false).Checklist:
CHANGELOG.md)packages/sdk-metrics/README.md)