Skip to main content

oopsie_core/
tracing.rs

1//! `tracing` integration helpers.
2
3use tracing_error::ErrorLayer;
4use tracing_subscriber::fmt::format;
5use tracing_subscriber::registry::LookupSpan;
6
7/// Construct a `tracing_error::ErrorLayer` configured to format span fields
8/// as JSON.
9///
10/// Equivalent to `ErrorLayer::new(JsonFields::default())` but doesn't require
11/// the caller to depend on `tracing-subscriber` directly.
12#[cfg(feature = "serde")]
13#[inline]
14#[must_use]
15pub fn json_error_layer<S>() -> ErrorLayer<S, format::JsonFields>
16where
17    S: tracing::Subscriber + for<'span> LookupSpan<'span>,
18{
19    ErrorLayer::new(format::JsonFields::default())
20}
21
22/// Construct a `tracing_error::ErrorLayer` configured to format span fields using
23/// the default format (i.e. `Debug`-formatting each field value).
24#[inline]
25#[must_use]
26pub fn default_error_layer<S>() -> ErrorLayer<S, format::DefaultFields>
27where
28    S: tracing::Subscriber + for<'span> LookupSpan<'span>,
29{
30    ErrorLayer::new(format::DefaultFields::new())
31}