#error-reporting #tracing #printing #spans #object #span-trace #color-backtrace

color-spantrace

A pretty printer for tracing_error::SpanTrace based on color-backtrace

9 releases

0.2.1 Nov 17, 2023
0.2.0 Jan 13, 2022
0.1.6 Dec 2, 2020
0.1.4 Jul 6, 2020
0.1.1 May 7, 2020

#158 in Command-line interface

Download history 101112/week @ 2024-07-23 96125/week @ 2024-07-30 99623/week @ 2024-08-06 96810/week @ 2024-08-13 94381/week @ 2024-08-20 95031/week @ 2024-08-27 107315/week @ 2024-09-03 97603/week @ 2024-09-10 96052/week @ 2024-09-17 107932/week @ 2024-09-24 104158/week @ 2024-10-01 107778/week @ 2024-10-08 121132/week @ 2024-10-15 113254/week @ 2024-10-22 119517/week @ 2024-10-29 112334/week @ 2024-11-05

484,273 downloads per month
Used in 18 crates (2 directly)

MIT/Apache

190KB
236 lines

color-spantrace

Build Status Latest Version Rust Documentation

A rust library for colorizing tracing_error::SpanTrace objects in the style of color-backtrace.

Setup

Add the following to your Cargo.toml:

[dependencies]
color-spantrace = "0.2"
tracing = "0.1"
tracing-error = "0.2"
tracing-subscriber = "0.3"

Setup a tracing subscriber with an ErrorLayer:

use tracing_error::ErrorLayer;
use tracing_subscriber::{prelude::*, registry::Registry};

Registry::default().with(ErrorLayer::default()).init();

Create spans and enter them:

use tracing::instrument;
use tracing_error::SpanTrace;

#[instrument]
fn foo() -> SpanTrace {
    SpanTrace::capture()
}

And finally colorize the SpanTrace:

use tracing_error::SpanTrace;

let span_trace = SpanTrace::capture();
println!("{}", color_spantrace::colorize(&span_trace));

Example

This example is taken from examples/color-spantrace-usage.rs:

use tracing::instrument;
use tracing_error::{ErrorLayer, SpanTrace};
use tracing_subscriber::{prelude::*, registry::Registry};

#[instrument]
fn main() {
    Registry::default().with(ErrorLayer::default()).init();

    let span_trace = one(42);
    println!("{}", color_spantrace::colorize(&span_trace));
}

#[instrument]
fn one(i: u32) -> SpanTrace {
    two()
}

#[instrument]
fn two() -> SpanTrace {
    SpanTrace::capture()
}

This creates the following output

Minimal Format

minimal format

Full Format

Full format

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.5MB
~26K SLoC