agentleFS
saizulsaizul/nodejs-backend-skills/skills/logging-and-tracing/SKILL.md

logging-and-tracing

Skill0 starsChanged 4 days agoMITView on GitHub

Observability for Node.js backends - structured JSON logging with pino / pino-http (levels, child loggers, error serialization, redaction of authorization, cookies, passwords and tokens), request ids reused from x-request-id and propagated with AsyncLocalStorage, and OpenTelemetry basics (NodeSDK loaded with --import before the app, OTLP exporter, sampling, custom spans, trace ids in logs, shutdown). Includes a checker for secrets and req.body in log calls, logger.error('msg', err) that pino drops, err.message-only logging, console.* in server code, hard-coded debug level, pino-pretty in production, missing redact config, missing request ids and late OpenTelemetry initialisation, plus logger.ts and instrumentation.mjs templates and a checklist. Use when the user asks to add or fix logging, structured logs, request/correlation ids, tracing, OpenTelemetry, or to find why logs are missing errors or leak tokens.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. Mushfiqur-Rahman-Robin/coding-rules★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Tracing (optional, recommended for >1 service): Follow references/opentelemetry.md: copy assets/instrumentation.mjs, start with node …

    line 54

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Logging and tracing

Logs that a machine can search, that never contain credentials, and that link every line of one request (and its jobs) together; traces for where the time goes.

Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).

When to use

  • "Add structured logging", "replace console.log", "set up pino"
  • "Our logs contain tokens / passwords", "errors are logged without stack traces"
  • Request ids, correlation ids, "trace a request across services/jobs"
  • "Set up OpenTelemetry", traces are missing spans for Express/pg/Redis

When not to use

  • Error mapping and HTTP error bodies: error-handling-patterns
  • Profiling CPU and latency in depth: api-performance
  • Choosing or operating a log/trace backend (Loki, Elastic, Datadog): out of scope

Workflow

  1. Inventory. Which logger (pino, winston, NestJS Logger, console), which framework, where logs go (stdout -> Docker/journald/k8s), any tracing already.
  2. Run the checker (read-only; skips tests).
    python3 scripts/check_logging.py src
    python3 scripts/check_logging.py src --json --min-severity medium
    Exit 1 = findings at or above --fail-on (default medium).
  3. Fix leaks first. log.sensitive high: remove the field, add redact paths, and tell the user that logs already shipped contain the secret: rotate it and purge or restrict access to the affected log streams.
  4. Fix lost errors. log.pino_error_dropped and log.error_message_only: change to logger.error({ err }, 'what failed'). With winston, use format.errors({ stack: true }).
  5. Standardise the logger from assets/logger.ts (show the diff first):
    • Framework wiring: Express app.use(httpLogger); Fastify built-in Fastify({ logger: { level, redact }, requestIdHeader: 'x-request-id', genReqId }) and request.log; NestJS nestjs-pino LoggerModule.forRoot({ pinoHttp: {...} }); Hono hono/request-id + a pino middleware.
    • LOG_LEVEL env, JSON in production, pretty only in development.
  6. Request ids. Reuse a valid incoming x-request-id, otherwise generate; return it in the response header and error bodies; pass it to outgoing calls and job payloads.
  7. Tracing (optional, recommended for >1 service). Follow references/opentelemetry.md: copy assets/instrumentation.mjs, start with node --import ./instrumentation.mjs dist/server.js, set OTEL_SERVICE_NAME and OTEL_EXPORTER_OTLP_ENDPOINT, verify spans for one request end to end.
  8. Review against the checklist in references/checklist.md and report the items that remain open. Re-run the checker.

Output

Logging review: api (Express 5, pino 9) - 2 high, 3 medium
HIGH  src/auth.ts:41    log.sensitive 'password' in logger.debug -> field removed, redact added
HIGH  src/http.ts:12    req.headers logged -> redact authorization/cookie
MED   src/pay.ts:88     logger.error('charge failed', err) -> logger.error({ err }, 'charge failed')
MED   -                 pino.no_redact -> redact paths added (diff below)

Request ids: x-request-id reused/generated, returned in header and problem bodies.
Tracing: instrumentation.mjs added; start command node --import ./instrumentation.mjs dist/server.js.
Sample line: {"level":30,"time":"2026-11-27T10:00:00.000Z","service":"api","reqId":"6b1e...","orderId":"o_42","msg":"order created"}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.