Improve error handling / reporting and logging via `eyre` and `tracing`
- Dominant language
- Rust
- Stars
- 1.3k
- Forks
- 116
- Avg merge
- 12h 34m
- Merged PRs (30d)
- 19
Description
@davidanthoff As discussed via Slack, here are some thoughts of how we could improve the current error handling / reporting and logging infrastructure. This is not a particularly urgent topic, but I'd like to hear your thoughts on this. If this sounds interesting to you, we could discuss how a small PoC could look like.
In the Rust ecosystem, the `tracing` family of crates are very popular for a variety of applications. They are originally from the `tokio` project and designed to work well even in asynchronous contexts, but I've found them to be extremely useful even in smaller and non-async applications.
The general idea is that the event-producers and how these are handled are separated out.
The core crate is the tracing crate. Particularly the `#[instrument]` macro is very powerful for automatically logging relevant context: https://docs.rs/tracing/0.1.37/tracing/attr.instrument.html
There are various forms of subscribers that can handle the produced events and output / pass them on. For the purposes that `env_log` currently provides, the `tracing_subscriber` crate should have everything we need: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/
Where things become really powerful is when we combine the `tracing` infrastructure with the `eyre` / `color_eyre` crates.
`eyre` is very similar to anyhow but a bit more actively developed and the author of the crate is actively shaping the Rust error handling ecosystem.
By using the `tracing_error` crate, the recorded span information (for logging purposes) can even be used as additional data for the error handling backtraces. See [here](https://github.com/yaahc/color-eyre#custom-sections-for-error-reports-via-section-trait) for an example of how the combination looks like.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the current error-handling and logging infrastructure, especially what env_log currently provides. Then evaluate a small PoC using tracing, tracing_subscriber, eyre or color_eyre, and tracing_error. Done means the project has an agreed PoC scope and feedback on whether this combination improves reporting and logging.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100