> ## Documentation Index
> Fetch the complete documentation index at: https://desme.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# trace

> Mark a function as a traced execution node in the dbgflow graph.

The `#[trace]` attribute macro instruments a function so that every call appears as a node in the dbgflow execution graph. When the function is called, dbgflow records entry, captures previews of all arguments, and records the return event. You can then inspect this data in the browser UI or during test playback.

## Usage

Add `#[trace]` directly above any `fn` item:

```rust theme={null}
use dbgflow::prelude::*;

#[trace]
fn process(input: &str) -> usize {
    input.len()
}
```

## Arguments

**name** `string`

Optional display label shown in the browser UI. Defaults to the function name as written in source.

```rust theme={null}
#[trace(name = "Normalize Tokens")]
fn normalize(tokens: &mut Vec<String>) {
    for t in tokens.iter_mut() {
        *t = t.to_lowercase();
    }
}
```

## What gets captured

For every call to a traced function, dbgflow records three things:

| Event | Description |
| - | - |
| Function entry | Marks the call start and establishes the node in the session graph |
| Argument previews | Each parameter is formatted with `Debug` and stored alongside the entry event |
| Return value | The return value is formatted with `Debug` and stored as the exit event |

> [!NOTE]
>
> Argument previews use `Debug` formatting. Any type passed as an argument must implement `Debug` for its preview to be captured. Types that do not implement `Debug` will show `<non-ident pattern>` in the UI instead.

## Example

The following example shows basic usage alongside a named override:

```rust theme={null}
use dbgflow::prelude::*;

#[derive(Debug)]
struct Payload {
    value: u32,
}

// Basic trace — node label in the UI will be "validate"
#[trace]
fn validate(payload: &Payload) -> bool {
    payload.value > 0
}

// Named trace — node label in the UI will be "Validate Payload"
#[trace(name = "Validate Payload")]
fn validate_named(payload: &Payload) -> bool {
    payload.value > 0
}

fn main() {
    dbgflow::capture_and_serve("example", "127.0.0.1", 3000, || {
        let p = Payload { value: 42 };
        validate(&p);
        validate_named(&p);
    }).unwrap();
}
```

## Notes on `Debug` requirements

* **Primitive types** (`u32`, `&str`, `bool`, etc.) implement `Debug` by default.
* **Standard library types** like `Vec<T>`, `Option<T>`, and `Result<T, E>` implement `Debug` when their type parameters do.
* **Your own types** need `#[derive(Debug)]` or a manual `Debug` implementation. If you also annotate them with [`#[ui_debug]`](https://desme.mintlify.site/macros/ui-debug), `Debug` is derived automatically.
* **`self` receivers** are always captured as `"self"` in the preview — the `Self` type must implement `Debug`.

> [!WARNING]
>
> If a traced function takes a type that does not implement `Debug`, your code will fail to compile. Add `#[derive(Debug)]` to the type or implement `Debug` manually before adding `#[trace]`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.