# Observability (/docs/operate/observability)



## Logs [#logs]

Logs are **JSON lines on stdout** (pino), one per request with its route pattern, status,
duration, request id and the caller (user, API key, project), plus whatever the worker does.
Every line written inside a request or a delivery carries its `trace_id` and `span_id`.

`LOG_LEVEL` sets the level; probes and scrapes log at `debug`.

## Metrics [#metrics]

Metrics are published in **Prometheus format** on `GET /metrics` (outside `/api`, so the
console's nginx never exposes it; set `METRICS_TOKEN` to require it as a bearer token). The
worker serves its own on `METRICS_PORT`.

What is exposed:

* HTTP requests and latency by route pattern.
* Executions by decision, status, source, environment, experiment arm and result, with engine
  latency.
* `apiCall` calls by host and outcome.
* Outbox and webhook deliveries (sent, retry, dead), with the outbox backlog by status.
* Version-cache hits and misses by layer (`dc_cache_hits_total`, `dc_cache_misses_total`), for
  sizing `VERSION_CACHE_SIZE` and Redis.
* The process defaults.

## Traces [#traces]

Traces use **OpenTelemetry**. A request continues the caller's `traceparent`; the execution is a
`decision.execute` span, and every `apiCall` attempt is a client span whose `traceparent` is
sent to the service called, so its spans join the same trace. The trace id is stored on the
execution, and the outbox keeps the execution's `traceparent`, so a webhook delivered minutes
later is still part of that trace (and carries the header too).

Spans are exported over OTLP/HTTP when `OTEL_EXPORTER_OTLP_ENDPOINT` is set
(`OTEL_SERVICE_NAME`, `OTEL_EXPORTER_OTLP_HEADERS` as usual). Without it, trace ids are still
generated, logged and propagated.

## Benchmarks [#benchmarks]

`bun run bench` (in `apps/api`) drives the execute endpoint with concurrent callers and prints
throughput and p50/p95/p99 latency, audit write included. Published versions are cached in memory
by id (`VERSION_CACHE_SIZE`): they are immutable, so the cache never needs invalidating.

For reference, on a laptop with a local Postgres, `transaction-monitoring` at 16 concurrent
callers: without Redis \~850 req/s, p50 16 ms, p99 48 ms; with Redis \~1,440 req/s, p50 10.5 ms,
p99 24 ms.

The nightly `Nightly benchmark` workflow runs the same benchmark against a freshly seeded API and
fails when p95 or throughput regresses past the tolerance in `apps/api/load/bench-baseline.json`,
so the published figures cannot quietly rot.
