francoposa / tower-otel-http-metrics

OpenTelemetry HTTP Metrics Middleware Layer for Tower-Compatible Servers (Axum, Hyper)
https://docs.rs/tower-otel-http-metrics/latest/tower_otel_http_metrics
MIT License
8 stars 5 forks source link

endpoint classification? #14

Open flokli opened 1 day ago

flokli commented 1 day ago

Looking at the docs, we currently use a single .layer() call on a axum Router.

That way we however are not able to distinguish individual types of requests.

I'd ideally like to have the counters/histograms provided by this crate on a per-endpoint-of-specific-type granularity.

What do you think about adding an example applying the handler to two separate individual handlers?

We maybe would end up with separate HTTPMetricsLayer instances, and add a method to HTTPMetricsLayerBuilder allowing to add additional (static for the lifetime of HTTPMetricsLayer) fields?

flokli commented 1 day ago

The field to distinguish is probably http.route, as per https://opentelemetry.io/docs/specs/semconv/attributes-registry/http/

Though they explicitly mention this can be just the routes the framework is configured with, meaning we could have out-of-the-box handling for axum::Router.