Skip to main content

Export traces, metrics and logs, and scrape Prometheus

DEVELOPER GUIDE

Send OpenTelemetry traces, metrics and logs to a collector, switch signals off, and enable the Prometheus endpoint.

Who this guide is for

Developers and self-hosters who run Claviger and can set its environment variables.

Why it matters

Telemetry is off until you set a variable, so a default install does nothing extra. A metrics token that is too weak, or sent over plain http, exposes your traffic figures.

What you will do, in one sentence

Set OTEL_EXPORTER_OTLP_ENDPOINT for OTLP export, and set CLAVIGER_METRICS_TOKEN to turn on GET /api/metrics.

Screens are captured from a seeded test system. Every name, address and number on the screens is invented. Prepared 15 November 2026.

1. What is off by default​

With none of the variables below set, no telemetry provider, exporter or background task exists. The only cost left is one check in each request.

Telemetry never depends on a vendor connection string. You choose the collector.

VariableEffect
OTEL_EXPORTER_OTLP_ENDPOINTTurns on OTLP over HTTP for traces, metrics and logs.
OTEL_TRACES_EXPORTER=noneSwitches trace export off.
OTEL_METRICS_EXPORTER=noneSwitches OTLP metric export off.
OTEL_SDK_DISABLED=trueSwitches traces and metrics off.
CLAVIGER_METRICS_TOKENTurns on the Prometheus endpoint GET /api/metrics.

2. Send traces, metrics and logs with OTLP​

Set the endpoint of your collector:

OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.example.org
OTEL_EXPORTER_OTLP_HEADERS=authorization=Bearer%20TOKEN
OTEL_RESOURCE_ATTRIBUTES=service.name=claviger,deployment.environment=prod

OTEL_EXPORTER_OTLP_HEADERS is a list of key=value pairs with URL-encoded values. The standard OTEL_* variables for protocol, timeout, OTEL_SERVICE_NAME and resource attributes apply.

You can also set a signal-specific endpoint, such as OTEL_EXPORTER_OTLP_TRACES_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.

What you get:

  • Traces. One server span for each request, named by the route template. Database queries are child spans that show placeholders only, never bound values. Claviger reads an incoming W3C traceparent header. Health, realtime and metrics requests get no span, but they are still counted.
  • Metrics. Request counts and durations, active requests, database query durations, sign-in attempts, webhook deliveries, captcha checks and realtime subscribers.
  • Logs. Claviger copies its application log to the collector. The built-in log store still keeps its own copy. Set PB_OTEL_MIN_LEVEL to cut what is sent.

The trace sampler is the standard OTEL_TRACES_SAMPLER. The default is parentbased_always_on.

3. Switch one signal off​

Keep the endpoint and turn one signal off:

OTEL_TRACES_EXPORTER=none # no traces
OTEL_METRICS_EXPORTER=none # no OTLP metrics
OTEL_SDK_DISABLED=true # no traces and no metrics

These variables leave the log export alone. Unset the endpoint to stop that too.

4. Scrape with Prometheus​

Prometheus text is served at GET /api/metrics. The route exists only while CLAVIGER_METRICS_TOKEN is set. While it is unset, the path answers 404 like any unknown route.

CLAVIGER_METRICS_TOKEN=$(openssl rand -hex 24)

Send the token as a static Bearer token:

curl https://auth.example.org/api/metrics -H "Authorization: Bearer $CLAVIGER_METRICS_TOKEN"

A missing or wrong token gets 401. Claviger compares the token in constant time.

Treat the token as a secret

The token is a single shared value with no expiry. Store it in your secret manager, scrape over https, and change it by restarting with a new value. The Compose, Fly and Azure templates all accept it as an optional setting.

In Prometheus, set the scrape job with a bearer token:

scrape_configs:
- job_name: claviger
metrics_path: /api/metrics
scheme: https
authorization:
credentials: <the token>
static_configs:
- targets: ["auth.example.org"]

5. Quick reference card​

OTLP on​

  1. Set OTEL_EXPORTER_OTLP_ENDPOINT and, if needed, OTEL_EXPORTER_OTLP_HEADERS.
  2. Restart Claviger.

OTLP signal off​

  1. OTEL_TRACES_EXPORTER=none
  2. OTEL_METRICS_EXPORTER=none
  3. OTEL_SDK_DISABLED=true

Prometheus​

  1. Set CLAVIGER_METRICS_TOKEN.
  2. Scrape GET /api/metrics with Authorization: Bearer <token>.
  3. Unset the token and the route returns 404.

Nothing is exported until you set a variable.