# `Supertester.TelemetryHelpers`
[🔗](https://github.com/nshkrdotcom/supertester/blob/v0.6.0/lib/supertester/telemetry_helpers.ex#L1)

Async-safe telemetry testing helpers with per-test event isolation.

# `assert_opts`

```elixir
@type assert_opts() :: [{:timeout, pos_integer()}]
```

# `attach_opts`

```elixir
@type attach_opts() :: [
  filter_key: atom(),
  passthrough: boolean(),
  buffer: boolean(),
  transform: (telemetry_message() -&gt; term())
]
```

# `event`

```elixir
@type event() :: [atom()]
```

# `handler_id`

```elixir
@type handler_id() :: String.t()
```

# `measurements`

```elixir
@type measurements() :: map()
```

# `metadata`

```elixir
@type metadata() :: map()
```

# `telemetry_message`

```elixir
@type telemetry_message() :: {:telemetry, event(), measurements(), metadata()}
```

# `test_id`

```elixir
@type test_id() :: integer()
```

# `assert_telemetry_count`

```elixir
@spec assert_telemetry_count(
  event() | (event() -&gt; boolean()),
  pos_integer(),
  assert_opts()
) :: [
  telemetry_message()
]
```

Assert exactly `expected_count` telemetry events were received.

# `attach_isolated`

```elixir
@spec attach_isolated(event() | [event()], attach_opts()) :: {:ok, handler_id()}
```

Attach a telemetry handler that only receives events matching the current test ID.

# `current_test_metadata`

```elixir
@spec current_test_metadata() :: map()
```

Return metadata map containing the current test's telemetry ID.

# `current_test_metadata`

```elixir
@spec current_test_metadata(map()) :: map()
```

Merge the current test's telemetry metadata into an existing map.

# `detach_isolated`

```elixir
@spec detach_isolated(handler_id()) :: :ok
```

Detach a telemetry handler attached via `attach_isolated/2` and release any
associated buffered state.

# `emit_with_context`

```elixir
@spec emit_with_context(event(), measurements(), metadata()) :: :ok
```

Emit a telemetry event with the current test's context.

# `flush_buffered_telemetry`

```elixir
@spec flush_buffered_telemetry(handler_id()) :: [telemetry_message()]
```

Flush buffered telemetry messages for a handler created with `buffer: true`.

# `flush_telemetry`

```elixir
@spec flush_telemetry(:all | event()) :: [telemetry_message()]
```

Flush telemetry messages from the mailbox.

# `get_test_id`

```elixir
@spec get_test_id() :: test_id() | nil
```

Retrieve the current test's telemetry ID.

# `get_test_id!`

```elixir
@spec get_test_id!() :: test_id()
```

Retrieve the current test's telemetry ID or raise if missing.

# `setup_telemetry_isolation`

```elixir
@spec setup_telemetry_isolation() :: {:ok, test_id()}
```

Initialize telemetry isolation for the current process.

# `setup_telemetry_isolation`

```elixir
@spec setup_telemetry_isolation(Supertester.IsolationContext.t()) ::
  {:ok, test_id(), Supertester.IsolationContext.t()}
```

Initialize telemetry isolation and update the isolation context.

# `with_telemetry`

```elixir
@spec with_telemetry(event() | [event()], (-&gt; result), attach_opts()) ::
  {result, [telemetry_message()]}
when result: term()
```

Execute a function and capture emitted telemetry events.

---

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