A Caddy that is “working” is not the same as a Caddy you can debug at 3am. The difference is the observability — metrics that quantify the request mix and upstream health, structured logs you can grep, and traces that connect Caddy’s view of the request to the application behind it. This article is the configuration we deploy at clients to turn Caddy from a black box into a queryable, alertable, debuggable component of the stack.
How to verify
A Caddy with observability wired up exposes all three surfaces:
curl -s http://localhost:2019/metrics | head -30
sudo tail -n 5 /var/log/caddy/access.log | jq .
sudo journalctl -u caddy --since '5m ago' | jq -r 'select(.level=="error")'
ss -ltnp | grep :2019
caddy list-modules | grep -i 'metrics\|otel'
The /metrics endpoint exposes Prometheus-format counters and histograms. The access log is one JSON object per line. The journal shows Caddy’s own runtime logs (separate from access logs). The caddy list-modules confirms which observability plugins (OTel exporters, etc.) are compiled in.
What’s happening
Caddy emits three observability surfaces:
-
Metrics. Prometheus format, exposed on the admin port at
/metricsif the global config opts in. Counters and histograms for HTTP requests, responses by status code, request duration buckets, upstream health, certificate state, and storage backend operations. These are the source of pages, dashboards, and capacity reports. -
Logs. Two streams. The access log records each HTTP request (one line per request — JSON by default). The runtime log records Caddy’s own behavior (config reloads, ACME activity, errors). Both can be configured per-site or globally, with multiple sinks per stream.
-
Traces. Via OpenTelemetry, an external plugin. The HTTP server can emit spans for each request, with trace context propagated upstream so the application can join the trace. Useful for distributed debugging — Caddy’s piece of the trace shows the time from accept to upstream first-byte to client first-byte.
The default Caddy install does not enable metrics; you opt in. Logs default to the runtime log only; access logs are off by default. Traces require building Caddy with the OTel module.
The procedure
-
Enable Prometheus metrics. In the global block of the Caddyfile:
{ email ops@example.com servers { metrics } }The
metricsdirective insideserversenables the Prometheus exporter on the admin endpoint. Nowcurl http://localhost:2019/metricsreturns the standard exposition format. -
Configure access logging. Per-site, JSON format, with rotation:
example.com { reverse_proxy localhost:3000 log { output file /var/log/caddy/example.com.access.log { roll_size 100MiB roll_keep 14 roll_keep_for 720h } format json { time_format "iso8601" } level INFO } }roll_sizeis per-file size limit,roll_keepis the number of rotated files retained,roll_keep_foris the age cap. JSON format with iso8601 timestamps is what most log processors want. -
Ship to a central aggregator. Several options:
- Promtail/Loki. The Promtail agent tails
/var/log/caddy/*.log, parses JSON, ships to Loki. Pattern:pipeline_stages: [{ json: { expressions: { status: status, duration: duration } } }]. - Vector. The Vector agent does the same with richer transforms. Same approach — tail, parse JSON, ship.
- Fluent Bit. Lighter weight; tail with parser
json. - Direct journald. Set
output stderrand letjournalctl -u caddycapture; ship the journal upstream.
We typically use Vector or Promtail at clients — both handle JSON natively and back-pressure cleanly.
- Promtail/Loki. The Promtail agent tails
-
Add OpenTelemetry tracing. Build Caddy with the OTel module and the OTLP exporter:
xcaddy build \ --with github.com/caddyserver/caddy-otel \ --output /usr/local/bin/caddyConfigure tracing in the global block:
{ email ops@example.com tracing { span otel } servers { trace } }And the OTel SDK environment variables in the systemd unit:
[Service] Environment=OTEL_EXPORTER_OTLP_ENDPOINT=https://otel-collector.internal:4317 Environment=OTEL_SERVICE_NAME=caddy-edge Environment=OTEL_RESOURCE_ATTRIBUTES=deployment.environment=prodCaddy now emits a span per request, propagates trace context to the upstream via
traceparentheader, and ships spans to your collector. -
The metrics worth alerting on. Not every Prometheus counter deserves a page. The ones we wire up at clients:
caddy_http_requests_total{code=~"5.."}rate — application 5xx rate. Threshold: 1% of total over 5 minutes.caddy_http_request_duration_seconds_bucket— p95 and p99. Threshold: depends on workload SLO.caddy_certificates_renewals_failed_total— any non-zero value is a page. Renewal failures cascade.caddy_storage_io_errors_total— storage backend failures. Any non-zero is a page if you run shared storage.caddy_reverse_proxy_upstreams_healthy— per-upstream gauge. Threshold: < total count over 1 minute.
-
Grafana dashboard starter. The Caddy community maintains a sample dashboard at
grafana.com/grafana/dashboards/14280. Import, set the Prometheus data source, tweak the labels. Customize from there. The base dashboard covers request rate, duration percentiles, status code distribution, and upstream health.
Operational notes
- The
/metricsendpoint shares the admin port. If you change the admin bind from localhost, you have moved your metrics off localhost too — point your Prometheus scrape at the new address, and audit who else can reach it. - The access log can grow fast — a busy edge writes gigabytes per day. The
roll_sizeandroll_keep_forlimits matter. We commonly setroll_size 500MiBandroll_keep_for 168h(one week) plus shipping to long-term storage. - The
format jsonof the access log includes all request headers by default, which can include sensitive values (Authorization, Cookie). Useformat json { fields { request>headers>Authorization delete } }to redact before shipping. - Tracing has overhead. For high-throughput edges, sample —
OTEL_TRACES_SAMPLER=parentbased_traceidratiowith a sample ratio of 0.01 keeps the cost bounded while preserving error-path traces (parent-based sampling captures whatever the upstream samples). - The Caddy runtime log (config reload events, ACME activity) goes to stderr by default, captured by journald. Separate it from access logs — they answer different questions and your aggregator should index them differently.
Stack Harbor wires Caddy into the same observability pipeline as the rest of a client stack — Prometheus scrape, JSON access logs into Loki or Elastic, traces into the existing collector — and we tune the alert thresholds to the actual SLO, not to defaults. If you have a Caddy fleet that runs without the metrics ever being looked at, this is the kind of work covered by our Managed Operations practice.