Skip to content

mateuszkj/tracing-span-capture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

Mirror repository of tracing-span-capture

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks