Adds structured logging with slog, distributed tracing with OpenTelemetry, and Prometheus metrics to Go services. Includes best practices for log levels, sensitive data, and alerting.
Ships in go-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Observability is not optional for production services. Every service must produce
structured logs, expose metrics, and propagate trace context. Use the stdlib
log/slog for logging and OpenTelemetry for tracing and metrics.
Community default. A project skill or agent-config rule that explicitly supersedes
go-observabilitytakes precedence over this one.
Detailed reference material, loaded on demand:
references/slog.md — handler setup, logger injection, child loggers,
LogValuer redaction, trace-ID handler, hot paths, runtime levels.references/tracing.md — tracer provider, spans, propagation, sampling,
profile labels, shutdown.references/metrics.md — metric definitions, HTTP instrumentation.references/alerting.md — RED/USE, histograms vs summaries, burn-rate
alerts, alert hygiene, exemplars.Read a reference file only when the section below is not enough.
Use log/slog (Go 1.21+) with a JSON handler in production. Every line is
key-value pairs, never a formatted sentence:
// ✅ Good — structured, leveled
logger.Info("user created", slog.String("user_id", user.ID), slog.Duration("latency", elapsed))
// ❌ Bad — unparseable in production
log.Printf("user %s created in %v", user.ID, elapsed)
Inject the logger as a dependency; never reach for a package-level global.
Derive child loggers with logger.With(...) so component, method and request
ID are attached once instead of at every call site. See references/slog.md.
| Level | Use for |
|---|---|
Debug | Verbose diagnostic info, disabled in production |
Info | Normal operations: request received, job completed |
Warn | Recoverable issues: retry succeeded, deprecated usage |
Error | Failures requiring attention: DB down, external call failed |
NEVER log at Error level for expected conditions (user not found → Info or Warn).
// ✅ Good — an opaque internal ID, no personal data
logger.Info("auth attempt", slog.String("user_id", userID), slog.Bool("success", ok))
// ❌ Bad — leaks a credential and a personal identifier
logger.Info("auth attempt", slog.String("password", password))
logger.Info("auth attempt", slog.String("user", email))
Log the stable internal ID and join to personal data in the system that is allowed to hold it. Log retention, search access and third-party log sinks rarely meet the bar that applies to the user table.
Make redaction a property of the type: implement slog.LogValuer on
secrets and on structs that hold personal data, so slog.Any(user) logs
only the safe fields everywhere.
logger.LogAttrs and guard expensive attributes with
logger.Enabled.slog.LevelVar in HandlerOptions lets the level change at run time
without a deploy.slog.NewMultiHandler (Go 1.26+) fans out to several handlers.Start a span for every operation worth seeing on a waterfall — inbound
requests, DB calls, outbound HTTP, meaningful business steps — and always
defer span.End().
Rules the reference examples follow:
GetUser, db.query), never after the
fully-qualified function, and never doStuff.span.RecordError(err) and span.SetStatus(codes.Error, ...),
or the trace shows a green span for a failed request.ctx down the whole chain. A context.Background() mid-chain silently
starts a new trace and breaks the parent link.ParentBased(TraceIDRatioBased(r)) so services agree on a
trace; keep errors and slow requests with tail sampling in the collector.pprof.Labels (route, tenant tier) to split a hot function.Setup and examples in references/tracing.md.
| Type | Use for | Example |
|---|---|---|
| Counter | Monotonically increasing values | Requests total, errors total |
| Gauge | Values that go up and down | Active connections, queue depth |
| Histogram | Distribution of values | Request latency, response size |
Naming is <namespace>_<subsystem>_<name>_<unit>:
http_request_duration_seconds ✅ (unit in name)
http_requests_total ✅ (counter with _total suffix)
db_connections_active ✅ (gauge, no suffix needed)
user_signups ❌ (missing _total for counter)
requestLatency ❌ (camelCase, no unit)
Keep cardinality bounded. Label with the route pattern, method and status —
never a user ID, request ID or raw r.URL.Path, each of which mints a new
time series per value and eventually takes the metrics backend down.
Definitions and middleware in references/metrics.md.
A log line without a trace ID cannot be joined to the request that produced
it. Wrap the handler once so every *Context log call adds trace_id and
span_id from ctx — the wrapper must also override WithAttrs and
WithGroup, or child loggers lose it. Attach exemplars (trace IDs) to
latency histograms to jump from a p99 spike to an offending trace.
rate() not irate(); absent() for
series that must exist; a runbook link on every page.Queries and exemplar wiring: references/alerting.md.
The batch span processor holds spans in memory. Call tp.Shutdown(ctx) with
its own timeout on the way out, or the last seconds before a crash — the
interesting ones — never reach the collector.
Both examples in references/tracing.md.
log/slog with structured key-value pairs, not fmt.Printf or log.Printfcontext.Contextspan.RecordError(err) and set error status_seconds, _total, _bytesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/go-agent-skills:go-observabilityfrom go-agent-skills
npx claudepluginhub eduardo-sl/go-agent-skills --plugin go-agent-skills35 skills in this plugin
/git-commitStructured git commit messages following Conventional Commits format for Go projects. Generates well-scoped, atomic commits with clear descriptions. Use when committing changes, writing commit messages, preparing PRs, or reviewing commit history quality. Trigger examples: "commit these changes", "create commit", "commit message", "prepare PR", "squash commits". Not for: code review (go-code-review), changelog generation.
/go-api-designHTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and graceful shutdown. Use when designing APIs, writing HTTP handlers, implementing middleware, or structuring REST endpoints. Trigger examples: "design API", "REST endpoints", "HTTP handler", "middleware pattern", "graceful shutdown", "API versioning". Not for: gRPC services (go-grpc), spec-first OpenAPI work (go-openapi), general architecture (go-architecture-review), concurrency in handlers (go-concurrency-review).
/go-architecture-reviewReview Go project architecture: package structure, dependency direction, layering, separation of concerns, domain modeling, and module boundaries. Use when reviewing architecture, designing package layout, evaluating dependency graphs, or refactoring monoliths into modules. Trigger examples: "review architecture", "package structure", "project layout", "dependency direction", "clean architecture Go", "module boundaries". Not for: code-level style (go-coding-standards), endpoint design (go-api-design).
Other plugins' skills for the same job