From 3551fe8a2857e18bd5d0e89dc7c054a4040b28e4 Mon Sep 17 00:00:00 2001 From: ssing2 Date: Sat, 7 Mar 2026 16:41:03 +0800 Subject: [PATCH] fix: add hasSubscribers property to TracingChannel Fixes #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 --- src/js/node/diagnostics_channel.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/node/diagnostics_channel.ts b/src/js/node/diagnostics_channel.ts index 4c26ff1017fe..8ff68c60567a 100644 --- a/src/js/node/diagnostics_channel.ts +++ b/src/js/node/diagnostics_channel.ts @@ -255,6 +255,14 @@ class TracingChannel { asyncEnd; error; + get hasSubscribers() { + return this.start.hasSubscribers || + this.end.hasSubscribers || + this.asyncStart.hasSubscribers || + this.asyncEnd.hasSubscribers || + this.error.hasSubscribers; + } + constructor(nameOrChannels) { if (typeof nameOrChannels === "string") { this.start = channel(`tracing:${nameOrChannels}:start`);