Struct actix_web_opentelemetry::RequestTracing
source · [−]pub struct RequestTracing { /* private fields */ }Expand description
Request tracing middleware.
Examples:
use actix_web::{web, App, HttpServer};
use actix_web_opentelemetry::RequestTracing;
async fn index() -> &'static str {
"Hello world!"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Install an OpenTelemetry trace pipeline.
// Swap for https://docs.rs/opentelemetry-jaeger or other compatible
// exporter to send trace information to your collector.
opentelemetry::sdk::export::trace::stdout::new_pipeline().install_simple();
HttpServer::new(|| {
App::new()
.wrap(RequestTracing::new())
.service(web::resource("/").to(index))
})
.bind("127.0.0.1:8080")?
.run()
.await
}Implementations
sourceimpl RequestTracing
impl RequestTracing
sourcepub fn new() -> RequestTracing
pub fn new() -> RequestTracing
Actix web middleware to trace each request in an OpenTelemetry span.
sourcepub fn with_formatter<T: RouteFormatter + 'static>(route_formatter: T) -> Self
pub fn with_formatter<T: RouteFormatter + 'static>(route_formatter: T) -> Self
Actix web middleware to trace each request in an OpenTelemetry span with formatted routes.
Examples
use actix_web::{web, App, HttpServer};
use actix_web_opentelemetry::{RouteFormatter, RequestTracing};
#[derive(Debug)]
struct MyLowercaseFormatter;
impl RouteFormatter for MyLowercaseFormatter {
fn format(&self, path: &str) -> String {
path.to_lowercase()
}
}
// report /users/{id} as /users/:id
HttpServer::new(move || {
App::new()
.wrap(RequestTracing::with_formatter(MyLowercaseFormatter))
.service(web::resource("/users/{id}").to(|| async { "ok" }))
})
.bind("127.0.0.1:8080")?
.run()
.awaitTrait Implementations
sourceimpl Debug for RequestTracing
impl Debug for RequestTracing
sourceimpl Default for RequestTracing
impl Default for RequestTracing
sourcefn default() -> RequestTracing
fn default() -> RequestTracing
Returns the “default value” for a type. Read more
sourceimpl<S, B> Transform<S, ServiceRequest> for RequestTracingwhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
impl<S, B> Transform<S, ServiceRequest> for RequestTracingwhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
type Transform = RequestTracingMiddleware<S>
type Transform = RequestTracingMiddleware<S>
The
TransformService value created by this factorytype Future = Ready<Result<<RequestTracing as Transform<S, ServiceRequest>>::Transform, <RequestTracing as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<RequestTracing as Transform<S, ServiceRequest>>::Transform, <RequestTracing as Transform<S, ServiceRequest>>::InitError>>
The future response value.
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations
impl !RefUnwindSafe for RequestTracing
impl !Send for RequestTracing
impl !Sync for RequestTracing
impl Unpin for RequestTracing
impl !UnwindSafe for RequestTracing
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more