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

Implement `url.scheme` attribute label for Opentelemetry compliance #8

Open francoposa opened 1 month ago

francoposa commented 1 month ago

https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#http-server

Since generally in any modern environment the webserver app is not going to be terminating TLS itself, the spec tells us to lean on the X-Forwarded-Proto and Forwarded headers for the information.

The middleware needs to:

The docs do not explicitly say this but I would assume we should give precedence to Forwarded since it is a real standard, while X-Forwarded-Proto is a "de-facto standard" which seems unlikely to ever be promoted from that status, as Forwarded covers the same info.

Given that this is an HTTP server middleware, we can fall back to http or just splitting it from the URL if it's not present in the headers, as described: Otherwise, the scheme of the immediate peer request.