
# 0.2.4 (April 6, 2020) This release includes several API ergonomics improvements, including shorthand constructors for many types, and an extension trait for initializing subscribers using method-chaining style. Additionally, several bugs in less commonly used `fmt` APIs were fixed. ### Added - **fmt**: Shorthand free functions for constructing most types in `fmt` (including `tracing_subscriber::fmt()` to return a `SubscriberBuilder`, `tracing_subscriber::fmt::layer()` to return a format `Layer`, etc) (#660) - **registry**: Shorthand free function `tracing_subscriber::registry()` to construct a new registry (#660) - Added `SubscriberInitExt` extension trait for more ergonomic subscriber initialization (#660) ### Changed - **fmt**: Moved `LayerBuilder` methods to `Layer` (#655) ### Deprecated - **fmt**: `LayerBuilder`, as `Layer` now implements all builder methods (#655) ### Fixed - **fmt**: Fixed `Compact` formatter not omitting levels with `with_level(false)` (#657) - **fmt**: Fixed `fmt::Layer` duplicating the fields for a new span if another layer has already formatted its fields (#634) - **fmt**: Added missing space when using `record` to add new fields to a span that already has fields (#659) - Updated outdated documentation (#647) Signed-off-by: Eliza Weisman <eliza@buoyant.io>
tracing-error
Utilities for instrumenting errors with tracing
.
Documentation (release) | Documentation (master) | Chat
Overview
tracing
is a framework for instrumenting Rust programs to collect
scoped, structured, and async-aware diagnostics. This crate provides
integrations between tracing
instrumentation and Rust error handling. It
enables enriching error types with diagnostic information from tracing
span contexts, formatting those contexts when errors are displayed, and
automatically generate tracing
[events] when errors occur.
The crate provides the following:
-
SpanTrace
, a captured trace of the currenttracing
span context -
ErrorLayer
, a subscriber layer which enables capturingSpanTrace
s
Note: This crate is currently experimental.
Compiler support: requires rustc
1.39+
Usage
Currently, tracing-error
provides the SpanTrace
type, which captures
the current tracing
span context when it is constructed and allows it to
be displayed at a later time.
This crate does not currently provide any actual error types implementing
std::error::Error
. Instead, user-constructed errors or libraries
implementing error types may capture a SpanTrace
and include it as part
of their error types.
For example:
use std::{fmt, error::Error};
use tracing_error::SpanTrace;
#[derive(Debug)]
pub struct MyError {
context: SpanTrace,
// ...
}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// ... format other parts of the error ...
self.context.fmt(f)?;
// ... format other error context information, cause chain, etc ...
}
}
impl Error for MyError {}
impl MyError {
pub fn new() -> Self {
Self {
context: SpanTrace::capture(),
// ... other error information ...
}
}
}
In the future, this crate may also provide its own Error
types as well,
for users who do not wish to use other error-handling libraries.
Applications that wish to use tracing-error
-enabled errors should
construct an ErrorLayer
and add it to their [Subscriber
] in order to
enable capturing SpanTrace
s. For example:
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
fn main() {
let subscriber = tracing_subscriber::Registry::default()
// any number of other subscriber layers may be added before or
// after the `ErrorLayer`...
.with(ErrorLayer::default());
// set the subscriber as the default for the application
tracing::subscriber::set_global_default(subscriber);
}
License
This project is licensed under the MIT license.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tracing by you, shall be licensed as MIT, without any additional terms or conditions.