Skip to main content
The capture API lets you instrument any Rust code — not just tests — and collect a debug session from it. Use these helpers when you want to trace a main function, a CLI script, a benchmark harness, or any other code that runs outside of #[dbg_test].

Setup

Add dbgflow to your Cargo.toml:
Then import the prelude at the top of your file:
The prelude re-exports capture, capture_to_file, capture_and_serve, and all instrumentation macros (#[trace], #[ui_debug], #[dbg_test]).

dbgflow::capture

Runs a closure inside a fresh in-memory session and returns its result. The session stays in memory after the closure completes; use dbgflow::save_current_session afterward if you want to persist it. Parameters Returns T — the return value of the closure.

Example

capture resets any previously active session. If you need to keep an existing session, retrieve it with dbgflow::current_session() before calling capture.

dbgflow::capture_to_file

Runs a closure, then writes the captured session to a JSON file. This is the most common choice for CI pipelines or build scripts where you want to save a session artifact for later review. Parameters Returns std::io::Result<T> — Ok(result) on success, or an Err if writing the file fails.

Example

After saving, you can open the session in the browser UI with the CLI:

dbgflow::capture_and_serve

Runs a closure, then immediately serves the captured session over the embedded HTTP server. Your browser can then open the interactive graph UI. This is the fastest way to get a visual of your execution during local development. Parameters Returns std::io::Result<T> — Ok(result) on success, or an Err if starting the server fails. The call blocks until you stop the server.

Example

capture_and_serve blocks the current thread while the server is running. Use it in standalone binaries or scripts, not in library code that should return promptly.

Choosing the right helper