instrument-service
Skill1 starsChanged 2 months agoMITView on GitHub
Add tracing, metrics, and structured logs to a service using OpenTelemetry and the LGTM stack (Loki, Grafana, Tempo, Mimir) — spans on the real boundaries, RED metrics, log discipline, and the rule that observability init must degrade, never crash. Use when a service has poor visibility, when adding OTEL, or when asked to "instrument this" / "add tracing / metrics".
In this repository73 other files it gives its agents.
- AGENTS.mdAGENTS.md
- bigquery-analyticsSkill
- cache-invalidationSkill
- mongo-aggregationSkill
- mongo-modelingSkill
- postgres-aggregationSkill
- postgres-indexingSkill
- redis-coordinationSkill
- redis-patternsSkill
- review-querySkill
- code-migrationSkill
- cut-releaseSkill
- data-migrationSkill
- deploy-serviceSkill
- hotfixSkill
- rollbackSkill
- design-endpointSkill
- design-eventSkill
- design-schemaSkill
- evolve-contractSkill
- scaffold-nestjs-moduleSkill
- scaffold-projectSkill
- incident-responseSkill
- investigate-bugSkill
- on-callSkill
- postmortemSkill
- audit-skillsSkill
- distill-review-styleSkill
- write-skillSkill
- debug-with-tracesSkill
- define-alertsSkill
- evaluate-dependencySkill
- grillSkill
- handoffSkill
- orientSkill
- phased-deliverySkill
- spikeSkill
- to-questionnaireSkill
- write-adrSkill
- write-prdSkill
- devops-pr-reviewSkill
- go-backend-pr-reviewSkill
- nestjs-backend-pr-reviewSkill
- python-backend-pr-reviewSkill
- react-frontend-pr-reviewSkill
- bisectSkill
- break-couplingSkill
- dead-code-sweepSkill
- deslopifySkill
- extract-moduleSkill
- rebase-cleanSkill
- resolve-merge-conflictsSkill
- split-commitSkill
- tddSkill
- wait-whatSkill
- wide-renameSkill
- bullmqSkill
- kafkaSkill
- sqs-consumerSkill
- audit-dependenciesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
If you genuinely want loud-fail, fine — but then it's not "optional", pick one stance and be consistent.
- Very specific: line 51
No manual [module] / [method] prefixes if the framework adds them.
- Very specific: line 52
Never log full headers / request body / Authorization / cookies / the OTP.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
Instrument a service
Reference stack: OTEL SDK → OTLP → Tempo (traces), Mimir/Prometheus
(metrics), Loki (logs), Grafana (view). Matches the ember template.
The non-negotiable rule
Observability is optional infrastructure, never a hard startup dependency.
- OTEL / metrics / tracing init failing must not take the service down.
log.Fatalfon OTEL init → fall back to a no-op provider and start anyway. - Exporter endpoint down → buffer and drop, don't block requests.
- If you genuinely want loud-fail, fine — but then it's not "optional", pick one stance and be consistent.
Traces
- Span the real boundaries: inbound request, outbound HTTP/gRPC, DB query, cache call, queue publish/consume, expensive compute. Not every function.
- Span names are low-cardinality and stable —
GET /users/:id, not the interpolated path. A 404 that returns""for the route → span name becomes"GET "; add a fallback. - Attributes:
user.id,tenant.id,queue.name, result codes — enough to filter in Tempo. Never secrets or PII. - Propagate context — thread
context.Context/ the active span through every call so the trace isn't broken. A new blocking call that ignores ctx also can't be cancelled. - Errors — record the exception on the span, set status
ERROR.
Metrics (RED, per endpoint / consumer)
- Rate — requests/sec (
http_server_requests_total). - Errors — error count / ratio.
- Duration — a histogram (
_secondsbuckets) for p50/p95/p99, not just a mean. - Plus: queue depth / lag, cache hit ratio, DB pool in-use, in-flight requests.
- Low-cardinality labels only — no user IDs, no unbounded paths, no request IDs as labels.
Logs
- Structured (JSON), one event per line, correlated with the trace
(
trace_id/span_idin every line). info/warn/errorin prod —debugis invisible there, so anything you need during an incident must beinfo+. No per-iterationdebuglogs in bulk loops.- No manual
[module]/[method]prefixes if the framework adds them. - Never log full
headers/ requestbody/Authorization/ cookies / the OTP. error.stack, notJSON.stringify(error)(which serializes to{}).
Verify
- A request produces one connected trace across all hops in Tempo.
- The RED metrics show in Grafana; the histogram gives real percentiles.
- Killing the collector doesn't kill the service.
- Graceful shutdown flushes the exporter.
Anti-patterns
- ❌
Fatalf/ crash on telemetry init. - ❌ A span per function; high-cardinality span names.
- ❌ User IDs / paths as metric labels.
- ❌
debuglogs for something you'd need in an incident. - ❌ Broken traces because
contextisn't propagated.
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
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.

