minitrace-macro

Documentation Crates.io LICENSE

Provides an attribute-macro trace to help get rid of boilerplate.

Usage

Dependency

toml [dependencies] minitrace = "0.4" # minitrace-macro is within minitrace::prelude

Synchronous Function

```rust use minitrace::prelude::*;

[trace("foo")]

fn foo() { // function body }

// * WILL BE TRANSLATED INTO: * // // fn foo() { // let _guard = LocalSpan::enterwithlocalparent("foo"); // { // // function body // } // } ```

Asynchronous Function

```rust use minitrace::prelude::*;

[trace("bar")]

async fn bar() { // function body }

// * WILL BE TRANSLATED INTO: * // // fn bar() -> impl core::future::Futurespan(Span::enterwithlocalparent("bar")) // }

[trace("qux", enteronpoll = true)]

async fn qux() { // function body }

// * WILL BE TRANSLATED INTO: * // // fn qux() -> impl core::future::Futureonpoll("qux") // } ```

⚠️ Local Parent Needed

A function instrumented by trace always require a local parent in the context. Make sure that the caller is within the scope of Span::set_local_parent().

```rust use minitrace::prelude::*;

[trace("foo")]

fn foo() {}

[trace("bar")]

async fn bar() {}

let (root, collector) = Span::root("root");

{ foo(); // This foo will not be traced. }

{ let g = root.setlocal_parent(); foo(); // This foo will be traced. }

{ runtime::spawn(bar()); // This bar will not be traced. }

{ let g = root.setlocal_parent(); runtime::spawn(bar()); // This bar will be traced. } ```

Developers

This Crate adopts the Ferrous Systems proc-macro pipeline:

image info

Tests

To see a list of all tests:

bash pushd minitest-macro cargo test -- --list popd

To run an individual test suite, say the ui suite:

bash cargo test ui -- --nocapture