<!-- Canonical HTML: https://docs.didro.ai/sap-ui-automation/guides/trace-viewer -->

# Trace viewer

A trace is a recording with timings, screens and screenshots: what the
agent or the test did, step by step, and what SAP showed after each step.
Use it to see why a test failed, or to review what an agent did before you
trust it with more.

## Making a trace

- **Tests:** the [test runner](https://docs.didro.ai/sap-ui-automation/guides/sdk-tests#the-test-runner) writes a trace
  for each test to `sap-results/<test>/`.
- **Scripts:** `connect({ trace: { dir, name, screenshots: true } })`; `sap.close()`
  returns the trace's path.
- **Agents:** `sap_record` with `SAP_RECORD_DIR` ([Recording and
  replay](https://docs.didro.ai/sap-ui-automation/guides/record-replay)).

A trace is a `.saptest.json` file (format `sap-gui-test/1`), the same as a
recording: every step has `ms` (how long it took) and `at` (when it
started), as a recording's steps do. A trace's steps also carry:

| Field | Holds |
| --- | --- |
| `screen` | the compact screen after the step |
| `code` | the SDK line that repeats it |
| `shot` | the path of a screenshot, `<name>.trace/step-N.png` |

Every field: [File formats](https://docs.didro.ai/sap-ui-automation/reference/file-formats#recordings-saptest-json).

## Opening it

```sh
npx sap-ui-automation show-trace sap-results/sap-tests-display-order-display-order/display-order.saptest.json --open
```

The runner names each test's folder after its file and its title, and the
trace after its title: the test "display order" in
`sap-tests/display-order.sap.ts` writes
`sap-results/sap-tests-display-order-display-order/display-order.saptest.json`.
The [tutorial](https://docs.didro.ai/sap-ui-automation/getting-started/tutorial#_9-open-the-trace) makes
that one.

`show-trace` writes one self-contained HTML file next to the JSON (or to
`--out <file>`) and, with `--open`, opens it in your browser. The page has
no scripts or fonts from the network: you can attach it to a ticket or keep
it with test results. It replaces a file of that name, but never writes
through a link: when the page's path is a link, it stops and asks for
`--out`. It inlines only screenshots that are regular image files inside
the trace's folder, so a trace you were sent cannot pull your other files
into the page.

> **Traces hold business data**
>
> Screens, screenshots and typed values are in the trace. Treat a trace like
> the system's data: keep it where that data may be kept, and do not attach
> it to public issues. See [Security and data handling](https://docs.didro.ai/sap-ui-automation/security).
