Repository navigation
Releases
Releases · Flopsstuff/cotel
cotel v0.4.0
Added
- The scheduled health probe watches the database snapshots, not just the process.
scripts/probe-healthz.shfollows a green/healthzwith a second question to/api/v1/health— the only place the snapshot worker's report exists — and goes red (exit 6) onstatus: "error", on alast_run_atolder thanSNAPSHOT_STALE_AFTER_SECONDS(default 43200 s, twoCOTEL_SNAPSHOT_INTERVALperiods at the shipped6h), and on astatus: "ok"whose timestamp is missing or unparseable. The worker could previously die or start failing and nothing would say so until a human opened the endpoint, which is the shape of the failure that already cost six days of blind outage. The claim is deliberately kept off/healthz: that endpoint is the container liveness contract read bycotel --healthcheck, the DockerHEALTHCHECKandscripts/wait-for-healthy.sh, and a failed backup must not mark a working container unhealthy or fail the next deploy — the boundary is checked at the edge and the backup claim lives on the alert path instead.status: "unknown"stays silent by default, because it means both "the worker has not run yet" and "snapshots are disabled", and disabled is the shipped default everywhere but production: a probe reddening on it would lie on every local instance.SNAPSHOT_CHECK=requireis the caller asserting snapshots are expected here and turns that — along with a missingsnapshotfield and an unreadable/api/v1/health— red too;SNAPSHOT_CHECK=offskips the question. The/api/v1/healthaddress is derived from the/healthzURL the probe is already given, so the host wrapper on the Pi needs no edit and the check reaches the timer with the merge. Exit 6 rather than 5, which~/ops/cotel-healthz.shalready spends on "the LAN half is green and the public ingest half is not" (docs/operations/duckdb-snapshots.md, docs/operations/health-probe.md) - cotel snapshots its own database. A worker runs
EXPORT DATABASE ... (FORMAT PARQUET, COMPRESSION ZSTD)at startup and then everyCOTEL_SNAPSHOT_INTERVAL, into one dated directory per snapshot underCOTEL_SNAPSHOT_DIR(/snapshotsin compose, its own volume), keeping theCOTEL_SNAPSHOT_KEEPnewest. It had to be taken from inside cotel: DuckDB has one writer and the live process holds the file lock, so no external process can open the database even read-only. Measured on the production host against a probe copy of the live 152.6 MB database, the export holds the single connection for 0.15-0.3 s and writes 4.2 MiB - 1/35th of the file for a full copy of all six tables - and because it runs on that same connection it cannot race the WAL checkpoint: the two are serialised by construction rather than by a lock. The format is the point: Parquet plus a plain-textschema.sqlis readable by any DuckDB build, and an import rebuilds the secondary indexes from the data, so a snapshot of a database with a damaged ART index - the September 2026 failure, a file whose rows were all readable - restores to a healthy one, where a byte copy of the volume reproduces the damage faithfully.snapshot.jsonis written last and by nothing else, so its presence is the only "complete" signal; it carries the row count per table, read back out of the Parquet files, so a restore is checked against what the snapshot claims rather than trusted. A snapshot is only taken when the newest complete one is older than the interval, so a restart - or a crash loop - cannot spend the retained window on snapshots minutes apart. Pruning keeps the newest N complete snapshots, deletes incomplete ones, runs only after a successful export, and leaves directories whose name is not a snapshot instant alone (ADR-0023, docs/operations/duckdb-snapshots.md) cotel --db-import <dir>restores a snapshot intoCOTEL_DB_PATHand verifies every table against the snapshot's manifest, failing with the table and both numbers named if a count does not match. It needs nothing but the image already on the host - no DuckDB CLI with its version matched by hand, which is the step of the recovery procedure most able to destroy a file. It refuses a target that already holds tables (the snapshot'sschema.sqlissues plainCREATE TABLE, so importing over data would fail halfway and leave a mixed database) and a snapshot with nosnapshot.json. Note that the paths in a snapshot'sload.sqlare absolute, so a snapshot cannot be moved or renamed and still be imported; it must be visible at the path it was written toGET /api/v1/healthreports asnapshotobject (status,last_run_at,last_error,last_dir), and a failed export flips the top-levelstatustodegraded- the same treatment a failing retention roll-up gets, because a backup that has been failing quietly for a month is worse than a known absent one.unknowncovers both a worker that has not run yet and snapshots left disabled, which is the default outside the compose file- The Overview leads with a Span activity grid — a block of cells counting spans, GitHub-contribution-graph style, sitting directly under the KPI row. A line chart answers how much and when; it does not answer what does a week here look like, which is the question a telemetry front door gets asked most. The selected range picks both the grid and how much time one cell is: 53 × 7 day cells over a year (and over
All), 31 × 6 four-hour cells over a month, 24 × 7 hourly cells over a week, 24 × 6 ten-minute cells over a day — each tiling its window exactly, and each about 115 px tall, so switching range does not move the page under the reader. Cells outside the queried window — the leading edge of the lattice, and the rest of today — are drawn as an outline with no fill: an empty cell means "we looked and there was nothing", an outline means "we did not look", and conflating the two is how a heatmap invents a quiet weekend. The grid is placed in UTC, which the footer and every tooltip say. Intensity is cut at the quartiles of the cells in view, not scaled against the busiest one: against a 722-span peak a 200-span day and a 700-span day are both "busy", so a max-relative ramp — linear or log — renders a working week as one flat block of full-intensity cells, which is the difference the grid exists to show. A step therefore means a rank, so the footer names the busiest cell in view and every tooltip gives the cell's own count. The scale lives infrontend/src/lib/heat.tsand is shared with the History page's calendar and hour-of-day heatmaps, which had a private copy of it and pick up the quartile cut with this change (ADR-0016) GET /api/v1/historyaccepts two more bucket widths,granularity=10mandgranularity=4h, so the activity grid asks for exactly the width it draws — one bucket, one cell — instead of re-bucketing an hourly series in the page, which could not have produced a ten-minute cell at all. Both are additive and no existing caller changes; an unrecognised width still falls back todayrather than 400ing. Likehourthey are answered fromspansalone and report the shortfall incovered_since, becausedaily_usagebuckets whole UTC days and cannot produce a sub-day bucket.bucketis now documented as a UTC wall-clock label floored to the width, on any host, so a client can reconstruct it for an instant without asking what the server thinks midnight isscripts/seed-demo.pyfills a throwaway instance with a synthetic team — seven users, three models, 90 days of sessions and tool calls. It goes in over the OTLP endpoint rather than writing to DuckDB, so a seeded instance exercises the same ingest, cost-derivation and roll-up path a real one does, and it sends only attributes Claude Code actually sends: nocommandonBashspans, so the Tools page shows the same "no command detail" state a real install sees. The RNG seed is fixed, so a re-run against a fresh volume reproduces the same numbers.scripts/shoot-screenshots.mjsturns that instance into the README images, each cropped at the bottom edge of a named element rather than at a pixel count (docs/operations/screenshots.md)GET /api/v1/overview,/sessions,/costsand/modelsacceptrange, the same five-key rolling window/usersand/toolsalready took, and each echoes back the key it used. Defaults preserve today's behaviour instead of converging on one value:/overviewand/costsdefault tomonth(the 30-day window they already applied),/sessionsand/modelstoall, because they had no time filter and amonthdefault would silently truncate every existing caller. Long ranges resolve against thespans∪daily_usageunion at the raw-floor split, soyearandallkeep answering after retention has deleted the raw spans rather than repeating themonthfigure. On/costs, explicitfrom/tostill beat the range key and the response then echoes"range": null(ADR-0014)GET /api/v1/sessionsreturnscovered_since. A session row needs a start time, model and status, none of which the roll-up keeps, so the list is raw-only; a range reaching past the raw floor is clamped and the field names the instant the list actually starts from (nullwhen the range is fully covered). The Overview's Sessions block states that window in one line. The session count KPI is unaffected —daily_usagecarriessession_id, so counting distinct sessions across the union is exactGET /api/v1/historyacceptsrangetoo — the last read endpoint that did not. It defaults tomonth, the windowfrom/toalready defaulted to, so a caller that passes no range sees exactly what it saw before; explicitfrom/tostill win and...
cotel v0.3.0
Fixed
- Pricing table now covers the Claude 5 family (Fable 5, Mythos 5, Opus 5, Sonnet 5) and the missing 4.x models (Opus 4.8, Opus 4.6). Spans from
claude-opus-5were previously recorded withcost_usd = 0because the model was absent from the table - Corrected two stale rates: Opus 4.7 ($15.00/$75.00 → $5.00/$25.00) and Haiku 4.5 ($0.80/$4.00 → $1.00/$5.00) per MTok
- Retention roll-up no longer aborts with
NOT NULL constraint failed: daily_usage.modelwhen a span has an empty or NULLmodel,session_id, ortool_name. Such spans are now rolled up under anunknownsentinel instead of silently stopping all aggregation and purging (ADR-0009) - No more silent telemetry loss on restart/deploy: the ingest (
:4318) and dashboard (:8080) ports now bind and accept connections before the DuckDB open (WAL replay + schema migration), which can take minutes on a large production database. During that window both ports answer a retryable503withRetry-Afterinstead of resetting the connection, so OTLP exporters retry and spans are delivered once cotel is ready. Previously the ports bound only after the open finished, so every deploy had a multi-minute window where ingest refused connections and dropped spans - Retention roll-up no longer loses part of a day's usage. The cutoff was a wall-clock instant, so with the worker ticking every 6h (
COTEL_RETENTION_INTERVAL) a day was rolled up in slices; becausedaily_usageis keyed by day and written withINSERT OR REPLACE, each slice overwrote the previous one while its raw spans were already purged. Every day'sspan_count, token totals andtotal_cost_usdwere therefore systematically understated — only the last slice survived. The cutoff is now snapped back to UTC midnight — the same boundary thedaykey is bucketed on — so only whole days are ever rolled up and purged. Trade-off: raw spans now live up to one day longer thanCOTEL_RETENTION_RAW_DAYS(default 30). Aggregates already flattened by the old behaviour cannot be recovered — the raw spans are gone - Retention is now correct on servers that do not run in UTC. A span's
dayis its UTC calendar day, but both retention cutoffs were computed in the server's local zone, so on any host at a non-zero UTC offset — including UTC+1/+2 — the boundary fell inside a day bucket and re-introduced the overwrite above for spans near midnight UTC. Both cutoffs are now computed in UTC, and the retention tests run under a matrix of server timezones so the alignment cannot silently regress - Retention roll-up no longer overwrites an already-rolled-up day's aggregate when a span dated to that day arrives late — a backfill, or an import of telemetry older than
COTEL_RETENTION_RAW_DAYS. The day had already been aggregated and its raw spans purged, so the next cycle recomputed the day from the single late span alone andINSERT OR REPLACEd the correct total away, silently corrupting historical cost. Late spans now accumulate into the existingdaily_usagerow (ON CONFLICT DO UPDATE) instead of replacing it; the accumulate and the raw-span purge run in one transaction so a crash between them cannot double-count - Fast restarts: cotel now runs a DuckDB
CHECKPOINTonSIGTERM/SIGINTbefore exiting, folding the write-ahead log into the main file, and the container entrypoint forwards the stop signal to cotel and waits for it. That multi-minute cold start on a large DB is WAL replay, not the schema migration — previously every deploy killed cotel with a non-empty WAL (the old entrypoint never forwarded the signal and cotel had no handler), so the next start replayed the whole log. Measured on a copy of production (108 MB DB, 6.2 MB WAL): a cold start took 5m38s; after a graceful stop the next start is 0.14s. A hard kill (docker kill, OOM,SIGKILLafter the stop grace period) skips the checkpoint and pays the replay again, but never corrupts the database and loses no committed span — DuckDB replays the WAL on the next open GET /api/v1/bash-commandsreturned an empty list on every request from the day it shipped, so the Tools page's per-command Bash breakdown always looked like "no Bash calls yet". Under the bundled DuckDB engine a baretool_name = 'Bash'predicate is pushed into the table scan and then matches nothing; the query now uses a form the optimizer leaves alone. Onlytool_nameandservice_nameare affected — filters on session, model, user and the id columns were always correct
Added
COTEL_WAL_AUTOCHECKPOINT(default4MB, DuckDB's own default is 16MB) caps how large the write-ahead log grows before DuckDB folds it into the main file. A graceful stop avoids WAL replay entirely; this cap only bounds the replay an ungraceful kill (OOM,SIGKILLafter the grace period) leaves behind, by folding the log — including a retention roll-up's ~6MB of deletes — into the main file promptly. The cost is slightly more frequent checkpoints during ingest, negligible at cotel's write rate- Startup logging of each phase —
opening db,db ready: schema/migrations applied in <duration>, andready: serving live traffic …— so a slow open is visible instead of a silent container. Plus a DockerHEALTHCHECK(cotel -healthcheck, which probes the dashboard/healthz) so the container reportshealth: startinguntil the database is open rather than a misleadingUp; no curl/wget is added to the runtime image daily_usagenow preserves cache-token totals through roll-up: newtotal_cache_read_tokensandtotal_cache_write_tokenscolumns (schema v8) are filled byRollupAndPurgeand carried through/api/v1/exportand import. Previously only input/output tokens survived the roll-up, so aggregates older than the raw-span retention window (default 30 days) undercounted total tokens by ~2 orders of magnitude — in real traffic cache tokens are ~99% of volume. Additive, idempotent migration (ADD COLUMN IF NOT EXISTS); rows rolled up before the migration keepNULL(honestly unknown, not0). Exportformat_versionstays1— additive columns don't bump it (ADR-0005). Cost was already correct (SUM(spans.cost_usd))- Retention worker health on
GET /api/v1/health: aretentionobject (status/last_run_at/last_error); a failed roll-up flips top-level health todegradedand logs atERRORlevel instead of failing silently - Schema migrations are version-guarded on startup:
storage.Openskips the whole ofschema.sqlwhen the database already records the current schema version, so migrations run once (on the deploy that introduces them) rather than on every boot. Measured against a copy of production the apply is ~165 ms, so this is correctness hygiene — the multi-minute open is DuckDB WAL replay, which the guard cannot affect (ADR-0010) - Users page is now one sortable, searchable, paged list carrying per-user cost and session count, scoped by a range switcher (All / Year / Month / Week / Day, default month) that persists in a cookie. Sorting and paging happen in SQL, so "top spender" means top of the whole table for the chosen window rather than top of whatever the browser had loaded. Ranged figures union raw spans with the
daily_usageroll-up, so a window older than the raw-span retention still answers;created_atandlast_seenstay all-time (ADR-0011) - Per-user page at
/users/:id(newGET /api/v1/users/{id}), reached by clicking any row. The token, rotate and delete actions that used to crowd every list row live there - Tools page gains the same contract: ranged call counts, average duration and error rate per tool, server-side sort, search and paging, with the range switcher in the page toolbar. Tool metrics union raw spans with the roll-up; rows aggregated before schema v9 count toward calls but stay out of the duration and failure denominators, and the response names the instant those two figures actually start from.
/api/v1/bash-commandsis raw-only by design and reports the window it covers (ADR-0012) GET /api/v1/usersandGET /api/v1/toolsacceptrange,q,sort,order,pageandlimitand echo the resolved values back. Sort keys are whitelisted,totalcounts matches before paging, andlimit=0returns the unpaginated list the typeahead needsdaily_usagepreserves average duration and failure counts through roll-up (schema v9): new nullabletotal_duration_msandfail_countcolumns, accumulated the same additive, idempotent way as the v8 cache-token migration, so pre-v9 rows stay honestly unknown rather than counting as zero- Sessions and the Overview sessions block show a User column; the Sessions search box filters by user instead of by opaque session ID, and clicking a user filters the table to their sessions
Changed
- The Users page is flat — title, search, range switcher and Add user on one toolbar row above the table, with no card wrapper around a page that holds a single thing
Removed
- The "Cost by user (top 10)" chart on Users and the top-10 chart on Tools. Both ranked a fixed slice on one hardcoded metric; the ranged, sortable lists that replace them answer the same question for any column and any window
- Token display, copy-token and delete from the Users list rows — those actions moved to the per-user page
cotel v0.2.0
Added
- Multi-user telemetry separation — each Claude Code user's data is tracked independently via
user.idresource attribute - Bearer-token authentication: API token creation and management via Tokens page; tokens linked to users in OTLP ingest
- Users page with search, pagination, per-user click-through to filtered analytics, and anonymous user view/delete
- Unified analytics dashboard with per-user filter across all charts and tables
- Setup page with step-by-step onboarding guide and copyable agent configuration prompt
- History page with time-series charts and daily activity heatmaps
- Session Detail: Cache Read and Cache Write KPI cards
- Data export (versioned ZIP/CSV) and import endpoint (
POST /api/v1/import) with migration support - Export/import round-trip integration tests
- Public ingest URL configuration (
COTEL_PUBLIC_INGEST_URL) surfaced on Setup page - Cloudflare Tunnel integration: locally-managed mode with bundled
cloudflaredbinary - Allow-anonymous setting to accept unauthenticated telemetry
- cotel logo mark as SVG favicon and sidebar brand
- GitHub links in header and Setup page
- VitePress documentation site deployed to GitHub Pages
- Manual release workflow with automated CHANGELOG stamping, Docker image push to GHCR, and GitHub Release creation
- Deploy workflow for self-hosted runner on push to main
Fixed
- Sessions were always empty with Claude Code beta telemetry: corrected attribute key mismatch for
tool_nameandcache_creation_tokens - Cost-by-user chart now sorted by cost descending instead of insertion order
- Dashboard costs rounded to 2 decimal places
- Export endpoint returned 401 incorrectly; shared auth middleware extracted and applied consistently
- Session navigation: use React Router instead of
window.locationto avoid full page reloads - Propagate cotel exit code from entrypoint script
- GitHub→Paperclip intake: prevent duplicate issues and ensure backlog landing
Changed
- Legacy server-side rendered dashboard replaced by full React SPA served on all routes
- Settings page merged into Setup as a second tab