The best library for recording custom metrics in Datadog using Rust is dogstatsd (https://crates.io/crates/dogstatsd).
The alternative statsd (https://crates.io/crates/statsd) does not allow sending tags. There is even a fork, datadog-statsd (https://crates.io/crates/datadog-statsd), that enables tag sending. However, both define the client without deriving Clone, which prevents using this client as with_state
in Axum, resulting in an error similar to this:
the trait bound `...` is not satisfied
the trait `Clone` is not implemented for `...`rustcClick for full compiler diagnostic
method_routing.rs(168, 16): required by a bound in `post`
....rs(6, 1): consider annotating `...` with `#[derive(Clone)]`: `#[derive(Clone)]
`
the trait bound `...` is not satisfied
the trait `Clone` is not implemented for `...`rustcClick for full compiler diagnostic
method_routing.rs(168, 16): required by a bound in `post`
....rs(6, 1): consider annotating `...` with `#[derive(Clone)]`: `#[derive(Clone)]
`
the trait bound `fn(axum::extract::State<...>, Json<...>) -> impl futures::Future<Output = Result<hyper::Response<axum::body::Body>, AppError>> {...::handler}: Handler<_, _>` is not satisfied
the following other types implement trait `Handler<T, S>`:
`Layered<L, H, T, S>` implements `Handler<T, S>`
`MethodRouter<S>` implements `Handler<(), S>`rustcClick for full compiler diagnostic
....rs(55, 32): required by a bound introduced by this call
method_routing.rs(166, 16): required by a bound in `post`
the trait bound `fn(axum::extract::State<...>, axum::Json<...>) -> impl futures::Future<Output = Result<hyper::Response<axum::body::Body>, ...>> {...}: Handler<_, _>` is not satisfied
the following other types implement trait `Handler<T, S>`:
`Layered<L, H, T, S>` implements `Handler<T, S>`
`MethodRouter<S>` implements `Handler<(), S>`rustcClick for full compiler diagnostic
....rs(55, 32): required by a bound introduced by this call
method_routing.rs(166, 16): required by a bound in `post`
axum::routing::method_routing
pub fn post<H, T, S>(handler: H) -> MethodRouter<S, Infallible>
where
H: Handler<T, S>,
T: 'static,
S: Clone + Send + Sync + 'static,
H = fn handler(State<...>, …) -> …, S = ...