/last9:go-agent-installfrom last9
Installs Last9 go-agent instrumentation into a Go service with base setup, chi router, and database/sql tracing. Detects stack, shows diff plan, applies edits, and verifies telemetry.
Ships in last9. 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.
None: SKILL.md is the whole skill.
This skill edits the customer's repository. It detects the stack, shows a diff plan, applies minimal edits, promotes the features worth turning on, then verifies telemetry reaches Last9. v1 auto-wires base + chi + database/sql; other frameworks fall back to base + db with the manual snippet.
go-agent is the SDK path — one agent.Start() replaces the OpenTelemetry SDK setup, and each integration is a drop-in replacement for the standard constructor.
Run only inside a Go module. If there is no go.mod at or above the working directory, stop and tell the user this isn't a Go module — there is nothing to instrument.
Read go.mod and the main package. Determine:
require block and the router construction:
github.com/go-chi/chi → chi. Auto-wire it (step 4).DriverName: github.com/lib/pq → postgres, github.com/jackc/pgx → pgx, github.com/go-sql-driver/mysql → mysql, github.com/mattn/go-sqlite3 → sqlite3, modernc.org/sqlite → sqlite.go.opentelemetry.io/... SDK init, an otelgin/otelchi-style middleware, or a prior github.com/last9/go-agent import is present, this is a conflict. Do not double-instrument. Report what you found and stop for user direction.Show the detected stack and the exact edits (as a diff preview) before touching any file. Get one explicit confirmation. A single yes/no — not an interview.
go get github.com/last9/go-agentmain, add the first two lines (and the import):
import agent "github.com/last9/go-agent"
func main() {
agent.Start()
defer agent.Shutdown()
// existing code, unchanged
}
.env; if absent, prompt the user. Never write a token into a tracked file.
OTEL_EXPORTER_OTLP_ENDPOINT="<your last9 otlp endpoint>"
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic <your last9 token>"
OTEL_SERVICE_NAME="<service name>"
chiagent.New() alone does not instrument — Chi captures the route pattern only when the middleware is applied after routes are defined. Always finish with chiagent.Use(r) and serve the handler it returns:
import chiagent "github.com/last9/go-agent/instrumentation/chi"
r := chiagent.New() // or keep an existing chi.NewRouter()
r.Get("/users/{id}", handler) // define ALL routes first
handler := chiagent.Use(r) // REQUIRED — returns the instrumented http.Handler
http.ListenAndServe(":8080", handler)
Without the chiagent.Use(r) call, no server spans are produced. Do not instead call r.Use(...) here — Chi v5 panics when middleware is added after routes.
Replace sql.Open(...) with database.Open(...). Every query gets a span; connection-pool metrics and DSN attributes (host, port, user, db name) come automatically.
import "github.com/last9/go-agent/integrations/database"
db, err := database.Open(database.Config{
DriverName: "postgres", // from detection: postgres | pgx | mysql | sqlite3
DSN: dsn, // reuse the existing DSN expression
DatabaseName: "<db name>",
})
Supported drivers: postgres, pgx, mysql, sqlite, sqlite3. A database.MustOpen panic-on-error variant exists for quick init. GORM: don't replace it — use the official gorm.io/plugin/opentelemetry plugin alongside database.Open for two-layer (ORM span + wire-level SQL span) tracing; go-agent does not wrap GORM.
After the core wiring builds, tell the user what go-agent gives them beyond basic spans, and offer to turn on the opt-in ones. Don't silently enable anything that changes data captured.
Already on, no action — agent.Start() automatically stamps code.* call-site attributes (code.function, code.filepath, code.lineno) onto Client/Producer/Consumer spans, so you see where an outbound call originated. No config, no hot-path cost on Server/Internal spans.
HTTP request/response body capture — the httpcapture middleware records bodies onto the span as http.request.body / http.response.body. Opt-in, off by default. Offer it, with the trade-off: enable only after confirming payloads carry no PII or credentials; for production prefer redacting at the collector. It must run inside the tracing middleware so the span is already active. Canonical wiring (net/http, from go-agent docs):
import (
nethttpagent "github.com/last9/go-agent/instrumentation/nethttp"
"github.com/last9/go-agent/instrumentation/httpcapture"
)
http.ListenAndServe(":8080", nethttpagent.WrapHandler(httpcapture.Middleware(mux)))
Placement differs per framework (for chi, the chiagent.Use(r) span wrapper must stay outermost). Follow go-agent's HTTP Body Capture docs for the framework in use, and verify that http.request.body/http.response.body actually land on a span before relying on it.
export LAST9_BODY_CAPTURE_ENABLED=true # default false
export LAST9_BODY_CAPTURE_MAX_BYTES=4096 # default 8192
export LAST9_BODY_CAPTURE_ON_ERROR_ONLY=true # only status >= 400; no alloc on success
export LAST9_BODY_CAPTURE_CONTENT_TYPES="application/json,application/xml,text/plain" # this is the default
Log-trace correlation — if the app uses log/slog or Uber zap, offer to swap in github.com/last9/go-agent/instrumentation/slog (or the zap equivalent) so trace_id/span_id get injected into log lines — jump from a log straight to its trace.
Mention these; wire the ones the user accepts. Note: don't add per-operation metric instrumentation — Last9 derives RED metrics from spans server-side.
See Verification.
v1 auto-wires chi only. For a detected non-chi framework, wire base + db automatically and hand the user the matching drop-in (each replaces the standard constructor):
| Framework | Drop-in |
|---|---|
| net/http | nethttpagent.NewServeMux() |
| Gin | ginagent.Default() / ginagent.New() |
| Echo | echoagent.New() |
| Gorilla Mux | gorillaagent.NewRouter() |
| gRPC | grpcagent.NewServer() + grpcagent.NewClientDialOption() |
| fasthttp | fasthttpagent.Middleware(handler) |
| Iris | irisagent.New() |
| Beego | beegoagent.New() |
Import path pattern: github.com/last9/go-agent/instrumentation/<framework>. The package name is the bare framework (gin, echo, …), so alias it to avoid colliding with the upstream import — e.g. import ginagent "github.com/last9/go-agent/instrumentation/gin".
These break a naive run. Handle each explicitly; never paper over with a guess:
main, or several main packages (e.g. cmd/api/main.go + cmd/worker/main.go) — agent.Start() goes in the entrypoint that runs the server. If there's more than one, ask which binary to instrument; don't edit all of them.main — the framework constructor may live in a setupRouter() / NewServer() function. Wire it where the router is constructed, not where it's used. Find the construction site before editing.database.Open for a service that has no SQL.database.Config{DSN: ...}. Never inline a hardcoded connection string, and never a password.vendor/ + -mod=vendor) — go get won't update vendored modules; run go mod vendor after adding the dependency, or tell the user to.go get fails (proxy, private module, network) — report the exact error and stop; don't guess a workaround.golangci-lint not installed — say so, fall back to go vet ./..., and report that lint was skipped because the tool is missing. Don't silently skip.This skill mutates the customer's repo. Hold these lines:
go build ./... before editing. If it already fails, report that and stop — don't own pre-existing breakage..env only; never a token in a tracked file.httpcapture without the user explicitly accepting the PII trade-off.go build ./... must pass after the edits.golangci-lint run when a .golangci.y*ml exists.make build / make lint / make test when the Makefile defines them.go vet ./... as a fallback.last9-traces skill to confirm the spans arrive in Last9. agent.Shutdown() flushes on exit, but a blocking server never returns — rely on the batch processor's periodic flush (tunable via OTEL_BSP_SCHEDULE_DELAY) or stop the process cleanly. Use the real run path — not a simulated curl against a mock.
OTEL_EXPORTER_OTLP_ENDPOINT at a local OTLP/HTTP sink (an OpenTelemetry Collector with a debug exporter, or any listener on /v1/traces) and confirm a span appears — same export path, no production token. Seeing a SPAN_KIND_SERVER span named by route pattern (e.g. /users/{id}) confirms the HTTP layer is wired correctly.agent, chiagent, database), or go get/go mod tidy not run.agent.Shutdown() flushed; or no request was sent to an instrumented route.last9-traces — confirm the spans you just produced are landing in Last9.last9-logs — verify log-trace correlation once traces flow.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub last9/ai-toolkit --plugin last96 skills in this plugin
/last9-apiCall the Last9 REST API from the command line with a stdlib Python helper that handles refresh-token exchange, access-token caching, and the X-LAST9-API-TOKEN header. Use when calling the Last9 REST API from scripts, CI, or an agent without the MCP server — exchanging refresh tokens for access tokens, sending change events, querying logs or traces over HTTP, migrating Alertmanager rules ("last9 api", "access token", "refresh token", "change events", "X-LAST9-API-TOKEN")./last9-cloudwatchInvestigate AWS CloudWatch metrics in Last9 with read-only MCP queries. Covers Billing, RDS/Aurora, ElastiCache, MSK, DynamoDB, EC2, SQS, DMS, KMS, and S3. Discover resource metrics, interpret statistics and units, and distinguish sparse data from missing delivery./last9-emit-telemetryOther plugins' skills for the same job