server agent
Go
The install is explicit — a middleware, a driver wrap, and two lines at the top of the functions worth measuring — because Go has no build step to hook and no way to reach the caller's context without being handed it.
- package
github.com/andana-to/drift/packages/goon Go modules- runs on
- Go 1.22 or later. No dependencies, and none in the go.sum it adds.
- source
- packages/go
Installing it
Any net/http server and any database/sql driver: functions, HTTP routes and SQL. Spans are threaded through context, so the install is explicit rather than automatic.
The install is written as a prompt for the coding agent you already have open, not as a checklist for you. That is deliberate: it names what must be true when the install is finished rather than which files to edit, because where the code goes depends on the framework and putting it in the wrong place fails silently. An agent can read your repository and work that out; a paragraph on a documentation page cannot.
The same text is what install_sixty returns through the MCP server and what the collector serves at /v1/setup?kind=go. There is one copy of it.
the Go install, in full
Install the sixty agent in this Go service so its functions, HTTP routes and
database queries report to sixty.
The package is github.com/andana-to/drift/packages/go, imported as "sixty". It
has no dependencies of its own.
1. In main(), before the server starts:
defer sixty.Init(sixty.Config{}).Shutdown(context.Background())
The zero Config reads the environment. Shutdown sends the last window, so
a short-lived process still reports; on a long-lived server it runs at
exit. If this service already traps signals for graceful shutdown, call
Shutdown there instead of deferring.
2. Wrap the HTTP handler — sixty.Middleware(handler) — at the outermost level,
so the span covers the other middleware rather than sitting inside it.
Anything that speaks net/http works: chi, gorilla/mux, echo, the standard
library's own mux.
If this project uses a router that knows its route patterns, add one more
middleware AFTER routing that calls sixty.SetRoute(r.Context(), pattern) —
chi.RouteContext(r.Context()).RoutePattern(), or the equivalent. Without
it, /users/42/orders is templated to /users/:id/orders, which is close and
occasionally wrong.
3. Measure the database. Replace the sql.Open call with sixty.Open, passing
the same driver name and DSN:
db, err := sixty.Open("pgx", dsn)
If this project builds its pool some other way — a Connector, a pgx pool
through stdlib, a wrapper library — use sixty.WrapDriver(d) around the
driver it registers instead. Postgres is what the detector understands;
another database will report timings and nothing else.
4. Measure the functions worth measuring. This is the step that turns "this
endpoint got slow" into "this function started issuing 14 queries", and
skipping it leaves the feed with routes and queries and nothing between:
func (s *Store) GetUserOrders(ctx context.Context, id int) (_ []Order, err error) {
ctx, span := sixty.Start(ctx, "orders.GetUserOrders")
defer span.Capture(&err)
...
}
Put it on the service or repository layer — the code between the handler
and the database — not on handlers the middleware already covers. Name
operations package.Function, and keep the names stable: the name is the
identity, and renaming one starts its history over.
Do NOT put it on functions called hundreds of thousands of times a second.
A span costs a few hundred nanoseconds, which is nothing next to a request
and everything next to a tight loop.
5. Set these environment variables wherever the service is deployed:
SIXTY_API_KEY = a secret key starting sixty_sk_ — ask me for it. Do not
invent one, and do not commit it.
SIXTY_SERVICE = my-app
SIXTY_ENDPOINT = https://ingest.sixty.sh
The release identifier usually needs nothing: the Go toolchain stamps the
commit into the binary and the agent reads it back. If this builds with
-buildvcs=false, or from a source tarball with no repository, set
SIXTY_RELEASE to the commit SHA — without one, every measurement lands in
a single nameless bucket and no comparison can ever be made.
Constraints — correctness requirements, not style preferences:
- Do NOT change any application behaviour. This is instrumentation only: no
refactors, no reordering of business logic, no "while I was in here" fixes.
- Thread the context. sixty.Start returns a new ctx and the work must use it,
or the queries underneath are recorded as belonging to nobody. There is no
ambient-context version of this and you should not build one: no
goroutine-local storage, no //go:linkname, no global "current span".
- A goroutine started inside a measured function must be passed that ctx if
its work should count towards the operation. One that outlives the request
should NOT be — it would attribute background work to whoever happened to
start it.
- Do NOT add any analytics, user id, session id, or cookie to what is
reported. The agent is deliberately anonymous and must stay that way.
- Leave the sql.Rows handling alone. The agent counts rows as the caller
reads them and closes the span when the rows close, so a query whose rows
are never closed reports late — which is also a connection leak worth
fixing on its own terms.
When you are done, tell me which files you changed and what the deployed start
command now is, so I can confirm data is arriving.It needs a secret key — it starts sixty_sk_ and stays server-side. Mint one on the Settings page once you have signed in.
What it measures
| signal | unit | what it means |
|---|---|---|
rows | rows per call | this query returns more rows than it used to |
fanout | queries per call | this operation now issues more database calls per invocation — an N+1 |
latency | ms per call | this operation takes longer end to end than it used to |
self_latency | ms per call | the time spent in this function itself got longer — its children did not |
payload | bytes per call | the serialized result of this operation got bigger |
errors | error rate | a larger fraction of calls are throwing |
runaway | calls per minute | this operation is being called far more often than anything triggers it |
repeated_query | times per request | the identical query runs several times within one request |
overfetch | rows per call | far more rows are fetched than the code appears to use |
unbounded | rows per call | this query has no upper bound on what it can return |
recursion | levels deep | this operation calls itself, deeper than it should |
new_error | occurrences | an error that did not occur in the previous release |
missing_tenancy | — | This reads a table of per-person data without saying whose rows it wants. Unless your database is filtering it for you, everyone gets everyone else's. |
collapse | — | This is handing back roughly half the data it used to, or less. If that was not deliberate, something is filtering out rows that somebody expects to see. |
vanished | — | It was being used steadily until this release and has not been used once since. Usually the link, button, or redirect that led here stopped working. |
traffic_drop | — | This is still being used, but a fraction as often, and its share of your traffic fell too — so it is not just a quiet period. |
Where it hooks in
- net/http — sixty.Middleware wraps any handler, including the Go 1.22 pattern mux, chi, gorilla and echo.
- Route names — sixty.SetRoute(r, "/orders/{id}") where the router knows the pattern and the path does not.
- Your own functions — ctx, done := sixty.Start(ctx, "orders.List"); defer done() — two lines, and the context has to be threaded through.
Databases
- database/sql — Any driver. The agent wraps the driver rather than the connection, counts rows as the caller iterates them, and mirrors every optional interface the real driver implements.
What only this one does
- One dependency-free module — It adds nothing to go.sum. This gets loaded into other people's production binaries, and a dependency would be a version conflict caused by a monitoring tool.
- Rows counted as they are read — Not from a returned slice — database/sql has none. The span closes when the rows close, so a query whose rows are never closed reports late.
What it cannot do
- The context has to be threaded. A goroutine that is not passed the ctx does its work outside the operation, which is correct for background work and wrong for a fan-out you meant to measure. There is no ambient-context version of this and we will not build one.
- Query plans are not captured.
- CPU and waiting are not split. Goroutines migrate between threads, so a per-thread clock does not describe a span.
Configuration
Every agent reads the same four variables, and DRIFT_* still answers everywhere SIXTY_* does — the product was renamed and that name is not ours to retire from other people’s deployments.
SIXTY_API_KEY | Without it the agent stays inert and says so. It never guesses, never retries against an unknown endpoint, and never throws. |
|---|---|
SIXTY_SERVICE | What to call this service. Defaults to the project name where one is legible. |
SIXTY_RELEASE | The one that matters most. Picked up automatically on Vercel, Render, Railway, Fly, Heroku and GitHub Actions; set it to the commit SHA anywhere else. Without it every measurement lands in a single nameless bucket and no comparison can ever be made. |
SIXTY_ENDPOINT | Where to report. Defaults to http://localhost:4319, which is right on a laptop and wrong the moment the app is served to anyone else. |
The rest — flush interval, sample rate, what to instrument — is in the package’s own README, which is where it can stay true as the agent changes.