Skip to content

fix(sdk-node): ensure invalid metric reader config does not throw on startup#6295

Merged
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
dynatrace-oss-contrib:fix/metric-reader-setup-crash
Jan 14, 2026
Merged

fix(sdk-node): ensure invalid metric reader config does not throw on startup#6295
pichlermarc merged 4 commits intoopen-telemetry:mainfrom
dynatrace-oss-contrib:fix/metric-reader-setup-crash

Conversation

@pichlermarc
Copy link
Copy Markdown
Member

@pichlermarc pichlermarc commented Jan 14, 2026

Which problem is this PR solving?

Our approach to environment vars is that they should not throw if set incorrectly, but instead gracefully handle it and fall back to defaults. This is backed by the specification:

For sources accepting a numeric value, if the user provides a value which is outside the valid range for the configuration item, the implementation SHOULD generate a warning and gracefully ignore the setting, i.e., treat them as not set. In particular, implementations SHOULD NOT assign a custom interpretation e.g. to negative values if a negative value does not naturally apply to a configuration and does not have an explicitly specified meaning, but treat it like any other invalid value.

This PR aligns the NodeSDK setup of the PeriodicExportingMetricReader accordingly:

  • treats values that are negative as unset and warns
  • treats values that are interdependent (timeout and interval) by clamping these as needed

Not doing this currently causes the PeriodicExportingMetricReader to throw on startup ([1], [2], [3]) and crash the app, which can happen particularly often when just reducing OTEL_METRIC_EXPORT_INTERVAL below 30_000 (30s).

Fixes #5550 (see specifically #5550 (comment))

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added unit tests

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.39%. Comparing base (77040f3) to head (f8736b5).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ental/packages/opentelemetry-sdk-node/src/utils.ts 97.91% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6295   +/-   ##
=======================================
  Coverage   95.39%   95.39%           
=======================================
  Files         316      316           
  Lines        9548     9574   +26     
  Branches     2210     2216    +6     
=======================================
+ Hits         9108     9133   +25     
- Misses        440      441    +1     
Files with missing lines Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 95.85% <100.00%> (-0.50%) ⬇️
...ental/packages/opentelemetry-sdk-node/src/utils.ts 94.78% <97.91%> (+0.92%) ⬆️

... and 1 file 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.

@pichlermarc pichlermarc changed the title fix(sdk-node): ensure invalid metric reader config does not throw on setup fix(sdk-node): ensure invalid metric reader config does not throw on startup Jan 14, 2026
@pichlermarc pichlermarc added bug Something isn't working priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies, etc labels Jan 14, 2026
@pichlermarc pichlermarc marked this pull request as ready for review January 14, 2026 14:04
@pichlermarc pichlermarc requested a review from a team as a code owner January 14, 2026 14:04
@pichlermarc pichlermarc added this pull request to the merge queue Jan 14, 2026
Merged via the queue into open-telemetry:main with commit 4a0036a Jan 14, 2026
27 checks passed
@pichlermarc pichlermarc deleted the fix/metric-reader-setup-crash branch January 14, 2026 16:11
maryliag pushed a commit to maryliag/opentelemetry-js that referenced this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PeriodicExportingMetricReader: timeout can be greater than interval

2 participants