eyre/color-spantrace
Georg Semmler 9f35b8c83f
Exclude images from published crate (#239)
This commit introduces an explict `include` configuration in the
`Cargo.toml` file of `color-spantrace`. That has the effect that it now
excludes the two example images from the source code uploaded to
crates.io.
The main benifits of this change are:

* It reduces the size of the uploaded tar-ball from 186KB to 12KB, so an
over 90% reduction in size. That will reduce the traffic produced by
this crate at crates.io by over 350GB in a 90 day period based on the
number of downloads listed by crates.io
* It removes a hard to review binary blob from the source code. In
combination with the build script such a blob might enable a future
supply chain attack. By removing the blob it becomes at least harder to
perform a xz-like code injection.

The pictures are only used by the readme. That readme is rendered by
crates.io. To keep the rendering there intact the links to the image
have been replaced by linkes to the image hosted by github. This removes
the need to upload these images to crates.io.
2025-05-27 21:10:13 +00:00
..
2023-11-21 14:28:07 -08:00
2023-10-10 23:51:31 +02:00
2023-10-03 21:18:59 +01:00

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.