Observability
The server can export traces, metrics and logs with OpenTelemetry (OTel). The export is built into Deno, the runtime the server uses. This page covers how to turn it on and where to send the data.
Turn it on
Set OTEL_DENO=true when you start the server. In Docker, set it in the container's environment.
OTEL_DENO=true civ api start
Without it, nothing is exported.
By default the data goes to an OTLP collector at http://localhost:4318. Set OTEL_EXPORTER_OTLP_ENDPOINT to send it somewhere else.
Send data to a collector
Grafana LGTM, for a quick local setup
The LGTM image contains a collector, Prometheus, Tempo, Loki and Grafana in one container.
Start it.
docker run --name lgtm -p 3000:3000 -p 4318:4318 --rm -ti \ docker.io/grafana/otel-lgtm:0.8.1Start the server.
OTEL_DENO=true OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 civ api startOpen http://localhost:3000 and sign in with
admin/admin. Traces are in Tempo, metrics in Prometheus, logs in Loki.
Your own collector
Point the server at any OpenTelemetry Collector. Use OTEL_EXPORTER_OTLP_HEADERS if the collector needs a credential.
OTEL_DENO=true \
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 \
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer my-api-key" \
civ api start
Settings
These environment variables are read by Deno.
| Variable | Default | What it sets |
|---|---|---|
OTEL_DENO |
unset | true turns the export on. |
OTEL_EXPORTER_OTLP_ENDPOINT |
http://localhost:4318 |
The collector's OTLP HTTP address. |
OTEL_EXPORTER_OTLP_PROTOCOL |
http/protobuf |
http/protobuf, http/json or console. |
OTEL_EXPORTER_OTLP_HEADERS |
unset | Headers sent to the collector, for example a credential. |
OTEL_SERVICE_NAME |
<unknown_service> |
The service name shown in traces and metrics. |
OTEL_DENO_CONSOLE |
capture |
What happens to log lines. See Logs. |
OTEL_METRIC_EXPORT_INTERVAL |
60000 |
How often metrics are sent, in milliseconds. |
What is exported
Traces
One span per HTTP request.
| Attribute | Example |
|---|---|
http.request.method |
GET |
url.full |
The full request URL |
url.path |
/admin/users/abc123 |
http.response.status_code |
200 |
http.route |
/admin/users/:id |
The server adds http.route, the route pattern that matched, and uses it as the span name. This lets you group traces by route, not by each separate URL.
Metrics
| Metric | Type | Meaning |
|---|---|---|
http.server.request.duration |
Histogram | Request duration in seconds |
http.server.active_requests |
Gauge | Requests in progress |
http.server.request.body.size |
Histogram | Request body size in bytes |
http.server.response.body.size |
Histogram | Response body size in bytes |
Logs
The server's log lines are exported as OTel log records, linked to the request's span. OTEL_DENO_CONSOLE controls where they go:
| Value | Log lines go to |
|---|---|
capture |
The terminal and the collector |
replace |
The collector only |
ignore |
The terminal only |
See also
- Operations for log rotation
- Deno OpenTelemetry docs
- Grafana LGTM image