Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-diagnostics

@5f83e6c
by jasnelljasnell/node-skills66 stars
1
Run it yourself

Instrumentation, context propagation and profiling added since Node.js 24. Use to instrument a library for APM or OpenTelemetry, propagate request context across async calls, profile one section of code (CPU or heap), capture a heap profile before an out-of-memory crash, find leaked objects, or set a conditional logpoint without editing code. Covers diagnostics_channel boundedChannel and TracingChannel (Stable), built-in channels, AsyncLocalStorage withScope/defaultValue, v8.startCpuProfile/startHeapProfile, setHeapProfileNearHeapLimit, queryObjects, node inspect --probe (--cond, --max-hit) and inspector Network/DOMStorage. Node.js 24+, some 26+.

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-diagnostics

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈168 tokens for metadata: the name and description. ≈953 when used: this file. ≈4.5k more on demand in 6 files.

Description uses 8.4% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈673 characters, or 8.4%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Node.js diagnostics (v24+)

Feature Versions Stability Flag
TracingChannel v19.9.0, v18.19.0 (Stable in v26.8.0) 2 —
boundedChannel, channel.withStoreScope v26.1.0 (not v24) 1 —
als.withScope / RunScope v25.9.0, v24.20.0 1 —
AsyncLocalStorage({ defaultValue, name }) v24.0.0 2 —
v8.startCpuProfile (sync) v25.0.0, v24.12.0 — —
v8.startHeapProfile (sync) v26.1.0 (not v24) 1 —
v8.setHeapProfileNearHeapLimit v26.9.0 (not v24) 1 —
worker.startCpuProfile / .startHeapProfile v24.8.0 / v24.9.0, v22.20.0 2 —
node inspect --probe v26.1.0, v24.16.0; JSON v2 + --max-hit v26.4.0, v24.19.0; --cond v26.6.0, v24.20.0 1 —
inspector DOMStorage.* v25.5.0, v24.16.0 1.1 --experimental-storage-inspection
Built-in channels see rules/diagnostics-channel.md 1 —

Experimental API. Before relying on these details, run the node-experimental-check skill's probe (or node --version plus a feature-detect one-liner) and check the docs for the installed version: https://nodejs.org/docs/<version>/api/<module>.html. If the installed version disagrees with this skill, the installed version wins.

Instrument a library (APM)

import { tracingChannel } from 'node:diagnostics_channel';
const ch = tracingChannel('mylib.db.query'); // once, at module top level
export function query(sql) {
  if (!ch.hasSubscribers) return run(sql);
  return ch.tracePromise(run, { sql }, null, sql);
}
// APM side: ch.start.bindStore(als, (ctx) => span(ctx)); ch.subscribe({...})

Scoped context with using

{ using _ = als.withScope(store); syncWork(); } // restored on exit/throw
{ using _ = ch.withStoreScope(msg); }          // enter bound stores + publish
{ using _ = bounded.withScope(ctx); }          // tracing:<name>:start ... end

Profile a section

const h = v8.startCpuProfile({ sampleInterval: 1 }); hot();
writeFileSync('x.cpuprofile', h.stop()); // JSON string; `using` discards
// worker.startCpuProfile() is async: await handle.stop()

Logpoint without editing code

node inspect --json --probe src/app.js:42 --expr 'user.id' --cond 'user.admin' --max-hit 5 app.js

Pitfalls

  • A using scope opened in an async function before the first await leaks into the caller; use als.run().
  • boundedChannel.run() sets neither ctx.result nor ctx.error. A bound store makes hasSubscribers true.
  • tracePromise (v26+) returns thenables as-is, non-thenables with a warning; v24 wraps both in a Promise.
  • defaultValue applies only when no store was entered; run(undefined)/exit() give undefined.
  • One heap profile at a time. setHeapProfileNearHeapLimit needs an active startHeapProfile().
  • Before v24.20, --cond is rejected with a misleading "Use --" usage error.
  • v8.queryObjects is documented Stable but still warns ExperimentalWarning.

Don't

  • Don't monkey-patch modules or use async_hooks.createHook for tracing: use channels + bindStore.
  • Don't use enterWith() for block scope (withScope()) or console.log edits to inspect values (--probe).

Reference

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    This skill provides technical documentation and examples for Node.js diagnostics and profiling features (v24+). It covers instrumentation, context propagation, and debugging utilities like TracingChannel and AsyncLocalStorage. No security risks were identified.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-diagnostics