@@ -1112,6 +1112,78 @@ another async task is triggered internally which fails and then the sync part
11121112of the function then throws and error two ` error ` events will be emitted, one
11131113for the sync error and one for the async error.
11141114
1115+ ### USDT probes
1116+
1117+ <!-- YAML
1118+ added: REPLACEME
1119+ -->
1120+
1121+ > Stability: 1 - Experimental
1122+
1123+ Node.js exposes a USDT (User-Level Statically Defined Tracing) probe for
1124+ diagnostics channel publish events, enabling external observability tools
1125+ such as ` bpftrace ` , DTrace, and ` perf ` to trace channel activity without
1126+ modifying application code or adding JavaScript subscribers.
1127+
1128+ #### Probe: ` node:dc__publish `
1129+
1130+ Fired when a message is published to a string-named diagnostics channel.
1131+ When published from native (C++) code and a tracer is attached, the probe
1132+ fires regardless of subscriber state. When published from JavaScript, the
1133+ probe fires only if the channel has active subscribers.
1134+
1135+ * ` arg0 ` {const char\* } The channel name (UTF-8).
1136+ * ` arg1 ` {const void\* } An opaque pointer to the V8 message object, or ` NULL `
1137+ if the published message is not a JavaScript object (e.g., a string, number,
1138+ or ` null ` ). ** Warning:** This pointer is unstable and must NOT be
1139+ dereferenced by tracing scripts. V8's garbage collector may move the
1140+ underlying object at any time. The pointer is valid only for the
1141+ duration of the probe callback and must not be stored or compared
1142+ across separate probe firings.
1143+
1144+ #### Platform support
1145+
1146+ At ` ./configure ` time, Node.js checks for a working ` dtrace ` tool and
1147+ uses ` dtrace -h ` to generate a probe header. Pass ` --without-dtrace ` to
1148+ ` ./configure ` to disable probe support entirely.
1149+
1150+ * ** Linux** : Install the ` systemtap-sdt-dev ` package (Debian/Ubuntu) or
1151+ ` systemtap-sdt-devel ` (Fedora/RHEL) before building Node.js. The
1152+ SystemTap ` dtrace ` wrapper generates a header with semaphore support,
1153+ giving the probe zero overhead when no tracer is attached.
1154+ * ** macOS** : Supported natively via DTrace. The probe instruction is
1155+ patched to a no-op by the kernel when no tracer is attached, but the
1156+ JS-to-C++ call for ` emitPublishProbe ` is still incurred on every
1157+ publish to a string-named channel with subscribers.
1158+ * ** FreeBSD** : Supported natively via DTrace, with the same
1159+ characteristics as macOS.
1160+ * ** illumos/SmartOS** : Supported natively via DTrace, with the same
1161+ characteristics as macOS.
1162+
1163+ If ` dtrace ` is not found but ` <sys/sdt.h> ` is available, the probe falls
1164+ back to always-enabled mode. On platforms where neither is available,
1165+ the probe compiles to a no-op with zero runtime overhead.
1166+
1167+ #### Example: bpftrace (Linux)
1168+
1169+ ``` bash
1170+ sudo bpftrace -e '
1171+ usdt:./out/Release/node:node:dc__publish {
1172+ printf("channel: %s\n", str(arg0));
1173+ }
1174+ ' -c ' ./out/Release/node app.js'
1175+ ```
1176+
1177+ #### Example: DTrace (macOS/FreeBSD)
1178+
1179+ ``` bash
1180+ sudo dtrace -n '
1181+ node*:::dc__publish {
1182+ printf("channel: %s\n", copyinstr(arg0));
1183+ }
1184+ ' -c ' ./out/Release/node app.js'
1185+ ```
1186+
11151187### Built-in Channels
11161188
11171189#### Console
0 commit comments