Open fleetingbytes opened 2 years ago
If you copy the source text directly, then you'll include the #[cfg(feature = "capture-spantrace")]
, which won't work unless you've defined your own feature named the same. Try removing the directives, i.e. write this:
use color_eyre::{eyre::Report, eyre::WrapErr, Section};
use tracing::{info, instrument};
#[instrument]
fn main() -> Result<(), Report> {
install_tracing();
color_eyre::install()?;
read_config()
}
fn install_tracing() {
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};
let fmt_layer = fmt::layer().with_target(false);
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();
tracing_subscriber::registry()
.with(filter_layer)
.with(fmt_layer)
.with(ErrorLayer::default())
.init();
}
#[instrument]
fn read_file(path: &str) -> Result<(), Report> {
info!("Reading file");
Ok(std::fs::read_to_string(path).map(drop)?)
}
#[instrument]
fn read_config() -> Result<(), Report> {
read_file("fake_file")
.wrap_err("Unable to read config")
.suggestion("try using a file that exists next time")
}
And then also enable the env-filter
feature of tracing-subscriber
so that the code builds:
[package]
name = "minimal"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
color-eyre = {version = "0.6.2", features = ["capture-spantrace"]}
tracing = "0.1.36"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
tracing-error = "0.2.0"
Then it works for me.
Thanks, I'll check it out in the course of the next week.
When I copy paste the source code of
usage.rs
into a new minimal rust project, it does not show theINFO
trace event and the error does not have theSPANTRACE
section.The Cargo.toml of that minimal project looks like this:
But when I run
cargo run --example usage
in the local clone of thecolor-eyre
repository, I see the Info Event being print out just just fine:And the Error is shown with its span trace section:
What am I missing in the minimal example?