PhoenixReplay.Recorder (PhoenixReplay v0.6.2)

Copy Markdown View Source

on_mount hook that records LiveView sessions.

live_session :default, on_mount: [PhoenixReplay.Recorder] do
  live "/dashboard", DashboardLive
end

Options given as {PhoenixReplay.Recorder, opts} override the PhoenixReplay.Config values for that live session. :sample_rate, :keep, :max_events, :sanitizer, :redact, :flush, :pointer and :state are accepted:

live_session :checkout,
  on_mount: [{PhoenixReplay.Recorder, keep: [rate: 0.1, errors: true]}] do
  live "/checkout", CheckoutLive
end

Recording starts on the connected mount. Lifecycle hooks capture events, params changes, handle_info/2 message tags, and the assigns changed by each render, all passed through the configured PhoenixReplay.Sanitizer. While :max_memory is exceeded, new sessions are not recorded. Events are written by the LiveView process itself into PhoenixReplay.Session.Buffer; PhoenixReplay.Session.Monitor saves the recording once the process exits.

Recorder state lives in socket.private, so the view's assigns are left untouched.

When the host app sends PhoenixReplay's client context, the recording also holds the browser's viewport, user agent, tab and the URL the user came from; see PhoenixReplay.Capture.Browser.

On the connected mount of a recorded session, the recorder pushes a "phx_replay:record" event with what the browser should record: %{pointer: settings | nil, state: settings | nil}. The client module's replayRecorder/1 starts on it and sends pointer batches and client state back, which the recorder records and halts; see PhoenixReplay.Capture.Pointer and PhoenixReplay.Capture.State.

Summary

Functions

Starts recording on the connected mount, for the sampled share of sessions.

Decides whether a session is recorded at rate, given a uniform draw in 0.0..1.0. Rates of 0.0 and 1.0 never consult the draw.

Functions

on_mount(opts, params, session, socket)

@spec on_mount(
  :default | keyword(),
  map() | :not_mounted_at_router,
  map(),
  Phoenix.LiveView.Socket.t()
) ::
  {:cont, Phoenix.LiveView.Socket.t()}

Starts recording on the connected mount, for the sampled share of sessions.

Takes :default or a keyword list of live-session options.

sampled?(rate, draw \\ :rand.uniform())

@spec sampled?(float(), float()) :: boolean()

Decides whether a session is recorded at rate, given a uniform draw in 0.0..1.0. Rates of 0.0 and 1.0 never consult the draw.