Skip to content

OpenTelemetry metrics export

Dwara can export metrics via the OpenTelemetry Protocol (OTLP) to a collector or backend of your choice. This complements the built-in Prometheus-style /metrics endpoint with a push-based export path for environments where scraping is impractical.

When to use this

Use OTLP export when:

  • Your observability backend ingests OTLP natively (Honeycomb, Datadog, New Relic, Grafana Cloud, etc.).
  • You are in an environment where a scrape endpoint is not reachable (e.g. a sidecar in a restricted network).
  • You want traces and metrics in a single pipeline.

Enabling

OTLP export is compiled into the default build (the opentelemetry stack costs ~405 KiB of binary size; the published OSS binaries do not include it). Build the gateway with the feature:

sh
cargo build -p dwara-bin

Set the DWARA_OTLP_ENDPOINT environment variable to enable export. Without it, the OTLP exporter is inert (the feature compiles but does nothing).

sh
export DWARA_OTLP_ENDPOINT=http://otel-collector:4318

The endpoint must be an HTTP URL. Both /v1/metrics and /v1/traces paths are appended automatically.

Exported metrics

The OTLP exporter sends the same metric families as the /metrics endpoint:

MetricTypeDescription
dwara_requests_totalcounterTotal requests processed
dwara_request_duration_secondshistogramRequest latency distribution
dwara_upstream_errors_totalcounterUpstream errors by service
dwara_active_requestsgaugeCurrently in-flight requests
dwara_cache_hits_totalcounterCache hits by route
dwara_cache_misses_totalcounterCache misses by route
dwara_circuit_breaker_stategaugeCircuit breaker state (0=closed, 1=open, 2=half-open)

Labels are config-bounded (no consumer-name labels) to keep cardinality predictable.

Shutdown flush

On graceful shutdown (SIGTERM/SIGINT), the gateway flushes a final metrics export before exiting. This ensures the last batch of counters is delivered to the collector.

Interaction with Prometheus

Both OTLP export and the Prometheus /metrics endpoint can run simultaneously. Use whichever fits your environment; there is no need to choose one.

Runnable demo

Run this feature against a live gateway: demos/09-operations/ (test script: test-04-otlp-export.sh) in the repository. The category README covers prerequisites and teardown.