PhoenixReplay.Capture.ViewEvents (PhoenixReplay v0.6.2)

Copy Markdown View Source

Records the events a LiveView handles, from LiveView's telemetry.

LiveView emits [:phoenix, :live_view, :handle_event, :start] around the whole of an event, its on_mount hooks included, with the socket and params. Recording from it rather than from a hook of the recorder's means an app hook that handles an event and halts, wherever it sits in on_mount, still has its event recorded.

The handler runs in the LiveView process and finds its session in PhoenixReplay.Session.Buffer, so a LiveView that is not recorded costs one ETS lookup per event. It records :event, %{name: String.t(), params: map}, with the params through the session's PhoenixReplay.Sanitizer, and the viewport they carry as a :viewport event; see PhoenixReplay.Capture.Browser.observe/1. The events the recorder's own script sends, the pointer, state and viewport, are recorded by PhoenixReplay.Recorder instead.

Like the other handlers, it reports a failure with [:phoenix_replay, :collector, :exception] rather than raise, which would detach it for the whole application.

Summary

Functions

Attaches the telemetry handler. Called by PhoenixReplay.Capture.Handlers.

Detaches the telemetry handler, if attached.

Records a LiveView's event in its process. A failure, such as a custom sanitizer raising, is reported with PhoenixReplay.Telemetry.collector_failed/5 instead of raised.

Functions

attach()

@spec attach() :: :ok | {:error, :already_exists}

Attaches the telemetry handler. Called by PhoenixReplay.Capture.Handlers.

detach()

@spec detach() :: :ok

Detaches the telemetry handler, if attached.

handle_event(event, measures, metadata, handler_config)

@spec handle_event([atom()], map(), map(), term()) :: :ok

Records a LiveView's event in its process. A failure, such as a custom sanitizer raising, is reported with PhoenixReplay.Telemetry.collector_failed/5 instead of raised.