Skip to content

Health and observability

  • API
  • dev dashboard

Health checks

Endpoint Purpose Answers
GET /up liveness — is the process up? always 200 {"status":"ok"}
GET /api/health readiness — can it serve traffic? 200, or 503 when a critical check fails

/api/health runs a registry of checks:

Check Critical?
environment, debug mode, application yes
database (every connection), migrations + River schema yes
cache, queue tables yes
scheduler heartbeat advisory
backups freshness (when enabled) advisory

Advisory checks report problems without making the API unready. Results are cached for 30 seconds so a public endpoint can’t be used to amplify load; ?fresh=1 from loopback forces a run. Load balancers and deploy scripts read the status code, so readiness fails closed.

Terminal window
ims health:check # the same checks from the CLI

The dashboard’s Inspector → System tab shows every check, the runtime (version, Go, uptime) and re-runs them on demand.

Connection pools

The database check also warns (the API stays ready) when a connection pool has 80% or more of its MAX_CONNS in use, before requests start waiting for a connection: the summary reads primary: busy. The public report never shows how many connections are in use. The dashboard does: Inspector → System → Database pools reads every pool live (in use, idle, opening, the maximum, how many requests had to wait and the average time to get a connection), and the Overview shows 3/20 active next to the Database check. Both come from GET /dev/api/inspector/database, which reads the pools from memory without a query.

A pool that is often busy or makes requests wait needs a higher DATABASE_MAX_CONNS (or DATABASE_<NAME>_MAX_CONNS), within the server’s max_connections across every process that connects, or fewer slow queries holding connections.

Maintenance mode

While the app is down for maintenance (ims down), /up and /api/health keep their status codes: the process is healthy, just closed, so load balancers and supervisors neither restart nor drop the servers. /api/health adds a block that monitoring can alert on:

"maintenance": {"down": true, "since": "2026-11-22T02:00:00Z", "message": "Upgrading", "retry_after": 120}

While up it is "maintenance": {"down": false}. The dashboard shows a red Maintenance pill on every page and the toggle on Inspector → System.

Metrics

With METRICS_ENABLED=true, GET /metrics serves a small, dependency-free Prometheus exporter: request counts and latency by method, route pattern and status — low cardinality by design (no ids, no raw paths). Protect it with METRICS_TOKEN (bearer); unset, it answers loopback only.

Tracing (OpenTelemetry)

Traces go out over OTLP to any OpenTelemetry backend: Grafana Tempo, Jaeger, Honeycomb, Datadog, New Relic or an OpenTelemetry Collector. Tracing is off until an endpoint is set. Until then every span is a no-op and costs nothing.

OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 # OTLP/HTTP; set = tracing on
OTEL_EXPORTER_OTLP_HEADERS=x-honeycomb-team=KEY # backend auth, if any

The standard OTEL_* variables apply as the SDK defines them: OTEL_SERVICE_NAME (default APP_NAME), OTEL_RESOURCE_ATTRIBUTES, OTEL_TRACES_SAMPLER (set, it replaces the app’s sampler) and OTEL_SDK_DISABLED. OTEL_TRACES_SAMPLER_ARG on its own sets the app’s ratio. OTEL_ENABLED=true turns tracing on without an endpoint, so the exporter uses its default localhost:4318.

Sampling. By default the app keeps 10% of new traces (parent-based). A traceparent that comes through a trusted proxy (HTTP_TRUSTED_PROXIES) is continued, and is kept when it is sampled. So a trace that starts at your gateway or in another service carries on here. From any other caller the request starts a new trace with a link to the caller’s, so an outside client cannot choose what gets kept. Raise the share with OTEL_TRACES_SAMPLER_ARG=1 while you look into something.

What is traced without any module code:

Span Named Notes
every HTTP request POST /api/v1/branch (the route pattern) user, tenant and impersonator ids; 5xx marks the span failed
SQL db CreateBranch (the sqlc query name) the statement, never its arguments; only inside a trace
queue jobs job webhook.deliver a child of the request that queued it, even on another process; the last failed attempt marks it
scheduled tasks task webhook.prune a failed run marks the span
outbound HTTP POST hooks.example.com webhooks, Twilio SMS, bKash, social sign-in, MCP client metadata, S3/R2/MinIO; passes traceparent on
Redis get, set, eval … (the command) the cache and locks with CACHE_DRIVER=redis, through the official redisotel
mail and delivery delivery.queue, delivery.deliver, mail.smtp_send the template and channel, the SMTP host; never an address
every service write identity.create, billing.approve_payment, privacy.erase … see below
panics an exception event with the stack on the request’s span

One request in Jaeger, with CACHE_DRIVER=redis: the route-named server span, then everything it did, in order and timed. The rate limiter’s Redis set and incrby come first, then the sign-in check (GetToken, GetAuthUser), cache reads, and the handler’s own ListDataProcessingJobs, CountDataProcessingJobs and ListDataProcessingJobActors: 22 spans in 7.6 ms.

A GET /api/v1/data-processing/jobs/user trace in Jaeger: the request span with its Redis commands and SQL queries, 22 spans in 7.6 ms

Open a span to see what it ran. A Redis span carries the command and the code that issued it; a SQL span carries the whole statement (named after its sqlc query) but never the arguments, so no personal data leaves the process. Each span also carries the service, version and environment.

Two spans opened in Jaeger: a Redis incrby with its command, address and calling function, and db GetAuthUser with its full SQL text

Every service write is a span. Each exported write of a module service (create, update, delete, import, erase, sign in, approve a payment, deliver an announcement…) opens one, named <module>.<operation>, so a trace reads request → identity.create → its queries instead of a flat list of queries:

func (s *Service) Create(ctx context.Context, scope tenancy.Scope, actorID int64, input CreateParams) (_ *Branch, err error) {
ctx, end := tracing.Begin(ctx, "branches.create", attribute.Int64("tenant.id", scope.EffectiveTenantID()))
defer end(&err)
…
tracing.Annotate(ctx, attribute.Int64("branch.id", branch.ID)) // known only part way
  • Name <module>.<operation> in snake case: identity.assign_roles, notifications.fan_out. A job’s service span sits under its job <kind> span.
  • Attributes are ids and counts: tenant.id, the target user.id (the actor is already enduser.id on the server span), the entity id, roles, recipients. Never names, e-mail addresses, phone numbers, tokens or payloads.
  • Errors reach the span through the named err and defer end(&err). Every error sets error.type to its apperr code. A failure (a 5xx code, or an error that is not an apperr) also marks the span failed with the stack; a refusal (validation, not found, conflict) does not, the same way a 409 does not fail the request.
  • Reads (Get, List, Count …) open no span: they are one or two queries, already spans. Operations on every request or row (the permission and plan checks, the activity recorder, token checks, progress updates) open none either.

TestServiceWritesOpenASpan (internal/app/service_spans_test.go) keeps it that way: a new service write without tracing.Begin fails the build’s tests, unless it is listed in unspannedOperations with the reason. It reads every module, authn, maintenance mode (maintenance.down, maintenance.up) and the queue admin (queue.retry_job, queue.cancel_job, queue.delete_job, queue.pause, queue.resume). The developer dashboard’s own actions are tooling and are not checked. ims gen module writes services that already comply.

Pass the returned ctx on, so queries and jobs inside the step join it. tracing.Start and tracing.Fail remain for spans that are not one service call.

Here branches.create groups the work of creating a branch under the request: the plan-limit check, the transaction with its advisory lock and count, and the insert. That insert failed (the branch name was taken): the query span is red and followed by the ROLLBACK, and branches.create carries error.type=CONFLICT. The request answered 409: the caller’s mistake, so neither the operation nor the server span is marked failed.

A POST /api/v1/branch trace in Jaeger: branches.create with its queries, a failed insert and the rollback

Logs and traces. While tracing is on, every log line written inside a span also carries trace_id and span_id, the OpenTelemetry ids, so a log search leads to the trace and back. request_id stays as it is. The trace_id of a 5xx problem body is the request id; that is the API’s contract and does not change.

Metrics stay Prometheus (/metrics above). Most teams scrape Prometheus and send traces over OTLP, and both meet in Grafana: the route label on a metric matches the span name.

Local backend. The compose file has an otel profile that runs Jaeger (UI on :16686, OTLP on :4317 and :4318, traces kept in memory):

Terminal window
# everything in containers:
OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318 docker compose --profile otel up -d
# or only Jaeger, with the app running natively (make dev):
docker compose --profile otel up -d jaeger

For make dev, put the endpoint in .env and restart it (settings are read at startup):

OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318
OTEL_TRACES_SAMPLER_ARG=1 # keep every trace while you look

Write 127.0.0.1, not localhost: on Windows localhost resolves to ::1 first, and the Jaeger binary listens on 127.0.0.1 only, so the exporter would drop every trace without an error. The container publishes on both, so 127.0.0.1 works for either.

Open http://localhost:16686 and pick the service ims-go-saas-kit (your APP_NAME). The list shows every request and scheduled task, with failed ones flagged; click one for its timeline. ims about (or the dashboard’s Commands → About) reports whether tracing is on.

Jaeger's search: requests, scheduled tasks and a failed write of the API

No Docker? Jaeger is also a single binary for Linux, macOS and Windows (releases): run jaeger with no arguments for the same setup. On Windows, if it fails with “An attempt was made to access a socket in a way forbidden by its access permissions”, a port it opens is in a range Windows reserves (list them with netsh interface ipv4 show excludedportrange protocol=tcp; the ranges differ from machine to machine). Besides OTLP and the UI it opens the health check on 13132 and 13133 and a Zipkin receiver on 9411. In a copy of Jaeger’s default config, move the health-check ports out of the reserved ranges and remove the Zipkin receiver (the app sends OTLP only), then start it with jaeger --config <file>.

Prefer Grafana? The compose file keeps a commented otel-lgtm service (Grafana with Tempo, Loki and Prometheus in one container, UI on :3000). Use it instead of Jaeger, not beside it: both take ports 4317 and 4318.

Sentry and others. The kit sends nothing to an error tracker. Sentry, Honeycomb and Datadog all accept OTLP, so pointing the endpoint at them is usually enough. A vendor SDK can still be added in internal/platform/tracing.

Logs

Logs are structured (log/slog): text locally, JSON-friendly key/values in production, written to stdout so systemd’s journal collects them (APP_LOG_DIR writes files instead). Every request gets an id (X-Request-ID: a well-formed one from the client is kept, anything else is replaced) that appears in the access log, in every log line of that request, and as trace_id in 5xx problems. An access log line looks roughly like:

level=INFO msg="http request" request_id=01JD… method=POST route=/api/v1/branch status=201 duration=8.4ms user_id=3 tenant_id=1

user_id is who the request ran as. While staff act as a user (X-Acting-User), it is that user, and impersonator_id names the staff member.

Secrets are redacted from logs and captured payloads (tokens, passwords, anything matching DEV_DASHBOARD_REDACT_KEYS).

Telemetry (the dashboard)

When the developer dashboard is enabled, a collector captures — sampled with DEV_DASHBOARD_SAMPLE_RATE, bodies redacted and capped at DEV_DASHBOARD_MAX_BODY_BYTES:

Category What
http requests: method, route, status, timing, headers, bodies; the user, tenant and branch it ran as, and the impersonator when acting as a user
sql queries per request with timing
cache hits, misses, writes
queue jobs enqueued (linked to the request)
logs warn and above
exceptions panics and 5xx with stack

Choose categories with DEV_DASHBOARD_CAPTURE; rows are pruned after DEV_DASHBOARD_RETENTION_DAYS. See the dashboard tour.