Crate color_spantrace

source ·
Expand description

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


Add the following to your Cargo.toml:

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};


Create spans and enter them:

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

fn foo() -> SpanTrace {

And finally colorize the SpanTrace:

use tracing_error::SpanTrace;

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

Output Format

Running examples/ from the color-spantrace repo produces the following output:

 cargo run --example color-spantrace-usage
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/examples/color-spantrace-usage`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

 0: color-spantrace-usage::two
    at examples/
 1: color-spantrace-usage::one with i=42
    at examples/


  • An error returned by set_theme if a global theme was already set
  • A struct that represents theme that is used by color_spantrace