pub struct TracingLayer { /* private fields */ }Expand description
Middleware layer that creates tracing spans for requests
This layer creates a span for each request containing:
- HTTP method
- Request path
- Request ID (if RequestIdLayer is applied)
- Response status code
- Request duration
- Any custom fields configured via
with_field()
§Example
ⓘ
use rustapi_core::middleware::TracingLayer;
RustApi::new()
.layer(TracingLayer::new()
.with_field("service", "my-api")
.with_field("version", "1.0.0"))
.route("/", get(handler))Implementations§
Source§impl TracingLayer
impl TracingLayer
Sourcepub fn new() -> TracingLayer
pub fn new() -> TracingLayer
Create a new TracingLayer with default INFO level
Sourcepub fn with_level(level: Level) -> TracingLayer
pub fn with_level(level: Level) -> TracingLayer
Create a TracingLayer with a specific log level
Sourcepub fn with_field(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> TracingLayer
pub fn with_field( self, key: impl Into<String>, value: impl Into<String>, ) -> TracingLayer
Trait Implementations§
Source§impl Clone for TracingLayer
impl Clone for TracingLayer
Source§fn clone(&self) -> TracingLayer
fn clone(&self) -> TracingLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for TracingLayer
impl Default for TracingLayer
Source§fn default() -> TracingLayer
fn default() -> TracingLayer
Returns the “default value” for a type. Read more
Source§impl MiddlewareLayer for TracingLayer
impl MiddlewareLayer for TracingLayer
Source§fn call(
&self,
req: Request,
next: Arc<dyn Fn(Request) -> Pin<Box<dyn Future<Output = Response<Full<Bytes>>> + Send>> + Sync + Send>,
) -> Pin<Box<dyn Future<Output = Response<Full<Bytes>>> + Send>>
fn call( &self, req: Request, next: Arc<dyn Fn(Request) -> Pin<Box<dyn Future<Output = Response<Full<Bytes>>> + Send>> + Sync + Send>, ) -> Pin<Box<dyn Future<Output = Response<Full<Bytes>>> + Send>>
Apply this middleware to a request, calling
next to continue the chainSource§fn clone_box(&self) -> Box<dyn MiddlewareLayer>
fn clone_box(&self) -> Box<dyn MiddlewareLayer>
Clone this middleware into a boxed trait object
Auto Trait Implementations§
impl Freeze for TracingLayer
impl RefUnwindSafe for TracingLayer
impl Send for TracingLayer
impl Sync for TracingLayer
impl Unpin for TracingLayer
impl UnwindSafe for TracingLayer
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