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

# dspy_rs::trace

> Execution trace capture (RFC 0001).

<Note>
  Generated from rustdoc JSON at `dspy-rs v0.7.3` (commit `b5da857`). Do not edit by hand; regenerate with `python3 docs/scripts/gen_api.py` (see the script header for the rustdoc commands). Item links lead to full signatures and method docs on docs.rs.
</Note>

Execution trace capture (RFC 0001).

## Re-exports

| Item                                                                                                                | Description                                     |
| ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| `capture::*`                                                                                                        | Glob re-export.                                 |
| `export::*`                                                                                                         | Glob re-export.                                 |
| [`is_replaying`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/fn.is_replaying.html)                          | Re-export of `replay::is_replaying`.            |
| [`replay`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/fn.replay.html)                                      | Re-export of `replay::replay`.                  |
| [`ReplayError`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/enum.ReplayError.html)                          | Re-export of `replay::ReplayError`.             |
| [`ReplayMode`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/enum.ReplayMode.html)                            | Re-export of `replay::ReplayMode`.              |
| [`ReplayReport`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/struct.ReplayReport.html)                      | Re-export of `replay::ReplayReport`.            |
| `span::*`                                                                                                           | Glob re-export.                                 |
| [`TRACE_FORMAT_VERSION`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/serialize/constant.TRACE_FORMAT_VERSION.html) | Re-export of `serialize::TRACE_FORMAT_VERSION`. |

## Modules

| Item                                                                             | Description                                                                                                       |
| -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| [`capture`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/index.html)     | Task-local capture scope for the unified trace format.                                                            |
| [`export`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/index.html)       | Exports: projections of the trace format onto external training and observability conventions (RFC 0001 §4f/§4g). |
| [`replay`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/index.html)       | Replay scope: serve `Predict` calls from a recorded `Trace` (RFC 0001 §4d/§4e).                                   |
| [`serialize`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/serialize/index.html) | JSONL wire format for `Trace`: header line, span lines, optional footer.                                          |
| [`span`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/index.html)           | The unified trace format (RFC 0001): one `Span` per `Predict` invocation, one `Trace` per rollout.                |

## `trace::capture`

Task-local capture scope for the unified trace format.

### Structs

| Item                                                                                          | Description                                                                                                                                                                             |
| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`SpanGuard`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/struct.SpanGuard.html)     | Owns a `SpanId` — event/close attribution travels with the guard, never through "innermost open span" lookups, so interleaved `Predict`s on one task (`futures::join!`) cannot cross... |
| [`SpanOutcome`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/struct.SpanOutcome.html) | Everything recorded lazily at span close.                                                                                                                                               |
| [`SpanRequest`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/struct.SpanRequest.html) | Everything recorded eagerly at span open.                                                                                                                                               |
| [`TraceSink`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/struct.TraceSink.html)     | Shared handle to an in-progress trace.                                                                                                                                                  |

### Functions

| Item                                                                                                  | Description                                                                                                                                        |
| ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`begin_span`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/fn.begin_span.html)               | Opens a span in the active capture scope. Returns `None` when no scope is active — the caller does nothing else in that case (zero-overhead path). |
| [`capture_with_meta`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/fn.capture_with_meta.html) | `capture` with caller-provided rollout metadata (input, candidate hash, tags). Missing `trace_id`/`started_at_us` are minted at scope start.       |
| [`capture`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/fn.capture.html)                     | Runs `f` while recording every `Predict` call on this task into a `Trace`.                                                                         |
| [`is_capturing`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/capture/fn.is_capturing.html)           | Returns `true` if the current task is inside a `capture` scope.                                                                                    |

## `trace::export`

Exports: projections of the trace format onto external training and observability conventions (RFC 0001 §4f/§4g).

### Re-exports

| Item                                                                                                | Description                        |
| --------------------------------------------------------------------------------------------------- | ---------------------------------- |
| [`OtelEvent`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelEvent.html)       | Re-export of `otel::OtelEvent`.    |
| [`OtelKeyValue`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelKeyValue.html) | Re-export of `otel::OtelKeyValue`. |
| [`OtelSpan`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelSpan.html)         | Re-export of `otel::OtelSpan`.     |
| [`OtelStatus`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelStatus.html)     | Re-export of `otel::OtelStatus`.   |
| [`OtelValue`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/enum.OtelValue.html)         | Re-export of `otel::OtelValue`.    |
| [`RlRollout`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/rl/struct.RlRollout.html)         | Re-export of `rl::RlRollout`.      |
| [`RlTransition`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/rl/struct.RlTransition.html)   | Re-export of `rl::RlTransition`.   |

## `trace::export::otel`

OTel export (RFC 0001 §4g): one-way batch mapping of a finished `Trace` onto OpenTelemetry GenAI semantic conventions — as plain serializable structs in the OTLP/JSON wire shape, w\...

### Structs

| Item                                                                                                | Description                                                                                                                           |
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| [`OtelEvent`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelEvent.html)       | OTLP span `Event`.                                                                                                                    |
| [`OtelKeyValue`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelKeyValue.html) | OTLP `KeyValue`.                                                                                                                      |
| [`OtelSpan`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelSpan.html)         | One span in the OTLP/JSON wire shape (proto3 JSON mapping: camelCase keys, 64-bit integers as decimal strings, ids as lowercase hex). |
| [`OtelStatus`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/struct.OtelStatus.html)     | OTLP span `Status`.                                                                                                                   |

### Enums

| Item                                                                                        | Description                                         |
| ------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| [`OtelValue`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/enum.OtelValue.html) | OTLP `AnyValue` (the oneof arms this export emits). |

### Constants

| Item                                                                                                              | Description                |
| ----------------------------------------------------------------------------------------------------------------- | -------------------------- |
| [`SPAN_KIND_CLIENT`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/constant.SPAN_KIND_CLIENT.html)     | OTLP `SPAN_KIND_CLIENT`.   |
| [`SPAN_KIND_INTERNAL`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/constant.SPAN_KIND_INTERNAL.html) | OTLP `SPAN_KIND_INTERNAL`. |
| [`STATUS_CODE_ERROR`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/otel/constant.STATUS_CODE_ERROR.html)   | OTLP `STATUS_CODE_ERROR`.  |

## `trace::export::rl`

RL rollout export (RFC 0001 §4f): the Agent Lightning / verifiers span convention — one rollout as message lists + reward + per-subcall transitions.

### Structs

| Item                                                                                              | Description                                                                                                                  |
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| [`RlRollout`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/rl/struct.RlRollout.html)       | One rollout: reward plus per-subcall transitions. Serializes to a single JSON object — the JSONL record RL trainers consume. |
| [`RlTransition`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/export/rl/struct.RlTransition.html) | One policy subcall — a `Predict` invocation as (prompt messages, emitted completion) with its span metadata.                 |

## `trace::replay`

Replay scope: serve `Predict` calls from a recorded `Trace` (RFC 0001 §4d/§4e).

### Structs

| Item                                                                                           | Description                                                                   |
| ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [`ReplayReport`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/struct.ReplayReport.html) | What a replay scope did, returned by `replay` alongside the closure's result. |

### Enums

| Item                                                                                       | Description                                                         |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------- |
| [`ReplayError`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/enum.ReplayError.html) | Why a call could not be served from the recording.                  |
| [`ReplayMode`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/enum.ReplayMode.html)   | How a replay scope treats a call that does not match its recording. |

### Functions

| Item                                                                                       | Description                                                                                                                                                                  |
| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`is_replaying`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/fn.is_replaying.html) | Returns `true` if the current task is inside a `replay` scope.                                                                                                               |
| [`replay`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/replay/fn.replay.html)             | Runs `f` with `trace` as the canned-response source for every `Predict` call on this task. Returns the closure's result and a `ReplayReport` of what was served versus live. |

## `trace::serialize`

JSONL wire format for `Trace`: header line, span lines, optional footer.

### Constants

| Item                                                                                                                | Description                                     |
| ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| [`TRACE_FORMAT_VERSION`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/serialize/constant.TRACE_FORMAT_VERSION.html) | Highest format version this reader understands. |

## `trace::span`

The unified trace format (RFC 0001): one `Span` per `Predict` invocation, one `Trace` per rollout.

### Structs

| Item                                                                                         | Description                                                                                                                                                                         |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`CompId`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.CompId.html)             | Per-trace interned component index. The component *name* is the same string the params system addresses: an fx slot name (`"drafter"`) or a facet dotted path (`"pipeline.rater"`). |
| [`Eval`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.Eval.html)                 | The metric result type: one score, optional textual feedback.                                                                                                                       |
| [`ModelEntry`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.ModelEntry.html)     | Interned model configuration: `LMConfig` minus live state, minus secrets.                                                                                                           |
| [`ModelId`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.ModelId.html)           | Per-trace interned model configuration.                                                                                                                                             |
| [`PrefixEntry`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.PrefixEntry.html)   |                                                                                                                                                                                     |
| [`PrefixId`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.PrefixId.html)         | Per-trace interned prompt prefix (system message + demo turns). One entry per distinct (component, candidate) configuration — demos serialize once per trace, not once per span.    |
| [`Span`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.Span.html)                 | One `Predict` invocation: one rendered prompt in, one parsed output out, with the tool loop's inner structure as ordered events.                                                    |
| [`SpanError`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.SpanError.html)       |                                                                                                                                                                                     |
| [`SpanId`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.SpanId.html)             | Index of a span within its trace. Dense, assigned in insertion order.                                                                                                               |
| [`Trace`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.Trace.html)               | One rollout: ordered spans plus per-trace intern tables.                                                                                                                            |
| [`TraceMeta`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.TraceMeta.html)       |                                                                                                                                                                                     |
| [`TraceOutcome`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/struct.TraceOutcome.html) |                                                                                                                                                                                     |

### Enums

| Item                                                                                         | Description                                                                                                 |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [`SpanErrorKind`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/enum.SpanErrorKind.html) |                                                                                                             |
| [`SpanEvent`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/enum.SpanEvent.html)         | Ordered events inside a span. Tagged; readers skip unknown tags — this is the streaming seam (RFC 0001 §6). |

### Type aliases

| Item                                                                             | Description |
| -------------------------------------------------------------------------------- | ----------- |
| [`JsonMap`](https://docs.rs/dspy-rs/latest/dspy_rs/trace/span/type.JsonMap.html) |             |
