Add the least logging, metrics or tracing that lets someone answer "what happened?" when code breaks in production, at the lowest running cost, in code a junior engineer reads at a glance. Use whenever a change adds or touches an I/O path (HTTP call, database query, queue, file, subprocess, third-party API, background job), when a slice's criteria ask for logs or a correlation ID, when someone asks to add logging, metrics, tracing or monitoring, or when an incident could not be diagnosed from...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Observability?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/restierecon-observability)
---
name: observability
description: Add the least logging, metrics or tracing that lets someone answer "what happened?" when code breaks in production, at the lowest running cost, in code a junior engineer reads at a glance. Use whenever a change adds or touches an I/O path (HTTP call, database query, queue, file, subprocess, third-party API, background job), when a slice's criteria ask for logs or a correlation ID, when someone asks to add logging, metrics, tracing or monitoring, or when an incident could not be diagnosed from the logs.
---
# Observability
Every log line, metric and span runs on every request and is paid for in storage,
CPU and reading time. Add only the signals that answer a question someone will
really ask when this code breaks, using what the project already has. Nothing
more, nothing less.
## 1. Name the questions
Before writing any telemetry, write down one to three questions the person on call
will ask about this code. For example, for a payment call:
- Did the charge for order 42 go through?
- Why do charges fail: the provider, a timeout, or our input?
- Is the provider getting slower?
No question, no telemetry. Every signal you add must answer one of them.
## 2. Use what the project already has
Search the code for the logger, request ID, metrics and tracing setup already in use
(`getLogger`, `logger.`, `pino`, `winston`, `slog`, `structlog`, `request_id`,
`x-request-id`, `prom`, `opentelemetry`). Reuse that logger, its format and its
request ID. Never add a second logger or a telemetry library: a new dependency needs
its one-line justification, and in a TBV project an ADR. If nothing is set up, use
the standard library (Python `logging`, Go `log/slog`, Node `console` with one JSON
object per line).
## 3. Pick the cheapest signal
| Signal | Add it when | Default |
|---|---|---|
| Log event | a question is about one case: "what happened to order 42?" | yes, one per outcome |
| Metric | a question is about rate or latency over time, and the project already exports metrics | no |
| Trace span | the call crosses a process and the project already traces | no: auto-instrumentation usually covers it |
Most changes need one log event per outcome and nothing else. Dashboards and alerts
live outside the code: if a question needs one, name it in your report instead of
building it.
## 4. Write one event per outcome
Log once, where the operation finishes, not on entry and again on exit. Give each
event:
- a stable name: `payment_charge`, `report_export`
- `outcome`: `ok` or `failed`
- the request ID, and the IDs needed to find the record (`order_id`), never the record
- `duration_ms` for anything that waits on I/O
- on failure, the error code or type, not the whole message or a stack trace
Levels: `error` means someone must act; `warn` means handled but degraded (a retry
succeeded, a fallback ran); `info` means a business outcome happened. Commit no
`debug` lines.
```python
import logging
import time
logger = logging.getLogger(__name__)
def charge(order, gateway, request_id):
started = time.monotonic()
try:
receipt = gateway.charge(order.total, timeout=5)
except gateway.Error as error:
logger.error(
"payment_charge outcome=failed request_id=%s order_id=%s error=%s duration_ms=%d",
request_id, order.id, error.code, (time.monotonic() - started) * 1000,
)
raise
logger.info(
"payment_charge outcome=ok request_id=%s order_id=%s duration_ms=%d",
request_id, order.id, (time.monotonic() - started) * 1000,
)
return receipt
```
```typescript
export async function chargeOrder(order: Order, requestId: string): Promise<Receipt> {
const started = performance.now();
try {
const receipt = await gateway.charge(order.total, { timeoutMs: 5000 });
logger.info({ event: "payment_charge", outcome: "ok", requestId, orderId: order.id, durationMs: Math.round(performance.now() - started) });
return receipt;
} catch (error) {
logger.error({ event: "payment_charge", outcome: "failed", requestId, orderId: order.id, error: errorCode(error), durationMs: Math.round(performance.now() - started) });
throw error;
}
}
```
## 5. Keep it cheap
- Nothing inside a loop: log one summary per batch (`count`, `failed`), not one line
per item.
- Pass values as logger arguments, not pre-formatted strings (`%s` with `logging`, an
object with `pino`), so a disabled level costs nothing.
- Log a failure once: at the boundary where it happens, as in the example above, or
where it is handled, never both. Catching, logging and re-raising at every layer
turns one failure into five lines.
- Stack traces only for unexpected errors, once, at the top-level handler.
- Metric labels come from small fixed sets (route template, status class, provider).
Never a user ID, email, URL or error message: each unique value is a new series you
pay for.
- Never log secrets, tokens, passwords, request or response bodies, or personal data.
Log the ID and let the reader look the record up.
## 6. Prove it with a test
Each event a question depends on gets one test that triggers the outcome and checks
the event name and its key fields, not the exact wording. A failure path gets its own
test. In Python, `caplog`:
```python
def test_failed_charge_logs_order_and_error(caplog):
gateway = FailingGateway(code="card_declined")
with pytest.raises(gateway.Error):
charge(Order(id=42, total=100), gateway, request_id="r-1")
assert "payment_charge outcome=failed" in caplog.text
assert "order_id=42" in caplog.text
assert "error=card_declined" in caplog.text
```
## 7. Keep it readable
Call the logger directly where the outcome happens. No comments: the event name says
what happened. No logging decorators, wrappers or helper classes of your own, unless
the project already uses them. A junior engineer should see what is logged by reading
the function.
## In a TBV project
A slice that adds an I/O path carries a criterion like "logs one `<event>` event with
the request ID, outcome and duration" (slice-planning skill). Build exactly that.
Telemetry the slice doesn't need, and gaps you notice elsewhere, go under FLAG
CANDIDATES, not into the diff.
## Never
- Telemetry with no question behind it, or "just in case" logs.
- A new logging, metrics or tracing dependency added to make one change observable.
- Secrets, personal data or full payloads in any signal.
- Unbounded metric labels, or log lines inside loops.
- Comments explaining a log line.