Skip to main content
The capture helpers (capture, capture_to_file, capture_and_serve) cover most use cases, but sometimes you need finer control — for example, interleaving multiple traced phases, conditionally saving only on failure, or loading a previously recorded session. The session management functions let you do all of this explicitly.

When to use manual management

Use the manual API when you need to:
  • Run instrumented code across multiple separate call sites and collect it all into one session
  • Conditionally persist a session (e.g. only on error)
  • Load a saved .json file or a directory of session files for programmatic inspection
  • Combine session collection with custom error handling or structured logging
For simpler one-shot captures, the Capture API is less code.

dbgflow::init_session

Starts a fresh in-memory session. Any previously active session is discarded. Instrumented functions (#[trace], #[ui_debug]) called after this point record their events into this new session. Parameters Returns nothing.
Calling init_session again at any point discards the previous session and starts a new one. If you need to preserve the existing session, call save_current_session first.

dbgflow::save_current_session

Writes the current in-memory session to a JSON file at the given path. The session remains active in memory after saving; you can continue running instrumented code and call save_current_session again to overwrite or save to a different path. Parameters Returns std::io::Result<()> — Ok(()) on success, or an Err if the file cannot be written.

dbgflow::serve_current_session

Serves the current in-memory session over the embedded HTTP server. Opens the interactive graph UI in your browser. This call blocks until the server is stopped. Parameters Returns std::io::Result<()> — Ok(()) when the server shuts down, or an Err if it fails to start.

dbgflow::load_saved_session

Reads a previously saved session from disk and returns it as a Session value. The path can point to either a single .json file or a directory containing multiple .json files. Parameters Returns std::io::Result<Session> — the loaded (or merged) session on success.

Loading a single file

Loading a directory

When the path is a directory, load_saved_session reads every .json file in it, sorts them by filename, and merges them into a single Session. Each individual session becomes a separate pipeline in the merged result.
Node IDs, event sequence numbers, and call IDs are all re-namespaced during the merge so there are no collisions between sessions.
This is the same merging behaviour that dbgflow serve <directory> uses on the CLI. You can use load_saved_session to inspect merged sessions programmatically — for example, to assert on aggregate node counts in integration tests.

Full manual flow example

You can also save and then load back the session in the same process:

Manual management vs. capture helpers