You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
When I copy paste the source code of usage.rs into a new minimal rust project, it does not show the INFO trace event and the error does not have the SPANTRACE section.
The Cargo.toml of that minimal project looks like this:
[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 = "0.3.15"
tracing-error = "0.2.0"
But when I run cargo run --example usage in the local clone of the color-eyre repository, I see the Info Event being print out just just fine:
2022-08-16T06:47:07.017504Z INFO read_config:read_file{path="fake_file"}: Reading file
And the Error is shown with its span trace section:
...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
0: usage::read_file with path="fake_file"
at examples\usage.rs:32
1: usage::read_config
at examples\usage.rs:38
...
What am I missing in the minimal example?
The text was updated successfully, but these errors were encountered:
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]fnmain() -> Result<(),Report>{install_tracing();
color_eyre::install()?;read_config()}fninstall_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]fnread_file(path:&str) -> Result<(),Report>{info!("Reading file");Ok(std::fs::read_to_string(path).map(drop)?)}#[instrument]fnread_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"
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?
The text was updated successfully, but these errors were encountered: