agentleFS
tejastn10tejastn10/workbench/skills/observability/instrument-service/SKILL.md

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".

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
  1. Distinctive:

    If you genuinely want loud-fail, fine — but then it's not "optional", pick one stance and be consistent.

    line 18
  2. Very specific:

    No manual [module] / [method] prefixes if the framework adds them.

    line 51
  3. Very specific:

    Never log full headers / request body / Authorization / cookies / the OTP.

    line 52

≈ “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.

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

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.Fatalf on 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 (_seconds buckets) 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_id in every line).
  • info / warn / error in prod — debug is invisible there, so anything you need during an incident must be info+. No per-iteration debug logs in bulk loops.
  • No manual [module] / [method] prefixes if the framework adds them.
  • Never log full headers / request body / Authorization / cookies / the OTP.
  • error.stack, not JSON.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.
  • ❌ debug logs for something you'd need in an incident.
  • ❌ Broken traces because context isn't propagated.

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.