SpanExt

Trait SpanExt 

Source
pub trait SpanExt: Sized {
    // Required method
    fn attach_span(self) -> Self;
}
Expand description

Extension trait for attaching tracing spans to reports.

This trait provides methods to easily attach the current tracing span to a report or to the error contained within a Result.

§Examples

Attach tracing span to a report:

use rootcause::report;
use rootcause_tracing::SpanExt;

#[tracing::instrument]
fn example() {
    let report = report!("An error occurred").attach_span();
}

Attach tracing span to a Result:

use rootcause::{Report, report};
use rootcause_tracing::SpanExt;

#[tracing::instrument]
fn might_fail() -> Result<(), Report> {
    Err(report!("operation failed").into_dynamic())
}

let result = might_fail().attach_span();

Required Methods§

Source

fn attach_span(self) -> Self

Attaches the current tracing span to the report.

§Examples
use rootcause::report;
use rootcause_tracing::SpanExt;

#[tracing::instrument]
fn example() {
    let report = report!("error").attach_span();
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<C: ?Sized, T> SpanExt for Report<C, Mutable, T>

Source§

fn attach_span(self) -> Self

Source§

impl<C: ?Sized, V, T> SpanExt for Result<V, Report<C, Mutable, T>>

Source§

fn attach_span(self) -> Self

Implementors§