Skip to main content

ObservabilityConfig

Struct ObservabilityConfig 

Source
pub struct ObservabilityConfig { /* private fields */ }
Expand description

Configuration for ObservabilityLayer.

Implementations§

Source§

impl ObservabilityConfig

Source

pub fn with_field_convention(self, convention: FieldConvention) -> Self

Selects the provider field convention.

Source

pub const fn with_trace_context_level(self, level: TraceContextLevel) -> Self

Selects the W3C Trace Context level used for inbound requests.

Source

pub const fn trace_context_level(&self) -> TraceContextLevel

Returns the resolved W3C Trace Context level.

Source

pub fn with_request_id_header(self, name: HeaderName) -> Self

Sets the request and response correlation header name.

Use HeaderName::from_static for a known lowercase name, or HeaderName::try_from when configuration supplies the value:

use axum::http::HeaderName;
use axum_observability::ObservabilityConfig;

let static_config = ObservabilityConfig::default()
    .with_request_id_header(HeaderName::from_static("x-correlation-id"));
let dynamic_name = HeaderName::try_from("x-runtime-correlation-id")?;
let dynamic_config = ObservabilityConfig::default()
    .with_request_id_header(dynamic_name);
Source

pub fn with_response_header(self, enabled: bool) -> Self

Enables or disables adding the request ID response header.

Source

pub fn with_raw_path(self, enabled: bool) -> Self

Enables or disables exact query-free raw path capture.

Every nonempty path component exposed by Uri::path is retained without applying a second path grammar.

Enabling this can record identifying data and changes the application’s privacy posture. Query strings are never captured.

Source

pub fn with_peer_ip(self, enabled: bool) -> Self

Enables or disables capture of Axum’s trusted socket peer extension.

Enabling this can record identifying data and changes the application’s privacy posture. Forwarding headers are never inspected.

Source

pub fn with_user_agent(self, enabled: bool) -> Self

Enables or disables capture of one unambiguous text User-Agent value.

Enabling this can record identifying data and changes the application’s privacy posture.

Source

pub fn with_request_id_generator( self, generator: impl Fn() -> Option<RequestId> + Send + Sync + 'static, ) -> Self

Sets a fallible request ID generator. It is invoked once per replacement request before the crate falls back to a package-owned random identifier.

Source

pub fn with_request_id_validator( self, validator: impl Fn(&str) -> bool + Send + Sync + 'static, ) -> Self

Adds an application validator for one runtime-valid caller header. Generated identifiers always retain the package’s default grammar.

Source

pub fn with_status_level_mapper( self, mapper: impl Fn(StatusCode) -> Level + Send + Sync + 'static, ) -> Self

Sets the mapping from final response status to access-event level.

Source

pub fn with_clock( self, clock: impl Fn() -> Instant + Send + Sync + 'static, ) -> Self

Sets a monotonic clock seam, primarily for deterministic testing.

Clock panics are contained when the application uses Rust’s default panic = "unwind" behavior. Rust code cannot recover from panic = "abort".

Source

pub fn with_access_enricher( self, enricher: impl Fn(&RequestContext) -> BTreeMap<String, Value> + Send + Sync + 'static, ) -> Self

Adds controlled fields to terminal access records. Reserved package fields cannot be overwritten.

Source

pub fn json_layer<W>(&self, writer: W) -> JsonLayer<W>

Creates a composable JSON layer using this configuration’s field convention.

Trait Implementations§

Source§

impl Clone for ObservabilityConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ObservabilityConfig

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ObservabilityConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more