> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rua.hud.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Telemetry

> Reference for rua.telemetry: TraceRecorder, the video streamer and encoder, and the hud.robot.step.v1 observation, inference and video step schemas.

`rua.telemetry` records robot runs onto HUD traces. The guide is [Recording traces](https://docs.rua.hud.ai/guides/recording-traces.md).

```python theme={"dark"}
from rua.telemetry.recorder import TraceRecorder, to_numpy
from rua.telemetry.steps import ROBOT_STEP_SCHEMA, RobotStepSource
from rua.telemetry.video import SegmentEncoder, VideoStreamer
```

The `rua.telemetry` package itself exports nothing; import from the submodules.

Steps reach the platform only when HUD reporting is on: `HUD_API_KEY` set and `HUD_TELEMETRY_ENABLED` not false.

## `TraceRecorder`

```python theme={"dark"}
TraceRecorder(
    *,
    trace_id: str | None = None,
    run: hud.Run | None = None,
    fps: int = 10,
    prompt: str | None = None,
    obs_space: dict[str, Any] | None = None,
    action_names: list[str] | None = None,
    state_names: dict[str, list[str]] | None = None,
    sim_clock: bool = False,
    keep_every_video_frame: bool = False,
)
```

Streams one trace's robot telemetry. The trace's lifecycle stays with the caller.

| Argument | Description |
| - | - |
| `trace_id` / `run` | One is required. With `run`, steps are recorded through it and land on `run.trace`; with `trace_id`, they are emitted directly, from any thread. |
| `fps` | Video frame rate, and the sim clock's tick length. |
| `prompt` | With `trace_id` only, emitted as an opening user step. |
| `obs_space` | Contract observation features, used to label state (see [labels with `order`](https://docs.rua.hud.ai/reference/contract#labels-with-order)). |
| `action_names` | Labels for each action dimension on inference steps. |
| `state_names` | Fallback labels per state key, used without `obs_space`. |
| `sim_clock` | Stamp each observation at `tick / fps` after the first, so the viewer's clock follows the video. |
| `keep_every_video_frame` | Block on the encoder instead of dropping frames, so video frame N is tick N. |

| Method | Description |
| - | - |
| `record_observation(data, *, tick, measured=None)` | One tick: arrays of rank 2 or more go to video (`HxWxC` with 1, 3 or 4 channels); flat numeric vectors become labelled state. Without `obs_space`, vectors over 512 elements are skipped. `measured` adds state features beside them. |
| `record_inference(chunk, *, tick, status=None, reason=None, played=None, started_at=None)` | One `[T, A]` chunk; a single action is a length-1 chunk. A direct-control request passes how it ended, and `started_at` so the step spans the request. |
| `add_reward(reward)` | Add to the `reward` attribute. |
| `close()` | Flush the video tails. Idempotent. |

## `to_numpy`

```python theme={"dark"}
to_numpy(x: Any) -> numpy.ndarray
```

Coerces a torch tensor (detached, moved to CPU), an array or a scalar to a numpy array, without importing torch.

## Video

`VideoStreamer(*, fps, trace_id, keep_every_frame=False)` runs one `SegmentEncoder` thread per camera and emits a
`VideoSegmentStep` for every segment. `record(obs)` submits each `HxWxC` frame in `obs["data"]` with 1, 3 or 4
channels; `finalize()` flushes every camera's tail. It needs PyAV (`av`), a rua dependency.

`SegmentEncoder(camera, on_segment, *, fps, segment_seconds=2.0, crf=23, max_queued_frames=16, keep_every_frame=False)`
encodes one camera to H.264 in fragmented MP4 (CMAF). Segment 0 is the init segment; each later one is a
fragment of about `segment_seconds`. Frames are converted to RGB, with odd sides cropped to even. Under
backpressure, `submit` drops frames unless `keep_every_frame`.

## Step schemas

Every robot step is a `hud.types.Step` subclass with `schema_tag = ROBOT_STEP_SCHEMA = "hud.robot.step.v1"`,
which the HUD trace viewer dispatches on. `RobotStepSource` is
`Literal["observation", "inference", "video_segment"]`.

| Step | `source` | Fields |
| - | - | - |
| `ObservationStep` | `observation` | `tick: int`, `state: dict[str, StateFeature]`, `images: dict[str, ImageContent]` (camera frames travel as video instead) |
| `InferenceStep` | `inference` | `tick: int`, `chunk: list[list[float]]`, `chunk_length: int`, `names: list[str]`, and for a direct-control request `status`, `reason`, `played` |
| `VideoSegmentStep` | `video_segment` | `camera: str`, `index: int` (0 is the init segment), `fps: int`, `segment: {"type": "video", "data": <base64 MP4>, "mimeType": "video/mp4"}` |

`StateFeature` is `{names: list[str], values: list[float], role: FeatureRole | None}`. `FeatureRole` is
`Literal["state", "privileged", "measured"]`: what the agent observes, the env's hidden state, which the agent never
sees, or a part as the embodiment measures it. `ObservationStep.from_obs(obs, *, tick=0, obs_space=None)`
builds an observation step from a raw `{"data": ...}` observation; a feature takes its role from the contract
feature that labels it (`observation` gives `state`, `privileged` gives `privileged`).

### Direct-control traces

`DirectControl` and `CodeControl` record each episode onto the rollout's trace. The recording opens at the
scene as it is on the agent's first call of any tool (`move`, `done`, `hindsight` or `python`), so an episode
that never moves still records its opening scene as tick 0.

* Each tick is an `ObservationStep` with the contract's `observation` and `privileged` features, and a
  `measured/<part>` feature (role `measured`) per embodiment part, labelled with the part's dims. A part's values
  are what a move starts from, in the dims' units.
* Each request is one `InferenceStep`: a `move` call, a cell's `robot.move` or a `robot.step`. `tick` is the tick
  the request started from, `chunk` holds the rows it played on ticks `tick + 1` to `tick + played`, and the step
  spans the request's wall-clock time. `status` is `RequestStatus`,
  `Literal["completed", "cut_short", "refused", "vetoed", "ended"]`; a refused or vetoed request has its `reason`
  and an empty chunk. A request still playing when the episode ends is not recorded.


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