Skip to content

refactor(sdk-trace, sdk-logs, sdk-metrics): type timers without NodeJS.Timeout - #7174

Merged
overbalance merged 2 commits into
open-telemetry:mainfrom
embrace-io:overbalance/timer-typing
Oct 9, 2026
Merged

overbalance merged 2 commits into
open-telemetry:mainfrom
embrace-io:overbalance/timer-typing

Conversation

@overbalance

Copy link
Copy Markdown
Contributor

Which problem is this PR solving?

BatchSpanProcessorBase, BatchLogRecordProcessorBase and PeriodicExportingMetricReader typed their timer handle as NodeJS.Timeout | number and called .unref() behind a typeof !== 'number' guard. With DOM types and no @types/node, the NodeJS namespace does not exist and the guard narrows the handle to never, so the shared code does not compile.

A follow-up PR (#7142) adds npm run typecheck:browser, which checks every browser build with DOM types and no @types/node. This PR is one of the changes that make that check passable.

Short description of the changes

  • Timer fields are typed ReturnType<typeof setTimeout> and ReturnType<typeof setInterval>, which already compile with both Node.js and DOM types elsewhere in the repo.
  • A small unrefTimer helper in each file casts the handle to number | { unref?: () => void } and calls unref when present. The cast is legal in both type environments, and unref?.() tolerates runtimes that return an object without it.
  • One test per package stubs the timer factory and asserts unref is called once through the real scheduling path.

Type of change

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

How Has This Been Tested?

  • npm run compile, npm run lint, npm run test, npm run test:browser, npm run test:webworker from the root.
  • The three new tests pass on the previous code too, so they pin behavior rather than the refactor.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated (none needed; internal typing)

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.02%. Comparing base (a38a5f7) to head (9322134).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7174   +/-   ##
=======================================
  Coverage   95.02%   95.02%           
=======================================
  Files         382      382           
  Lines       13532    13538    +6     
  Branches     3126     3126           
=======================================
+ Hits        12859    12865    +6     
  Misses        673      673           
Files with missing lines Coverage Δ
...sdk-logs/src/export/BatchLogRecordProcessorBase.ts 91.92% <100.00%> (+0.10%) ⬆️
...etrics/src/export/PeriodicExportingMetricReader.ts 98.30% <100.00%> (+0.02%) ⬆️
...ges/sdk-trace/src/export/BatchSpanProcessorBase.ts 96.87% <100.00%> (+0.04%) ⬆️
🚀 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.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-10-09 15:49 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@overbalance
overbalance marked this pull request as ready for review October 9, 2026 02:29
@overbalance
overbalance requested a review from a team as a code owner October 9, 2026 02:29
@overbalance overbalance added this to the SDK 3.0 milestone Oct 9, 2026
@overbalance
overbalance added this pull request to the merge queue Oct 9, 2026
Merged via the queue into open-telemetry:main with commit 89ec010 Oct 9, 2026
25 checks passed
@overbalance
overbalance deleted the overbalance/timer-typing branch October 9, 2026 15:32
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.

2 participants