pub struct ObservabilityConfig { /* private fields */ }Expand description
Configuration for ObservabilityLayer.
Implementations§
Source§impl ObservabilityConfig
impl ObservabilityConfig
Sourcepub fn with_field_convention(self, convention: FieldConvention) -> Self
pub fn with_field_convention(self, convention: FieldConvention) -> Self
Selects the provider field convention.
Sourcepub const fn with_trace_context_level(self, level: TraceContextLevel) -> Self
pub const fn with_trace_context_level(self, level: TraceContextLevel) -> Self
Selects the W3C Trace Context level used for inbound requests.
Sourcepub const fn trace_context_level(&self) -> TraceContextLevel
pub const fn trace_context_level(&self) -> TraceContextLevel
Returns the resolved W3C Trace Context level.
Sourcepub fn with_request_id_header(self, name: HeaderName) -> Self
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);Sourcepub fn with_response_header(self, enabled: bool) -> Self
pub fn with_response_header(self, enabled: bool) -> Self
Enables or disables adding the request ID response header.
Sourcepub fn with_raw_path(self, enabled: bool) -> Self
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.
Sourcepub fn with_peer_ip(self, enabled: bool) -> Self
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.
Sourcepub fn with_user_agent(self, enabled: bool) -> Self
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.
Sourcepub fn with_request_id_generator(
self,
generator: impl Fn() -> Option<RequestId> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn with_request_id_validator(
self,
validator: impl Fn(&str) -> bool + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn with_status_level_mapper(
self,
mapper: impl Fn(StatusCode) -> Level + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn with_clock(
self,
clock: impl Fn() -> Instant + Send + Sync + 'static,
) -> Self
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".
Sourcepub fn with_access_enricher(
self,
enricher: impl Fn(&RequestContext) -> BTreeMap<String, Value> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn json_layer<W>(&self, writer: W) -> JsonLayer<W>
pub fn json_layer<W>(&self, writer: W) -> JsonLayer<W>
Creates a composable JSON layer using this configuration’s field convention.