1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
//! # Route Formatter
//!
//! Format routes from paths.
/// Interface for formatting routes from paths.
///
/// This crate will render the actix web [match pattern] by default. E.g. for
/// path `/users/123/profile` the route for this span would be
/// `/users/{id}/profile`.
///
/// [match pattern]: actix_web::HttpRequest::match_pattern
///
/// # Custom Formatter Examples
///
/// ```
/// use actix_web_opentelemetry::RouteFormatter;
///
/// // A formatter to ensure all paths are reported as lowercase.
/// #[derive(Debug)]
/// struct MyLowercaseFormatter;
///
/// impl RouteFormatter for MyLowercaseFormatter {
/// fn format(&self, path: &str) -> String {
/// path.to_lowercase()
/// }
/// }
///
/// // now a match with pattern `/USERS/{id}` would be recorded as `/users/{id}`
/// ```
pub trait RouteFormatter: std::fmt::Debug {
/// Function from path to route.
/// e.g. /users/123 -> /users/:id
fn format(&self, path: &str) -> String;
}