Skip to main content

test_collect_traces

Attribute Macro test_collect_traces 

Source
#[test_collect_traces]
Expand description

Capture logs from a test run into an in-memory store.

This macro defaults to a log level of DEBUG on the tracing_subscriber::fmt layer if no level is provided.

This macro is powered by the tracing, tracing-subscriber, and commonware-runtime crates.

§Note

This macro requires the resolution of the commonware-runtime, tracing, and tracing_subscriber crates.

§Example

use commonware_runtime::telemetry::traces::collector::TraceStorage;
use tracing::{debug, info};

#[commonware_macros::test_collect_traces("INFO")]
fn test_info_level(traces: TraceStorage) {
    // Filter applies to console output (FmtLayer)
    info!("This is an info log");
    debug!("This is a debug log (won't be shown in console output)");

    // All traces are collected, regardless of level, by the CollectingLayer.
    assert_eq!(traces.get_all().len(), 2);
}