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.

@MikeGoldsmith MikeGoldsmith requested a review from trentm May 19, 2026 08:40
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.

I'll add to the JS SIG agenda for tomorrow for the side questions I have below.

Approving to remove my block on this, though I think the test case should be updated (see comment below).

const {
OpenCensusMetricProducer,
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('@opentelemetry/shim-opencensus');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will be one of the very few conditional imports that we have in OTel JS.

FWIW, we currently do this for:

  • require(): lazy load of @grpc/grpc-js in otlp-grpc-exporter-base to avoid loading it before instrumentation-grpc is possibly in place
  • await import(): for platform-specific code in packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId.ts
  • await import(): lazy load of http or https in experimental/packages/otlp-exporter-base/src/transport/http-exporter-transport.ts and experimental/packages/otlp-exporter-base/src/configuration/otlp-node-http-configuration.ts

I think having a dynamic import here is a better option than having a dep on shim-opencensus and always importing it.


Aside: I'm kinda curious if, given https://opentelemetry.io/blog/2023/sunsetting-opencensus/, we could eventually/soon/now remove opencensus support. https://opentelemetry.io/blog/2023/sunsetting-opencensus/#fn:3 mentions supporting the OpenCensus shims for a year. It has been more than a year since the shim-opencensus package was released.

@maryliag Do you happen to know?


Whereever we have Node.js-specific usage docs for declarative config, I think we should add a note that using producers: ["opencensus"] requires the user to separately install the @opentelemetry/shim-opencensus dep.

});
assert.ok(reader !== undefined);
await (reader as PeriodicExportingMetricReader).shutdown();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test isn't actually testing that the shim producer is working. If I make this change:

diff --git a/experimental/packages/opentelemetry-sdk-node/src/utils.ts b/experimental/packages/opentelemetry-sdk-node/src/utils.ts
index d80eb9a36..9495a2d01 100644
--- a/experimental/packages/opentelemetry-sdk-node/src/utils.ts
+++ b/experimental/packages/opentelemetry-sdk-node/src/utils.ts
@@ -529,7 +529,7 @@ function getMetricProducersFromConfiguration(
         const {
           OpenCensusMetricProducer,
           // eslint-disable-next-line @typescript-eslint/no-require-imports
-        } = require('@opentelemetry/shim-opencensus');
+        } = require('@opentelemetry/shim-opencensusXXX');
         result.push(new OpenCensusMetricProducer());
       } catch {
         diag.warn(

the test case still passes.

I think this could cheat and look at reader._metricProducers[0].constructor.name matches "OpenCensusMetricProducer".

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

3 participants