Error propagation tracing in Rust.

Related tags

Utilities propagate
Overview

Propagate

Error propagation tracing in Rust.

Why Propagate?

Being able to trace the cause of an error is critical for many types of software written in Rust. For easy diagnosis, errors should provide some sort of trace denoting source code locations that contributed to the error.

Crates such as anyhow provide easy access to backtraces when creating errors. The Propagate crate provides something similar but more powerful, which I call propagation tracing: every time the ? operator is applied to an error result, the code location of that ? invocation is appended to a running "stack trace" stored in the result.

Propagation tracing differs from runtime backtracing in a few important ways. You should evaluate which approach is appropriate for your application.

Advantages of Propagation Tracing

Multithreaded tracing

A backtrace provides a single point-in-time capture of a call stack on a single thread. In complex software, error results may pass between multiple threads on their way up to their final consumers.

Propagate provides a true view into the path that an error takes through your code, even if it passes between multiple threads.

Low performance overhead

Runtime backtracing requires unwinding stacks and mapping addresses to source code locations symbols at runtime.

With Propagate, the information for each code location is compiled statically into your application's binary, and the stack trace is built up in real time as the error propagates from function to function.

Disadvantages of Propagation Tracing

Code size

Propagate stores the code location of every ? invocation in the static section of your application or library's binary.

Boilerplate

Propagate results require a bit more attention to work with compared to using the standard library Result type. Much of this can be avoided if you elect to use try blocks.

See the crate docs for more details.

Try It Out

Building

Propagate requires #[feature(try_trait_v2)] and #[feature(control_flow_enum)]. Build with Rust nightly:

cargo +nightly build

Examples

See examples/ for some examples showing the usage of the Propagate crate. Run them as such:

cargo +nightly run --example usage

Tests

To run tests:

cargo +nightly test

Documentation

The rustdocs may lag behind as changes are made to the code. The examples and tests should be your first stop for understanding how the crate works.

To view the rustdocs, use cargo:

cargo doc --open
You might also like...
Utilities for integrating Datadog with opentelemetry + tracing in rust

Non-official datadog tracing and log correlation for Rust services. This crate contains the necessary glue to bridge the gap between OpenTelemetry, tr

This crate bridges between gstreamer and tracing ecosystems.

This crate provides a bridge between gstreamer and the tracing ecosystem. The goal is to allow Rust applications utilizing GStreamer to better integra

A tracing profiler for the Sega MegaDrive/Genesis
A tracing profiler for the Sega MegaDrive/Genesis

md-profiler, a tracing profiler for the Sega MegaDrive/Genesis This program, meant to be used with this fork of BlastEm, helps you finding bottlenecks

A tracing layer for macOS/iOS's `oslog`

tracing_oslog This is a tracing layer for the Apple OS logging framework. Activities are used to handle spans, Example use tracing_oslog::OsLogger; l

A patch to fix tracing LocalTime problem.

tracing-local-time A patch to fix tracing LocalTime problem. Tracing-subscriber now has a bug in LocalTime, so build ourselves' to fix it. In this pat

An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)
An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)

Rocket Tracing Fairing Example This repository aims to give a short example of how you can add a Fairing to your Rocket for tracing and how to use it

A dynamic binary tracing tool

Backlight Backlight is a dynamic binary tracing tool. Install $ git clone [email protected]:JoshMcguigan/backlight.git $ cd backlight $ cargo install-b

Tracing layer to quickly inspect spans and events

tracing-texray First, a word of warning: This is alpha software. Don't run this in prod or anywhere where a panic would ruin your day. tracing-texray

Middlewares and tools to integrate axum + tracing + opentelemetry

axum-tracing-opentelemetry Middlewares and tools to integrate axum + tracing + opentelemetry. Read OpenTelemetry header from incoming request Start a

Comments
  • Make `Result` a wrapper, not a re-implementation.

    Make `Result` a wrapper, not a re-implementation.

    Previously, propagate::Result was mostly a copy of std::result::Result, with a different Err type and modified FromResidual implementations.

    Because of this, users would have to to use propagate::Result::{Ok, Err} to construct results (unless they used try blocks).

    This changes propagate::Result<T, E, S> to be a minimal wrapper around a std::result::Result<T, TracedError<E, S>>. If users want to get to the wrapped result, they can call .unpack(), which will also return the traced stack if there is one.

    With this change, users no longer need to (nor have the ability to) shadow the standard library's Ok and Err. Now, there should be much less confusion about what a propagate::Result really is. It no longer pretends to be the same thing as a std::result::Result.

    opened by BGR360 3
Owner
Ben Reeves
haha Rust go brr
Ben Reeves
tracing-glog is a glog-inspired formatter for tracing-subscriber.

tracing-glog tracing-glog is a glog-inspired formatter for tracing-subscriber. tracing-glog should be used with tracing-subscriber, as it is a formatt

David Barsky 7 Oct 8, 2022
Error context library with support for type-erased sources and backtraces, targeting full support of all features on stable Rust

Error context library with support for type-erased sources and backtraces, targeting full support of all features on stable Rust, and with an eye towards serializing runtime errors using serde.

Findora Foundation 1 Feb 12, 2022
Rust Util Collection, a simple and friendly error-chain

RUC Rust Util Collection, a simple and friendly error-chain, with many useful utils as an addition. The painful experience of using error-chain gave b

漢 8 Dec 8, 2022
Rust Util Collection, a simple and friendly error-chain, with many useful utils as an addition.

RUC Rust Util Collection, a simple and friendly error-chain, with many useful utils as an addition. The painful experience of using error-chain gave b

漢 6 Mar 27, 2022
A fancy diagnostics & error reporting crate

A fancy diagnostics & error reporting crate

Joshua Barretto 1.1k Dec 30, 2022
Better error messages for axum framework.

axum-debug This is a debugging crate that provides better error messages for axum framework. axum is a great framework for developing web applications

Eray Karatay 3 Feb 3, 2022
my attempt at compromise between unwrapping and bullying my dependencies' authors for Error impl

string-eyre Has this happened to you? error[E0599]: the method `wrap_err` exists for enum `Result<(), tauri::Error>`, but its trait bounds were not sa

Michał Sidor 1 Nov 25, 2021
Emit ETW events in tracing-enabled Rust applications.

tracing-etw Emit ETW events in tracing-enabled Rust applications. This crate depends on rust_win_etw. There are four ETW events. fn NewSpan(span_id: u

Microsoft 11 Aug 10, 2022
tracing - a framework for instrumenting Rust programs to collect structured, event-based diagnostic information

tracing-appender Writers for logging events and spans Documentation | Chat Overview tracing is a framework for instrumenting Rust programs to collect

Cris Liao 1 Mar 9, 2022
A rust `tracing` compatible framework inspired by log4rs.

trace4rs This crate allows users to configure output from tracing in the same way as you would configure the output of log4rs. Overview For a usage ex

Imperva 5 Oct 24, 2022