# What a recording is

> A recording is a folder in .ormaos/ that holds what the Python processes of one command, or one block, did while they ran.

`ormaos run -- <command>` runs the command unchanged and records every Python process it creates into `.ormaos/r<N>/`, in the directory where you ran it. `with ormaos.record():` does the same for a block of a script or a notebook cell. A recording is read with the `ormaos` verbs; reading never runs the program.

## What it holds

| Capability | What |
|---|---|
| `context` | the command (names only), the names of the environment variables, the exit code, duration, CPU and memory, every Python process the command started |
| `calls` | the call tree of your code, with the shape of the arguments and of the result, the file and line, how long each call took |
| `exceptions` | every exception that passes through your code, where it was raised and where it was handled |
| `io` | sqlite3 statements, files opened, read and written, subprocesses started and HTTP requests, each with the line of your code that caused it |
| `logs` | every record your code asks of `logging`: level, logger, line, message template, how many arguments; also the ones the level dropped |
| `dataframes` | of each pandas DataFrame or Series that a call of your code receives or returns: rows, columns, dtypes, nulls per column |
| `tensors` | of each numpy array or torch tensor that a call of your code receives or returns: shape, dtype, device, how many NaN and inf, the smallest and largest number |
| `path` | line by line, only inside a scope you ask for with `--path` |
| `not_collected` | what this run could not record, with the reason |

Every call, exception, I/O event and logging record says which process, which thread and, inside asyncio, which task it ran in: small numbers that belong to one recording (`process 2`, `thread 3`, `task 5`).

## Your code

"Your code" is every file outside the standard library and outside `site-packages`. Code compiled from a string is yours when its file name is `<string>`, `<stdin>` or a notebook cell. Calls inside the standard library and installed packages are not recorded; an exception raised inside a library is recorded when it passes through your code, with the first line of your code it was seen at. Set `ORMAOS_ONLY` to a list of paths to narrow what counts as yours.

## Which code ran

Before the command starts, `ormaos run` asks git for the commit and whether there are uncommitted changes, and keeps a hash, a flag, the number of changed files and a hash of the changes: no file name, no branch name, no content. `ormaos show` prints it:

```console
$ ormaos show r2
r2 exit 0 in …: 1 Python process, 113 calls, 0 exceptions (0 swallowed, 0 uncaught)
command: python run.py
code: git commit 5b23406de1 with uncommitted changes in 1 file
io: 82 events (file 82)
io: 38x file open tiers.json (read) from billing.py:11  [r2:i5]
io: 38x file read tiers.json from billing.py:12  [r2:i6]
not collected: io: writes to the 2 files opened at run.py:18: opened for writing, and no `write` call by Python code was seen on a file of that name: if it was written, that was inside C code (`print(..., file=f)`, `csv.writer`)
never recorded: values, and 20 more kinds of things (`ormaos show --full` lists them with the reason)
next: ormaos tree r2:c1 | ormaos io r2 | ormaos io r2:i5
```

Outside a repository, or without `git`, the recording says that the commit was not read, and why. `ormaos diff` says when two recordings ran different versions of the code.

## How it is observed

Ormaos records with `sys.monitoring` (PEP 669) and Python's audit events. It replaces and wraps nothing: `open` is still `open`, a connection is still a `sqlite3.Connection`. The recorder starts in child processes through a `.pth` file, driven by environment variables. Two things touch the program: it takes one `sys.monitoring` tool id, and it sets the sqlite3 trace callback of each connection, because sqlite3 has no event for statements. See [Limits](/python/reference/limits.md) and the [Limitations of ormaos-python](https://github.com/ormaos/ormaos-python#limitations).

## Fail open

If Ormaos fails, the program runs unchanged: every callback is guarded, and on an internal error recording stops and the reason goes to `not_collected`. A test of ormaos-python runs the demo with and without Ormaos and compares stdout, stderr and the exit code.

## A recording that is not complete

The recorder writes while the program runs, so a recording can be read while the program is still running, and after `kill -9`. Each recording has a state: `complete`, `incomplete` or `in progress`. For every process that a signal ended, `ormaos show` says which signal and who sent it:

```console
$ ormaos run -- python term.py
ormaos: r3 (incomplete) exit 143 (signal 15) in …: 1 Python process, 1 call, 0 exceptions
ormaos: not collected: the last events of process …: it was ended by the program (process 1) with signal 15 before it had written everything: what it wrote is here, the calls that had not returned are marked open, and up to 256 records or what happened in its last 0.2 seconds can be missing
ormaos: saved in .ormaos/r3, next: ormaos tree r3:c1
# exit code 143
```

---

Source: https://docs.ormaos.com/python/concepts/recording/ · ormaos 0.0.1 · ormaos-python 968f69776c · ormaos-examples 6e27be5922
