instrument-for-observability
Logs, metrics and traces that answer the question someone will actually ask at 3am, without logging a secret or a cardinality bomb.
Save as .claude/skills/instrument-for-observability/SKILL.md in a repository, or under ~/.claude/skills/instrument-for-observability/SKILL.md to have it everywhere. The copy button takes the whole file, frontmatter included.
---
name: instrument-for-observability
description: Add logs, metrics and traces that answer the questions someone will actually ask during an incident, without leaking secrets or inflating the bill. Use when asked to add logging, metrics, tracing or monitoring to a service, or to make a system easier to debug in production.
---
# Instrument for observability
Instrumentation exists to answer a question someone will ask at 3am, with the
service failing and no time to read the code. Start from that question, not
from the library.
## Start from the question
1. Write down the questions the person on call will ask. Usually: is it broken
for everyone or for one customer, which dependency is slow, what changed,
and what did this one request do.
2. For each question, name the signal that answers it.
3. Add that and nothing else. Telemetry nobody queries is cost and noise.
## The three signals
- **Metrics** say that something is wrong and how badly. Cheap, aggregated,
and the right thing to alert on. They cannot describe a single request.
- **Traces** say where the time went inside one request, across services.
- **Logs** say what exactly happened in one event. The most detailed and the
most expensive, so the last place to search, not the first.
The metric tells you there is a problem, the trace tells you where, and the
log tells you why. Reaching for a log line to do a metric's job is the common
mistake.
## Order of work
1. Boundary calls first: every outbound HTTP request, database query, queue
publish and cache lookup. Record duration, outcome and target. This is
where the time goes and where most failures start.
2. Entry points next: one record per request with route, status and duration.
3. Carry a request identifier. Accept it from the incoming header or create
it, attach it to every log line, and pass it on every outbound call.
4. Internal logic last, and only where a question from the list needs it.
## Log lines
Write structured fields, not a sentence:
level=error event=payment_declined request_id=8f2c order_id=4471
provider=acme duration_ms=812 reason=card_expired
- Keep the event name a stable constant and put everything variable in
fields. A sentence with values interpolated into it cannot be counted.
- Put the unit in the field name: `duration_ms`, `size_bytes`.
- Reserve the error level for things a person must act on. If errors fire all
day in normal operation, nobody will see the real one.
## Cardinality
Every distinct combination of label values is its own time series, stored and
billed separately. One label holding a user identifier, a request identifier,
an email, a raw URL or an error message creates a series per value. This is
what makes a metrics bill explode, and it usually arrives in one small commit.
- Labels take bounded sets only: the route template rather than the path, the
status class, the region.
- Unbounded values belong in logs and trace attributes.
- Before adding a label, estimate its distinct values and multiply by the
labels already there.
## Secrets and personal data
Never log a password, token, API key, session cookie, authorisation header or
card number, and never log personal data such as an email or an address.
Redact at the point of logging, not later in the pipeline. Once a line leaves
the process it sits in buffers, shippers, indexes and backups that no filter
reaches. The traps are logging a whole request or headers object, logging an
error that embeds the request config, and URLs with a token in the query
string. Log an allow list of named fields, never an entire object.
## One error, one event
An error that is caught, logged and thrown again at three levels of the stack
is one event, not three. Counted three times, it triples the error rate and
buries the real line. Log it once, where it is handled. Lower layers add
context to the error and pass it up without logging.
## What not to do
- **Do not log every function entry and exit** in case it is useful one day.
- **Do not alert on causes.** Alert on what users feel: errors and latency.
- **Do not invent a new field name** for something that already has one. Two
names for the request identifier means a search that finds half the story.
- **Do not ship instrumentation you have not seen arrive** in the backend.
## When to stop
Stop when each question on the list can be answered from a query. Test this by
causing a failure outside production and answering from the telemetry alone.
If you could not watch the data arrive, say so and say what remains untested.
## Report back
1. The questions you instrumented for, and the signal that answers each.
2. What was added, with metric names, labels and log event names.
3. The estimated series count for any new labels.
4. What is redacted, and what you could not verify end to end.what it needs
Nothing. This skill is instructions only, so it works in any agent that reads SKILL.md with nothing installed and no account. Save the file and it is live in the next session.
the instructions, in full
Instrument for observability
Instrumentation exists to answer a question someone will ask at 3am, with the service failing and no time to read the code. Start from that question, not from the library.
Start from the question
- Write down the questions the person on call will ask. Usually: is it broken for everyone or for one customer, which dependency is slow, what changed, and what did this one request do.
- For each question, name the signal that answers it.
- Add that and nothing else. Telemetry nobody queries is cost and noise.
The three signals
- Metrics say that something is wrong and how badly. Cheap, aggregated, and the right thing to alert on. They cannot describe a single request.
- Traces say where the time went inside one request, across services.
- Logs say what exactly happened in one event. The most detailed and the most expensive, so the last place to search, not the first.
The metric tells you there is a problem, the trace tells you where, and the log tells you why. Reaching for a log line to do a metric's job is the common mistake.
Order of work
- Boundary calls first: every outbound HTTP request, database query, queue publish and cache lookup. Record duration, outcome and target. This is where the time goes and where most failures start.
- Entry points next: one record per request with route, status and duration.
- Carry a request identifier. Accept it from the incoming header or create it, attach it to every log line, and pass it on every outbound call.
- Internal logic last, and only where a question from the list needs it.
Log lines
Write structured fields, not a sentence:
level=error event=payment_declined request_id=8f2c order_id=4471
provider=acme duration_ms=812 reason=card_expired
- Keep the event name a stable constant and put everything variable in fields. A sentence with values interpolated into it cannot be counted.
- Put the unit in the field name:
duration_ms,size_bytes. - Reserve the error level for things a person must act on. If errors fire all day in normal operation, nobody will see the real one.
Cardinality
Every distinct combination of label values is its own time series, stored and billed separately. One label holding a user identifier, a request identifier, an email, a raw URL or an error message creates a series per value. This is what makes a metrics bill explode, and it usually arrives in one small commit.
- Labels take bounded sets only: the route template rather than the path, the status class, the region.
- Unbounded values belong in logs and trace attributes.
- Before adding a label, estimate its distinct values and multiply by the labels already there.
Secrets and personal data
Never log a password, token, API key, session cookie, authorisation header or card number, and never log personal data such as an email or an address.
Redact at the point of logging, not later in the pipeline. Once a line leaves the process it sits in buffers, shippers, indexes and backups that no filter reaches. The traps are logging a whole request or headers object, logging an error that embeds the request config, and URLs with a token in the query string. Log an allow list of named fields, never an entire object.
One error, one event
An error that is caught, logged and thrown again at three levels of the stack is one event, not three. Counted three times, it triples the error rate and buries the real line. Log it once, where it is handled. Lower layers add context to the error and pass it up without logging.
What not to do
- Do not log every function entry and exit in case it is useful one day.
- Do not alert on causes. Alert on what users feel: errors and latency.
- Do not invent a new field name for something that already has one. Two names for the request identifier means a search that finds half the story.
- Do not ship instrumentation you have not seen arrive in the backend.
When to stop
Stop when each question on the list can be answered from a query. Test this by causing a failure outside production and answering from the telemetry alone. If you could not watch the data arrive, say so and say what remains untested.
Report back
- The questions you instrumented for, and the signal that answers each.
- What was added, with metric names, labels and log event names.
- The estimated series count for any new labels.
- What is redacted, and what you could not verify end to end.
credit
This skill covers ground first mapped by addyosmani/agent-skills, a widely used open collection of engineering skills. The instructions above are written from scratch for this library, in its own voice and with its own opinions, and nothing is copied. The thanks is for the idea.