Skip to content

feat(leadline): a box-side helper that records what code did in development - #54

Merged
sean-brydon merged 1 commit into
mainfrom
feat/leadline-helper
Oct 11, 2026
Merged

sean-brydon merged 1 commit into
mainfrom
feat/leadline-helper

Conversation

@sean-brydon

Copy link
Copy Markdown
Collaborator

What this is

berth-leadline: Leadline's collector, ported into this repo as a standalone program that runs on a box next to a dev server. It records every database query by shape (with N+1 detection), request traces and logs, and serves them as JSON on loopback. Nothing user-visible yet: berthd does not install or start it, and the UI is a separate change.

berthd and berth are untouched: go list -deps ./cmd/berthd ./cmd/berth | grep leadline prints nothing, and the agent that built this found both binaries byte-for-byte identical before and after.

What's in it

  • cmd/berth-leadline (serve, version) and internal/leadline/…; make leadline builds linux and darwin, amd64 and arm64, with CGO_ENABLED=0 (about 15 MB stripped).
  • Ported closely from Leadline: the Postgres wire proxy, OTLP intake and SQL fingerprinting, the linker that pairs an app's spans with the proxy's so a query is counted once, and their tests.
  • Reimplemented: the store, on pure-Go SQLite instead of DuckDB (which needs cgo). Retention is 72 hours and a size cap, as in Leadline.
  • internal/leadline/API.md: all 22 routes with parameters and real responses; a test fails if a served route is missing from it, or the reverse.
  • An attach helper (standard library only) that gives a worktree's dev server the OpenTelemetry settings and a DATABASE_URL through the proxy. Not wired into berthd.

Left out on purpose: metrics, Redis, connect-a-database statistics, the MCP server, briefs, the desktop app, discovery and leadline run. Also not ported: stdout-to-logs capture, so an app with no OpenTelemetry SDK shows queries but no logs.

How it was checked

By the agent that built it: gofmt, go vet ./..., go test -race ./..., both linux cross-builds, an end-to-end test (helper on port 0, OTLP in, statements through the proxy to a fake Postgres, read back through the API, asserting 5 calls not 10, the N+1 flag, the span tree and a restart), the real-server proxy tests against a throwaway Postgres 17 container, and the static arm64 binary in a bare Alpine container.

Re-run by me after rebasing onto main: go vet and go test -race ./internal/leadline/..., both linux cross-builds, the dependency check, and a live smoke test on a spare port (health, sources, 403 for a non-loopback Host, 403 for a POST from a foreign Origin, files 0600). I did not read all 18,000 lines.

Open before berthd runs it

  • The API has no authentication, as in Leadline: another user on a shared box could read it on the port.
  • The proxy sits in the database path, so berthd must only rewrite a DATABASE_URL while the helper is up.
  • Wide time windows scan every row; a day over 400,000 spans takes about a second.

🤖 Generated with Claude Code

…opment

berth-leadline is Leadline's collector as a standalone helper for a box:
it takes OpenTelemetry traces and logs over OTLP/HTTP, records Postgres
statements through a loopback proxy, keeps both in one SQLite file, and
answers a JSON API on localhost. Queries are grouped by shape with call
counts, timings and an N+1 flag with the requests that show it; a trace
opens as a span tree with its SQL and its logs; logs are searched; each
route has its requests, latency, queries per request and database time. A
statement the app and the proxy both report is counted once.

Nothing installs or supervises it yet, and it is in no release: berthd
and berth do not import it, and their builds are byte for byte what they
were.

- cmd/berth-leadline: serve and version.
- internal/leadline: the attach helper the box daemon will use (the
  environment a dev server needs, and its database URL through the proxy).
  Standard library only.
- internal/leadline/pgproxy, ingest: Leadline's, with their tests.
- internal/leadline/store: Leadline's store rebuilt on SQLite
  (modernc.org/sqlite, no cgo), with its linker; kept for 72 hours and
  under 2 GB by default.
- internal/leadline/capture, api, helper: the proxies, the HTTP API and
  the helper put together.
- internal/leadline/API.md: every route, with real responses.
- make leadline builds it for linux and darwin, amd64 and arm64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
berth Ready Ready Preview Oct 11, 2026 9:57pm UTC
berth-docs Ready Ready Preview Oct 11, 2026 9:57pm UTC

Request Review

@sean-brydon
sean-brydon merged commit 05798be into main Oct 11, 2026
7 of 8 checks passed
@linear-code

linear-code Bot commented Oct 11, 2026

Copy link
Copy Markdown

ENG-5893

This branch was successfully deployed

2 active deployments
Preview – berth-docs — 405882ad Deployed Oct 11, 2026 by vercel[bot]
Preview – berth — 405882ad Deployed Oct 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant