Skip to content

fix: add hasSubscribers property to TracingChannel - #27881

Closed
ssing2 wants to merge 1 commit into
oven-sh:mainfrom
ssing2:fix-tracingChannel-hasSubscribers
Closed

fix: add hasSubscribers property to TracingChannel#27881
ssing2 wants to merge 1 commit into
oven-sh:mainfrom
ssing2:fix-tracingChannel-hasSubscribers

Conversation

@ssing2

@ssing2 ssing2 commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #27805

Problem

TracingChannel was missing the hasSubscribers property that exists in Node.js. This made it impossible to check if any channels have subscribers before calling trace methods.

Solution

Added a hasSubscribers getter that returns true if any of the underlying channels have subscribers:

  • start
  • end
  • asyncStart
  • asyncEnd
  • error

Usage Example

const { tracingChannel } = require('diagnostics_channel');

const trace = tracingChannel('some:random:tracing:channel');

trace.subscribe({
  start (ctx) { console.log('start fired:', ctx.name) },
  end (ctx) { console.log('end fired:', ctx.name) },
  error (ctx) { console.log('error fired:', ctx.error.message) },
});

console.log('has subscribers:', trace.hasSubscribers);
// Before: undefined
// After: true

if (trace.hasSubscribers) {
  trace.traceSync(() => {
    return 'ok:demo';
  }, { name: 'demo' });
}

Changes

  • Added hasSubscribers getter to TracingChannel class
  • Returns true if any of the 5 channels have subscribers
  • Matches Node.js diagnostics_channel API

Fixes oven-sh#27805

TracingChannel was missing the hasSubscribers getter that exists
in Node.js. This property should return true if any of the
underlying channels (start, end, asyncStart, asyncEnd, error)
have subscribers.

Now users can check trace.hasSubscribers before calling
traceSync/tracePromise/traceCallback methods, matching
Node.js diagnostics_channel API.

Before:
  trace.hasSubscribers // undefined

After:
  trace.hasSubscribers // true if any channel has subscribers
@coderabbitai

coderabbitai Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2244f441-61bb-4b84-9304-bfb78b766677

📥 Commits

Reviewing files that changed from the base of the PR and between e2b0d24 and 3551fe8.

📒 Files selected for processing (1)
  • src/js/node/diagnostics_channel.ts

Walkthrough

Added a hasSubscribers getter to the TracingChannel class that aggregates the subscription state across its internal channels (start, end, asyncStart, asyncEnd, error) and exposes it as a public property.

Changes

Cohort / File(s) Summary
Diagnostic Channel Enhancement
src/js/node/diagnostics_channel.ts
Added hasSubscribers computed getter to TracingChannel class that returns true if any of the internal channels (start, end, asyncStart, asyncEnd, error) have active subscribers.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding a hasSubscribers property to TracingChannel to fix the missing feature.
Description check ✅ Passed The description is comprehensive and follows the template with clear problem statement, solution, and usage example, though verification method is implicitly demonstrated through the usage example.
Linked Issues check ✅ Passed The PR directly addresses issue #27805 by implementing the hasSubscribers getter that returns true when any of the five channels have subscribers, matching Node.js behavior and enabling the conditional tracing pattern described in the issue.
Out of Scope Changes check ✅ Passed All changes are scoped to adding the hasSubscribers getter to TracingChannel; no unrelated modifications or out-of-scope code changes are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@robobun

robobun commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the fix, @ssing2. Main still lacks TracingChannel.hasSubscribers (checked on f426a8e), but #32628 ports Node 26's TracingChannel, which includes this getter and vendors Node's test-diagnostics-channel-tracing-channel-has-subscribers.js. That PR lists Fixes #27805, is green and is still being updated, so closing this one in its favor to keep the diagnostics_channel work in one place. #27805 stays open until #32628 lands.

@robobun robobun closed this Aug 12, 2026
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.

tracingChannel().hasSubscribers is undefined

2 participants