Skip to content

feat(sdk-node): wire up metric producers from declarative config#6712

Open
MikeGoldsmith wants to merge 6 commits into
open-telemetry:mainfrom
honeycombio:mike/set-meter-producer
Open

feat(sdk-node): wire up metric producers from declarative config#6712
MikeGoldsmith wants to merge 6 commits into
open-telemetry:mainfrom
honeycombio:mike/set-meter-producer

Conversation

@MikeGoldsmith
Copy link
Copy Markdown
Member

Which problem is this PR solving?

The declarative config schema supports producers on periodic metric readers (currently only opencensus), but getMeterReadersFromConfiguration ignores them — producers are never passed to PeriodicExportingMetricReader.

Short description of the changes

  • Add getMetricProducersFromConfiguration that resolves config model producers to SDK MetricProducer instances
  • For opencensus: dynamically require('@opentelemetry/shim-opencensus') to avoid a hard dependency — users who configure opencensus producers must install the shim package separately
  • Warn if the shim package is not installed, or if an unknown producer type is configured
  • Pass resolved metricProducers to PeriodicExportingMetricReader for both OTLP and console exporters

Type of change

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

How Has This Been Tested?

189 sdk-node tests pass. Full lint passes.

Checklist:

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

Closes #6424

Pass the `producers` config to PeriodicExportingMetricReader when
creating metric readers from declarative config.

Currently only opencensus is defined in the config schema. The
implementation dynamically requires @opentelemetry/shim-opencensus
at runtime to avoid adding it as a hard dependency — users who
configure opencensus producers must install the shim package
separately. A warning is emitted if the package is not found.

Closes open-telemetry#6424

Assisted-by: Claude Opus 4.6
@MikeGoldsmith MikeGoldsmith requested a review from a team as a code owner May 13, 2026 15:23
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.85%. Comparing base (c390f54) to head (9f88a33).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...ental/packages/opentelemetry-sdk-node/src/utils.ts 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6712      +/-   ##
==========================================
- Coverage   94.86%   94.85%   -0.02%     
==========================================
  Files         376      377       +1     
  Lines       12717    12765      +48     
  Branches     2884     2891       +7     
==========================================
+ Hits        12064    12108      +44     
- Misses        653      657       +4     
Files with missing lines Coverage Δ
...ental/packages/opentelemetry-sdk-node/src/utils.ts 97.08% <92.85%> (-0.12%) ⬇️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Assisted-by: Claude Opus 4.6
Copy link
Copy Markdown
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Just a nit. Not merging yet, to give Mike a chance to address the nit.

Comment thread experimental/packages/opentelemetry-sdk-node/src/utils.ts Outdated
Export MetricProducer as MetricProducerConfigModel from the
configuration package and use it as the function parameter type
instead of PeriodicMetricReaderConfigModel['producers']. This
decouples the function from PeriodicMetricReader so it can be
reused for PullMetricReader later.

Assisted-by: Claude Opus 4.6
@trentm trentm added this pull request to the merge queue May 15, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch May 15, 2026
@trentm trentm enabled auto-merge May 15, 2026 18:23
@trentm
Copy link
Copy Markdown
Contributor

trentm commented May 15, 2026

@MikeGoldsmith I broke test/start.test.ts in a mismerge (using the GitHub UI to resolve a conflict).
Here is a fix:

diff --git a/experimental/packages/opentelemetry-sdk-node/test/start.test.ts b/experimental/packages/opentelemetry-sdk-node/test/start.test.ts
index ede4ccd37..8f6021b06 100644
--- a/experimental/packages/opentelemetry-sdk-node/test/start.test.ts
+++ b/experimental/packages/opentelemetry-sdk-node/test/start.test.ts
@@ -986,6 +986,8 @@ describe('startNodeSDK', function () {
         )
       );
       await (reader as PeriodicExportingMetricReader).shutdown();
+    });
+
     it('should warn when exporter timeout is 0', async () => {
       const warnSpy = Sinon.spy(diag, 'warn');
       const exporter = getSpanExporter({

Can you please apply this?
I'm unable to push to your branch:

% git push honeycombio mike/set-meter-producer
ERROR: Permission to honeycombio/opentelemetry-js.git denied to trentm.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

which I think is (always/often?) the case with corporate forks.

(Aside: I find it inconsistent that I cannot push to this fork, but if there is a merge conflict, the GitHub UI allows me to push a commit along with any edits I've made to that file.)

Copy link
Copy Markdown
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

See the fix from #6712 (comment) (comment just above) because I mucked up a merge conflict.

auto-merge was automatically disabled May 18, 2026 13:40

Head branch was pushed to by a user without write access

@MikeGoldsmith
Copy link
Copy Markdown
Member Author

Thanks @trentm - I've applied the fix, should be good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

set meter producer on opentelemetry-sdk-node

2 participants