# observability-hello

This example documents the observability flow.

```rust
use axum::{Router, middleware, routing::get};
use rs_zero::observability::{
    MetricsRegistry, metrics_router, record_metrics_middleware,
};

let registry = MetricsRegistry::new();
let app = Router::new()
    .route("/ready", get(|| async { "ok" }))
    .merge(metrics_router(registry.clone()))
    .layer(middleware::from_fn_with_state(
        registry,
        record_metrics_middleware,
    ));
```

The metrics middleware records low-cardinality method, matched route, status, in-flight request and duration histogram data. The helper exposes Prometheus text at `/metrics`.

Enable the `otlp` feature when the service needs to export spans to an OpenTelemetry collector. See [Observability 手册](../../docs/manual/observability.md).
