pub struct RequestTracing { /* private fields */ }
Expand description
Request tracing middleware.
§Examples:
use actix_web::{web, App, HttpServer};
use actix_web_opentelemetry::RequestTracing;
use opentelemetry::global;
use opentelemetry_sdk::trace::SdkTracerProvider;
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.
let exporter = opentelemetry_stdout::SpanExporter::default();
// Configure your tracer provider with your exporter(s)
let provider = SdkTracerProvider::builder()
.with_simple_exporter(exporter)
.build();
global::set_tracer_provider(provider);
HttpServer::new(|| {
App::new()
.wrap(RequestTracing::new())
.service(web::resource("/").to(index))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
Implementations§
Source§impl 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()
.await
Trait Implementations§
Source§impl Debug for RequestTracing
impl Debug for RequestTracing
Source§impl Default for RequestTracing
impl Default for RequestTracing
Source§fn default() -> RequestTracing
fn default() -> RequestTracing
Returns the “default value” for a type. Read more
Source§impl<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,
Source§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
Source§type Transform = RequestTracingMiddleware<S>
type Transform = RequestTracingMiddleware<S>
The
TransformService
value created by this factorySource§type 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.
Source§fn 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 Freeze for RequestTracing
impl !RefUnwindSafe for RequestTracing
impl !Send for RequestTracing
impl !Sync for RequestTracing
impl Unpin for RequestTracing
impl !UnwindSafe for RequestTracing
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more