skills/observability-and-instrumentation/SKILL.md
Use when shipping any feature that runs in production. Use when adding logging, metrics, tracing, or alerting. Use when production issues are reported but you can't tell what happened from the available data.
npx skillsauth add paulund/skills observability-and-instrumentationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Define on-call questions first — before adding any instrumentation, write down 2–4 questions an engineer will ask about this feature when it breaks:
FEATURE: checkout payment retry
QUESTIONS ON-CALL WILL ASK:
1. What fraction of payments succeed on first attempt vs after retry?
2. When a payment fails permanently, why? (provider error? timeout? validation?)
3. Is the payment provider slower than usual?
→ Every signal below must help answer one of these.
If you can't name the questions, you're not ready to instrument — you'll log everything and learn nothing.
Pick the right signal for each question:
| Signal | Answers | Example |
|---|---|---|
| Structured log | "What happened in this specific case?" | payment_failed with provider error code + attempt count |
| Metric | "How often / how fast in aggregate?" | p99 latency histogram of provider calls |
| Trace | "Where did time go across services?" | One slow checkout broken down by hop |
Structured logs — log events not prose. Every log line is a JSON object with a stable event name and machine-readable fields. Attach a requestId to every line. Use consistent log levels: error (someone may need to act), warn (degraded but handled), info (significant business event), debug (off in production by default). Never log secrets, tokens, passwords, or full PII.
RED metrics on every endpoint and external dependency — Rate (requests/sec), Errors (failure rate), Duration (latency histogram, p95/p99 — never averages). Labels must come from small fixed sets; never use user IDs, raw URLs, or error message text as labels (cardinality bomb).
Alert on symptoms users feel, not infrastructure causes:
Verify the telemetry before shipping — trigger the path in staging, find the log line by requestId, confirm metric series appear with correct labels, follow one trace end-to-end without broken spans.
| Rationalization | Reality |
|---|---|
| "I'll add logging after it works" | "After" becomes "after the first incident" — the most expensive moment to discover you're blind. |
| "More logs = more observability" | Unstructured noise makes incidents slower. Three queryable events beat three hundred prose lines. |
| "console.log is fine for now" | Unstructured output can't be filtered, correlated, or alerted on. |
| "Alert on everything important, we'll tune later" | A noisy pager trains people to ignore it. The tuning never happens; the missed real alert does. |
requestId/correlationId to every log line.console.log calls in production code paths.development
Use when implementing any logic, fixing any bug, or changing any behaviour. Use when you need to prove code works, when a bug report arrives, or when modifying existing functionality. Do NOT use for config changes, data migrations, or dependency updates.
development
Use when starting a new feature, when requirements are unclear, when asked to write code without a clear spec, or before any non-trivial implementation. Do NOT use for trivial bug fixes or one-line changes.
development
Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters. Detects the stack from dependency files, fetches official documentation, implements following documented patterns, and cites sources for every framework-specific decision.
development
Use when preparing to ship a feature, release, or deployment. Use before merging to main, creating a release, or deploying to production. Do NOT use for CI-only changes or internal refactors that don't reach production.