tracing-span-capture

Crates.iotracing-span-capture
lib.rstracing-span-capture
version0.0.1
sourcesrc
created_at2023-03-29 10:44:48.350167
updated_at2023-03-29 10:44:48.350167
descriptionCapture and record logs for tracing span id
homepage
repositoryhttps://gitlab.com/mateuszkj/tracing-span-capture
max_upload_size
id823989
size32,800
(mateuszkj)

documentation

https://docs.rs/tracing-span-capture

README

Capture and record logs for tracing span id

This crate allow testing if function emitted logs.

Example

Example how to use it with cucumber, you can find here.

use tracing::{error, span, Level};
use tracing_span_capture::{RecordedLogs, TracingSpanCaptureLayer};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

fn tested_code() {
    error!("try capture this");
}

fn main() {
    tracing_subscriber::fmt()
        .finish()
        .with(TracingSpanCaptureLayer)
        .init();

    let span = span!(Level::INFO, "");
    let record = RecordedLogs::new(&span);
    {
        let _enter = span.enter();
        tested_code();
    }
    
    let logs = record.into_logs();
    let last_log = logs.into_iter().rev().next().unwrap();
    assert_eq!(last_log.message, "try capture this");
}

License

Licensed under either of:

Commit count: 7

cargo fmt