Skip to main content

Crate crustrace_mermaid

Crate crustrace_mermaid 

Source
Expand description

§crustrace-mermaid

A tracing_subscriber::Layer implementation that collects spans and renders them as Mermaid flowcharts.

This crate is designed to pair with crustrace, which automatically instruments entire modules. Together, you can generate call graphs of your Rust program without hand-writing #[instrument].

§Example

use crustrace::instrument;
use crustrace_mermaid::{MermaidLayer, GroupingMode};
use tracing_subscriber::prelude::*;

#[instrument]
fn inner(x: i32) -> i32 { x + 1 }

#[instrument]
fn outer(y: i32) -> i32 {
    inner(y) + inner(y * 2)
}

fn main() {
    let layer = MermaidLayer::new().with_mode(GroupingMode::MergeByName);
    tracing_subscriber::registry().with(layer).init();

    outer(5);
    // When the root span closes, a Mermaid diagram is printed to stdout
}

By default, the layer flushes automatically when a root span finishes, but you can disable this with MermaidLayer::without_auto_flush and call MermaidLayer::flush manually.

Structs§

MermaidLayer
A tracing_subscriber::Layer that collects function spans and renders them as a Mermaid flowchart.

Enums§

GroupingMode
How to group multiple calls in the rendered Mermaid output.
ParamRenderMode
How to render function parameters in Mermaid output.