pub struct OtelAxumLayer<P> { /* private fields */ }Expand description
OpenTelemetry layer for Axum applications.
This layer provides automatic tracing instrumentation for Axum web applications, creating spans for HTTP requests with appropriate semantic attributes.
The layer is generic over axum::extract::MatchedPath,
making it compatible with different versions of axum without being tied to any specific one.
§Example
use axum::{Router, routing};
use telemetry_rust::middleware::axum::OtelAxumLayer;
let app: Router = axum::Router::new()
.nest("/api", Router::new()) // api_routes would be your actual routes
.layer(OtelAxumLayer::new(axum::extract::MatchedPath::as_str));Implementations§
Source§impl<P> OtelAxumLayer<P>
impl<P> OtelAxumLayer<P>
Sourcepub fn new(matched_path_as_str: AsStr<P>) -> Self
pub fn new(matched_path_as_str: AsStr<P>) -> Self
Creates a new OpenTelemetry layer for Axum.
§Arguments
matched_path_as_str-axum::extract::MatchedPath::as_stror any function to convertaxum::extract::MatchedPathto a&str
Sourcepub fn filter(self, filter: Filter) -> Self
pub fn filter(self, filter: Filter) -> Self
Sets a filter function to selectively trace requests.
§Arguments
filter- Function that returns true for paths that should be traced
Sourcepub fn inject_context(self, inject_context: bool) -> Self
pub fn inject_context(self, inject_context: bool) -> Self
Configures whether to inject OpenTelemetry context into responses.
§Arguments
inject_context- Whether to inject trace context into response headers
Trait Implementations§
Source§impl<P: Clone> Clone for OtelAxumLayer<P>
impl<P: Clone> Clone for OtelAxumLayer<P>
Source§fn clone(&self) -> OtelAxumLayer<P>
fn clone(&self) -> OtelAxumLayer<P>
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<P: Debug> Debug for OtelAxumLayer<P>
impl<P: Debug> Debug for OtelAxumLayer<P>
Auto Trait Implementations§
impl<P> Freeze for OtelAxumLayer<P>
impl<P> RefUnwindSafe for OtelAxumLayer<P>
impl<P> Send for OtelAxumLayer<P>
impl<P> Sync for OtelAxumLayer<P>
impl<P> Unpin for OtelAxumLayer<P>
impl<P> UnwindSafe for OtelAxumLayer<P>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestCreates a shared type from an unshared type.