Skip to content

diagnostics_channel: add BoundedChannel and scopes - #61680

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
Qard:dc-windows
Mar 31, 2026
Merged

diagnostics_channel: add BoundedChannel and scopes#61680
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
Qard:dc-windows

Conversation

@Qard

@QardQard commented Feb 4, 2026

Copy link
Copy Markdown
Member

This adds BoundedChannel, adds a using syntax equivalent to runStores, and modifies the internals of TracingChannel to use these to avoid closures in several places.

Why BoundedChannel?

Reviewers asked why a new class is needed instead of just using the existing channel() or tracingChannel() APIs. Here's the motivation:

  • vs channel(): A bare Channel has no built-in concept of start/end lifecycle events or store binding for async context propagation. BoundedChannel combines two channels with a withScope() / run() API that ties start → store entry → user code → end → store exit into a single unit, which a raw channel can't express.

  • vs tracingChannel(): TracingChannel is designed for tracing operations with async continuations (it has 5 events: start, end, asyncStart, asyncEnd, error). BoundedChannel is a simpler, synchronous-only primitive with just start and end. It is also used internally by TracingChannel to implement its call window and continuation window, making the code cleaner and removing several closure allocations.

The name "Bounded" reflects that the scope is bounded by the using block — start fires when the scope begins, end fires when it is disposed.

Depends on #61674

cc @nodejs/diagnostics

@QardQard self-assigned this Feb 4, 2026
@QardQard added the diagnostics_channel Issues and PRs related to diagnostics channel label Feb 4, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/web-infra

@nodejs-github-botnodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 4, 2026
@QardQard added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 4, 2026
@github-actionsgithub-actionsBot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Feb 4, 2026
@github-actions

Copy link
Copy Markdown
Contributor
Failed to start CI
 ⚠ No approving reviews found
✘ Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/21678728231

@Qard
Qardforce-pushed the dc-windows branch 7 times, most recently from c764f06 to 1018c57CompareFebruary 4, 2026 17:50

@RafaelGSSRafaelGSS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please expand on PR description on why this is needed? We have channels, tracingChannels and now windowChannel, it would be great to know for which kind of situations we need each one of them.

added: REPLACEME
-->

> Stability: 1 - Experimental

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
> Stability: 1 - Experimental
> Stability: 1 - Experimental

Perhaps 1.1 Active Development instead?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The particular change is inherited from #61674. Do you want that made there? What about the new APIs in diagnostics_channel? Same status?

@Qard

Qard commented Feb 4, 2026

Copy link
Copy Markdown
MemberAuthor

WindowChannel is mainly just to enable using syntax scopes, but is exposed as there are possible use cases where one may want to emit events around a block/scope without the greater complexity of TracingChannel.

It's also replacing most of the internals of TracingChannel to make it more coherent since there seemed to be a lot of misunderstanding of how it worked. Now TracingChannel is just a WindowChannel around start + end, a WindowChannel around asyncStart + asyncEnd, and an error channel.

@codecov

codecovBot commented Feb 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.24561% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.72%. Comparing base (5b6091c) to head (c3c4886).
⚠️ Report is 34 commits behind head on main.

Files with missing linesPatch %Lines
lib/diagnostics_channel.js98.24%5 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #61680 +/- ##
==========================================
+ Coverage 89.71% 89.72% +0.01% 
==========================================
Files 692 692 Lines 213986 214167 +181 Branches 41055 41077 +22 ==========================================
+ Hits 191969 192153 +184 - Misses 14089 14102 +13 + Partials 7928 7912 -16 
Files with missing linesCoverage Δ
lib/diagnostics_channel.js98.13% <98.24%> (-0.36%)⬇️

... and 46 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.

Comment threaddoc/api/diagnostics_channel.md Outdated
@@ -282,6 +282,53 @@ const channelsByCollection = diagnostics_channel.tracingChannel({
});
```

#### `diagnostics_channel.windowChannel(nameOrChannels)`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This name window channel is confusing. It's not related to the specific window API in JavaScript. It reads to me that it is a version of tracing channel that enables using support. I feel terms like scope could be a more intuitive name.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I feel "scope" is an equally problematic name in that it makes many think of lexical scope which is typically associated with closures, which is exactly what this is explicitly trying to not be. Naming is hard. 🤷🏻

I'm happy to pick a different name if you have a better idea for one, but I'm not convinced "scope" is much better. I had also considered "block" but that also has weird associations with "blocking" which is again misleading. 😐

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I went with BoundedChannel. Hopefully that is clear and unique enough naming.

@QardQard changed the title diagnostics_channel: add WindowChannel and scopesdiagnostics_channel: add BoundedChannel and scopesMar 17, 2026
@Qard
Qardforce-pushed the dc-windows branch 2 times, most recently from 47e089b to bf59a1fCompareMarch 17, 2026 20:21
@Qard
Qardforce-pushed the dc-windows branch 2 times, most recently from 3f4d7df to b4ce8e9CompareMarch 28, 2026 21:02
@QardQard removed the needs-ci PRs that need a full CI run. label Mar 28, 2026
@QardQard added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Mar 29, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 29, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@QardQard added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 31, 2026
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 31, 2026
@nodejs-github-bot
nodejs-github-bot merged commit cb78a7f into nodejs:mainMar 31, 2026
66 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in cb78a7f

@aduh95aduh95 added backport-requested-v24.x PRs awaiting manual backport to the v24.x-staging branch. dont-land-on-v25.x labels Mar 31, 2026
@aduh95

Copy link
Copy Markdown
Contributor

That PR doesn't land cleanly on existing release lines and is using the using keyword, which is only available on main. I've added the labels

@Qard
Qard deleted the dc-windows branch March 31, 2026 21:54
aduh95 pushed a commit that referenced this pull request May 5, 2026
PR-URL: #61680
Reviewed-By: James M Snell <jasnell@gmail.com>
@aduh95aduh95 mentioned this pull request May 5, 2026
@Renegade334

Copy link
Copy Markdown
Member

@Qard The BoundedChannel constructor is publicly exposed here, whereas the TracingChannel constructor is not. Which way round do we want these?

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

Labels

backport-requested-v24.xPRs awaiting manual backport to the v24.x-staging branch.diagnostics_channelIssues and PRs related to diagnostics channellib / srcIssues and PRs related to general changes in the lib or src directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@Qard@nodejs-github-bot@aduh95@Renegade334@jasnell@legendecas@RafaelGSS