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;
use opentelemetry::global;
use opentelemetry_sdk::trace::TracerProvider;
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 = TracerProvider::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,
§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 factory§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 !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