# `PhoenixDevToolbar.Event`
[🔗](https://github.com/zoten/phoenix_dev_toolbar/blob/0.0.2/lib/phoenix_dev_toolbar/event.ex#L1)

One recorded fact: a query, a callback, a request ([ADR 05](https://github.com/zoten/phoenix_dev_toolbar/blob/main/adr/05-plugin-behaviour.md)).

Plugins build events with `new/4` in `c:PhoenixDevToolbar.Plugin.collect/3`.
`plugin` is the plugin's id, `kind` an atom of the plugin's choosing, `data`
a map that must already be bounded (see `PhoenixDevToolbar.Truncate`): it is
stored as is. `sid` and `seq` are set by the toolbar on insert; `plugin` and
`span` (the callback span, see `PhoenixDevToolbar.Context`) are stamped by the
collector: `span` is nil only on an event not recorded yet.

# `t`

```elixir
@type t() :: %PhoenixDevToolbar.Event{
  at: integer(),
  data: map(),
  duration: non_neg_integer() | nil,
  kind: atom(),
  plugin: atom(),
  seq: pos_integer() | nil,
  sid: String.t() | nil,
  span: non_neg_integer() | nil
}
```

# `native_to_us`

```elixir
@spec native_to_us(integer() | nil) :: non_neg_integer() | nil
```

Converts a native time duration to microseconds, passing `nil` through.

    iex> PhoenixDevToolbar.Event.native_to_us(nil)
    nil

    iex> PhoenixDevToolbar.Event.native_to_us(System.convert_time_unit(3, :millisecond, :native))
    3000

# `new`

```elixir
@spec new(atom(), atom(), map(), keyword()) :: t()
```

Builds an event stamped with the current system time in microseconds.

`:duration` is given in native time units (as `:telemetry` reports it) and
stored in microseconds.

---

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