# `Arcadic.Telemetry`
[🔗](https://github.com/baselabs/arcadic/blob/baselabs_arcadic-v4.0.1/lib/arcadic/telemetry.ex#L5)

Defines the telemetry spans and events emitted by Arcadic. The wrapper
checks metadata keys against `allowed_meta_keys/0`. Arcadic does not
include statement text, parameters, row values, or database names.

## Spans

All spans use `[:arcadic, operation, phase]`, with phases `:start`,
`:stop`, and `:exception`. Span timing and exception fields come from
`:telemetry.span/3`.

| Operation | Calls |
| --- | --- |
| `:query` | Statement reads, including bookmarked reads. |
| `:command` | Writes, bookmarked writes, and asynchronous submission. |
| `:explain` | Plan inspection and profiling. |
| `:transaction` | Managed transactions. |
| `:admin` | Server, security, and backup operations that use the admin wrapper. |
| `:bulk`, `:ingest`, `:record` | Batch ingest, document ingest, and record operations. |
| `:timeseries` | Time-series wire operations. |

Query, command, and plan start metadata includes language and mode.
Synchronous writes and profiling also report `:in_transaction?`.
Asynchronous submissions use `:async?` and have no row count. A successful
synchronous statement stop adds HTTP status, reason, and row count.
A failed statement stop adds the reason.

Transaction spans include `:isolation`. Admin spans include `:operation`
and a stop reason. Exception events include the metadata from the start
plus the telemetry library's kind, reason, and stacktrace.

## Events

| Event | Measurements and metadata |
| --- | --- |
| `[:arcadic, :query_stream, :start]` | HTTP and Bolt streams. Read mode metadata. |
| `[:arcadic, :query_stream, :stop]` | HTTP and Bolt streams. Row count measurement and an `:ok` or `:halted` reason. |
| `[:arcadic, :transaction, :retry]` | Attempt measurement and retry reason. |
| `[:arcadic, :vector, :sparse_index_preexisting]` | Count of pre-existing rows reported by the server. |
| `[:arcadic, :changes, :dropped]` | Count of dropped events and `:changes` operation metadata. |

See `Arcadic.Changes` for connection lifecycle events.

# `allowed_meta_keys`

```elixir
@spec allowed_meta_keys() :: [atom()]
```

The permitted span metadata keys.

# `event`

```elixir
@spec event([atom(), ...], map(), map()) :: :ok
```

Emit a manual `:telemetry.execute/3` event with allowlist-validated metadata, for
lazy operations (streaming) whose lifetime does not fit `span/3`'s synchronous
callback. Off-allowlist metadata keys raise (no statement/params/values/db name).

# `span`

```elixir
@spec span(atom(), map(), (-&gt; {term(), map()})) :: term()
```

Runs `fun` inside `:telemetry.span([:arcadic, op], …)`. `fun` returns
`{result, stop_meta}`; every start/stop metadata key MUST be in the allowlist or
an `ArgumentError` is raised.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
