Skip to content

Commit 993bc0d

Browse files
committed
lib,test: rename suppressed/subscriberId to bypass/bypassId in diagnostics_channel
Signed-off-by: Divyanshu Sharma <divyanshu88999@gmail.com>
1 parent f3fc5cf commit 993bc0d

2 files changed

Lines changed: 77 additions & 78 deletions

File tree

lib/diagnostics_channel.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ const { subscribers: subscriberCounts } = dc_binding;
3636
const { WeakReference } = require('internal/util');
3737
const { isPromise } = require('internal/util/types');
3838

39-
let suppressionStorage;
39+
let bypassStorage;
4040

41-
function getSuppressionsStorage() {
42-
if (suppressionStorage === undefined) {
41+
function getBypassStorage() {
42+
if (bypassStorage === undefined) {
4343
const { AsyncLocalStorage } = require('async_hooks');
44-
suppressionStorage = new AsyncLocalStorage();
44+
bypassStorage = new AsyncLocalStorage();
4545
}
46-
return suppressionStorage;
46+
return bypassStorage;
4747
}
4848

4949
function withSuppressionsContext(set, fn, thisArg, args) {
50-
return getSuppressionsStorage().run(
50+
return getBypassStorage().run(
5151
set,
5252
() => ReflectApply(fn, thisArg, args),
5353
);
@@ -125,7 +125,7 @@ class RunStoresScope {
125125
// eslint-disable-next-line no-restricted-globals
126126
using stack = new DisposableStack();
127127

128-
// Normal stores - exactly as before, zero extra cost
128+
// Normal stores, unchanged from before.
129129
if (activeChannel._stores) {
130130
for (const entry of activeChannel._stores.entries()) {
131131
const store = entry[0];
@@ -145,13 +145,13 @@ class RunStoresScope {
145145
}
146146
}
147147

148-
// Bypass stores - only entered if bypass stores exist
148+
// Bypass stores, only checked when bypass stores exist.
149149
if (activeChannel._bypassStores) {
150-
const activeKeys = getSuppressionsStorage().getStore();
150+
const activeKeys = getBypassStorage().getStore();
151151
for (const entry of activeChannel._bypassStores.entries()) {
152152
const store = entry[0];
153-
const { transform, subscriberId } = entry[1];
154-
if (activeKeys?.has(subscriberId)) continue;
153+
const { transform, bypassId } = entry[1];
154+
if (activeKeys?.has(bypassId)) continue;
155155
let newContext = data;
156156
if (transform) {
157157
try {
@@ -183,18 +183,18 @@ class RunStoresScope {
183183
class ActiveChannel {
184184
subscribe(subscription, options = {}) {
185185
validateFunction(subscription, 'subscription');
186-
const subscriberId = options?.subscriberId;
186+
const bypassId = options?.bypassId;
187187

188-
if (subscriberId !== undefined) {
189-
validateBypassKey(subscriberId, 'subscriberId');
190-
// Bypass path - lazy separate array
188+
if (bypassId !== undefined) {
189+
validateBypassKey(bypassId, 'bypassId');
190+
// Bypass path, lazy separate array only allocated when needed.
191191
if (this._bypassSubscribers === null) {
192192
this._bypassSubscribers = [];
193193
}
194194
this._bypassSubscribers = ArrayPrototypeSlice(this._bypassSubscribers);
195-
ArrayPrototypePush(this._bypassSubscribers, { handler: subscription, subscriberId });
195+
ArrayPrototypePush(this._bypassSubscribers, { handler: subscription, bypassId });
196196
} else {
197-
// Normal path - plain function, zero extra cost
197+
// Normal path, plain function call with no extra overhead.
198198
this._subscribers = ArrayPrototypeSlice(this._subscribers);
199199
ArrayPrototypePush(this._subscribers, subscription);
200200
}
@@ -252,11 +252,11 @@ class ActiveChannel {
252252
}
253253

254254
bindStore(store, transform, options = {}) {
255-
const subscriberId = options?.subscriberId;
255+
const bypassId = options?.bypassId;
256256

257-
if (subscriberId !== undefined) {
258-
validateBypassKey(subscriberId, 'subscriberId');
259-
// Bypass path - lazy separate SafeMap
257+
if (bypassId !== undefined) {
258+
validateBypassKey(bypassId, 'bypassId');
259+
// Bypass path, lazy separate SafeMap only allocated when needed.
260260
if (this._bypassStores === null) {
261261
this._bypassStores = new SafeMap();
262262
}
@@ -265,9 +265,9 @@ class ActiveChannel {
265265
channels.incRef(this.name);
266266
if (this._index !== undefined) subscriberCounts[this._index]++;
267267
}
268-
this._bypassStores.set(store, { transform, subscriberId });
268+
this._bypassStores.set(store, { transform, bypassId });
269269
} else {
270-
// Normal path - plain transform, zero extra cost
270+
// Normal path, plain transform with no extra overhead.
271271
const replacing = this._stores.has(store);
272272
if (!replacing) {
273273
channels.incRef(this.name);
@@ -305,7 +305,7 @@ class ActiveChannel {
305305
}
306306

307307
publish(data) {
308-
// Normal path - no ALS lookup, plain function call, zero overhead
308+
// Normal path, no ALS lookup, plain function call, zero overhead.
309309
const subscribers = this._subscribers;
310310
for (let i = 0; i < subscribers.length; i++) {
311311
try {
@@ -317,14 +317,14 @@ class ActiveChannel {
317317
}
318318
}
319319

320-
// Bypass path - only entered if bypass subscribers exist
320+
// Bypass path, only entered if bypass subscribers exist.
321321
if (this._bypassSubscribers !== null) {
322-
const activeKeys = getSuppressionsStorage().getStore();
322+
const activeKeys = getBypassStorage().getStore();
323323
const bypassSubscribers = this._bypassSubscribers;
324324
for (let i = 0; i < bypassSubscribers.length; i++) {
325325
try {
326-
const { handler, subscriberId } = bypassSubscribers[i];
327-
if (activeKeys?.has(subscriberId)) continue;
326+
const { handler, bypassId } = bypassSubscribers[i];
327+
if (activeKeys?.has(bypassId)) continue;
328328
handler(data, this.name);
329329
} catch (err) {
330330
process.nextTick(() => {
@@ -776,12 +776,12 @@ function tracingChannel(nameOrChannels) {
776776

777777
dc_binding.linkNativeChannel((name) => channel(name));
778778

779-
function suppressed(key, fn, thisArg, ...args) {
779+
function bypass(key, fn, thisArg, ...args) {
780780
validateFunction(fn, 'fn');
781781

782782
validateBypassKey(key, 'key');
783783

784-
const currentSet = getSuppressionsStorage().getStore();
784+
const currentSet = getBypassStorage().getStore();
785785
const next = currentSet ? new SafeSet(currentSet) : new SafeSet();
786786
next.add(key);
787787
return withSuppressionsContext(next, fn, thisArg, args);
@@ -791,7 +791,7 @@ module.exports = {
791791
channel,
792792
hasSubscribers,
793793
subscribe,
794-
suppressed,
794+
bypass,
795795
tracingChannel,
796796
unsubscribe,
797797
boundedChannel,

test/parallel/test-diagnostics-channel-suppression.js renamed to test/parallel/test-diagnostics-channel-bypass.js

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,60 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
const { channel, suppressed } = require('node:diagnostics_channel');
5+
const { channel, bypass } = require('node:diagnostics_channel');
66
const { AsyncLocalStorage } = require('async_hooks');
77

8-
// Test 1: Basic suppression - subscriber with subscriberId is skipped inside suppressed()
8+
// Test 1: Basic bypass - subscriber with bypassId is skipped inside bypass()
99
{
1010
const key = Symbol('tracer');
11-
const ch = channel('test-suppression-basic');
11+
const ch = channel('test-bypass-basic');
1212
const handler = common.mustNotCall();
13-
ch.subscribe(handler, { subscriberId: key });
13+
ch.subscribe(handler, { bypassId: key });
1414

15-
suppressed(key, common.mustCall(() => {
15+
bypass(key, common.mustCall(() => {
1616
ch.publish({});
1717
}));
1818

1919
ch.unsubscribe(handler);
2020
}
2121

22-
// Test 2: Non-opted subscriber fires even inside suppressed() scope
22+
// Test 2: Non-opted subscriber fires even inside bypass() scope
2323
{
2424
const key = Symbol('tracer2');
25-
const ch = channel('test-suppression-nonopted');
25+
const ch = channel('test-bypass-nonopted');
2626
const optedHandler = common.mustNotCall();
2727
const regularHandler = common.mustCall();
28-
ch.subscribe(optedHandler, { subscriberId: key });
29-
ch.subscribe(regularHandler); // no suppression
28+
ch.subscribe(optedHandler, { bypassId: key });
29+
ch.subscribe(regularHandler); // no bypass
3030

31-
suppressed(key, common.mustCall(() => {
31+
bypass(key, common.mustCall(() => {
3232
ch.publish({});
3333
}));
3434

3535
ch.unsubscribe(optedHandler);
3636
ch.unsubscribe(regularHandler);
3737
}
3838

39-
// Test 3: Two APMs with different keys don't suppress each other
39+
// Test 3: Two APMs with different keys don't bypass each other
4040
{
4141
const k1 = Symbol('k1');
4242
const k2 = Symbol('k2');
43-
const ch = channel('test-suppression-two-keys');
43+
const ch = channel('test-bypass-two-keys');
4444
let h1Calls = 0;
4545
let h2Calls = 0;
4646
const h1 = common.mustCall(() => { h1Calls++; }, 1);
4747
const h2 = common.mustCall(() => { h2Calls++; }, 1);
48-
ch.subscribe(h1, { subscriberId: k1 });
49-
ch.subscribe(h2, { subscriberId: k2 });
48+
ch.subscribe(h1, { bypassId: k1 });
49+
ch.subscribe(h2, { bypassId: k2 });
5050

51-
suppressed(k1, common.mustCall(() => {
51+
bypass(k1, common.mustCall(() => {
5252
ch.publish({});
5353
}));
5454

5555
assert.strictEqual(h1Calls, 0);
5656
assert.strictEqual(h2Calls, 1);
5757

58-
suppressed(k2, common.mustCall(() => {
58+
bypass(k2, common.mustCall(() => {
5959
ch.publish({});
6060
}));
6161

@@ -66,23 +66,23 @@ const { AsyncLocalStorage } = require('async_hooks');
6666
ch.unsubscribe(h2);
6767
}
6868

69-
// Test 4: Nested suppressed() calls (same key, different keys)
69+
// Test 4: Nested bypass() calls (same key, different keys)
7070
{
7171
const k1 = Symbol('nested1');
7272
const k2 = Symbol('nested2');
73-
const ch = channel('test-suppression-nested');
73+
const ch = channel('test-bypass-nested');
7474
const h1 = common.mustNotCall();
7575
let h2Calls = 0;
7676
const h2 = common.mustCall(() => { h2Calls++; }, 2);
77-
ch.subscribe(h1, { subscriberId: k1 });
78-
ch.subscribe(h2, { subscriberId: k2 });
77+
ch.subscribe(h1, { bypassId: k1 });
78+
ch.subscribe(h2, { bypassId: k2 });
7979

80-
suppressed(k1, common.mustCall(() => {
80+
bypass(k1, common.mustCall(() => {
8181
// Inside k1, h1 skipped, h2 runs
8282
ch.publish({});
8383
assert.strictEqual(h2Calls, 1);
8484

85-
suppressed(k2, common.mustCall(() => {
85+
bypass(k2, common.mustCall(() => {
8686
// Inside both, both skipped
8787
ch.publish({});
8888
assert.strictEqual(h2Calls, 1);
@@ -97,15 +97,15 @@ const { AsyncLocalStorage } = require('async_hooks');
9797
ch.unsubscribe(h2);
9898
}
9999

100-
// Test 5: suppressed() across a Promise boundary
100+
// Test 5: bypass() across a Promise boundary
101101
{
102102
const key = Symbol('promise');
103-
const ch = channel('test-suppression-promise');
103+
const ch = channel('test-bypass-promise');
104104
const handler = common.mustNotCall();
105-
ch.subscribe(handler, { subscriberId: key });
105+
ch.subscribe(handler, { bypassId: key });
106106
const done = common.mustCall();
107107

108-
suppressed(key, common.mustCall(async () => {
108+
bypass(key, common.mustCall(async () => {
109109
await Promise.resolve();
110110
ch.publish({});
111111
})).then(common.mustCall(() => {
@@ -114,15 +114,15 @@ const { AsyncLocalStorage } = require('async_hooks');
114114
}));
115115
}
116116

117-
// Test 6: suppressed() across setImmediate and queueMicrotask
117+
// Test 6: bypass() across setImmediate and queueMicrotask
118118
{
119119
const key = Symbol('timers');
120-
const ch = channel('test-suppression-timers');
120+
const ch = channel('test-bypass-timers');
121121
const handler = common.mustNotCall();
122-
ch.subscribe(handler, { subscriberId: key });
122+
ch.subscribe(handler, { bypassId: key });
123123
const done = common.mustCall();
124124

125-
suppressed(key, common.mustCall(async () => {
125+
bypass(key, common.mustCall(async () => {
126126
await new Promise((resolve) => {
127127
setImmediate(common.mustCall(() => {
128128
ch.publish({});
@@ -139,33 +139,32 @@ const { AsyncLocalStorage } = require('async_hooks');
139139
}));
140140
}
141141

142-
// Test 7: unsubscribe() works correctly after using subscriberId
142+
// Test 7: unsubscribe() works correctly after using bypassId
143143
{
144144
const key = Symbol('unsub');
145-
const ch = channel('test-suppression-unsubscribe');
145+
const ch = channel('test-bypass-unsubscribe');
146146
const handler = common.mustNotCall();
147-
ch.subscribe(handler, { subscriberId: key });
147+
ch.subscribe(handler, { bypassId: key });
148148
ch.unsubscribe(handler);
149149

150150
// Should not throw and should not be called
151-
suppressed(key, common.mustCall(() => {
151+
bypass(key, common.mustCall(() => {
152152
ch.publish({});
153153
}));
154-
155154
}
156155

157-
// Test 8: bindStore with subscriberId is skipped inside suppressed()
156+
// Test 8: bindStore with bypassId is skipped inside bypass()
158157
{
159158
const key = Symbol('store');
160-
const ch = channel('test-suppression-store');
159+
const ch = channel('test-bypass-store');
161160
const als = new AsyncLocalStorage();
162161
const normalAls = new AsyncLocalStorage();
163162

164-
// Normal store - no subscriberId, must always be entered
163+
// Normal store, no bypassId, must always be entered.
165164
ch.bindStore(normalAls, common.mustCall((data) => ({ value: data.value })));
166165

167-
// Bypass store - must NOT be entered inside suppressed()
168-
ch.bindStore(als, common.mustNotCall(), { subscriberId: key });
166+
// Bypass store, must NOT be entered inside bypass().
167+
ch.bindStore(als, common.mustNotCall(), { bypassId: key });
169168

170169
// Handler verifies:
171170
// - normal store WAS entered (normalAls has value)
@@ -176,7 +175,7 @@ const { AsyncLocalStorage } = require('async_hooks');
176175
});
177176
ch.subscribe(handler);
178177

179-
suppressed(key, common.mustCall(() => {
178+
bypass(key, common.mustCall(() => {
180179
ch.runStores({ value: 42 }, common.mustCall());
181180
}));
182181

@@ -185,24 +184,24 @@ const { AsyncLocalStorage } = require('async_hooks');
185184
ch.unbindStore(normalAls);
186185
}
187186

188-
// Test 9: Wrong type for subscriberId throws ERR_INVALID_ARG_TYPE
187+
// Test 9: Wrong type for bypassId throws ERR_INVALID_ARG_TYPE
189188
{
190-
const ch = channel('test-suppression-wrong-type');
189+
const ch = channel('test-bypass-wrong-type');
191190
const bad = 'not-allowed';
192-
assert.throws(() => ch.subscribe(() => {}, { subscriberId: bad }), {
191+
assert.throws(() => ch.subscribe(() => {}, { bypassId: bad }), {
193192
name: 'TypeError'
194193
});
195194
const als = new AsyncLocalStorage();
196-
assert.throws(() => ch.bindStore(als, (d) => d, { subscriberId: bad }), {
195+
assert.throws(() => ch.bindStore(als, (d) => d, { bypassId: bad }), {
197196
name: 'TypeError'
198197
});
199198
}
200199

201-
// Test 10: suppressed() return value passes through fn's return value
200+
// Test 10: bypass() return value passes through fn's return value
202201
{
203202
const key = Symbol('return');
204203
const receiver = { value: 41 };
205-
const result = suppressed(key, common.mustCall(function(a, b) {
204+
const result = bypass(key, common.mustCall(function(a, b) {
206205
assert.strictEqual(this, receiver);
207206
assert.strictEqual(a, 'a');
208207
assert.strictEqual(b, 'b');

0 commit comments

Comments
 (0)