PhoenixReplay.Storage behaviour (PhoenixReplay v0.2.0)

Copy Markdown View Source

Behaviour for persistent recording storage backends.

Active (in-flight) recordings always live in ETS for performance. When a LiveView process exits, the recording is finalized and persisted through the configured storage backend.

Built-in backends

Configuration

config :phoenix_replay,
  storage: PhoenixReplay.Storage.File,
  storage_opts: [
    path: "priv/replay_recordings",
    format: :etf  # or :json
  ]

Serialization formats

  • :etf — Erlang External Term Format (:erlang.term_to_binary/1). Fast, compact, preserves all Elixir types. Default.
  • :json — JSON via Jason. Portable, human-readable, but lossy for atoms, tuples, and structs.

Summary

Callbacks

Delete all recordings.

Delete a recording by ID.

Retrieve a recording by ID.

Initialize the backend (create tables, directories, etc).

List all recordings, most recent first.

List lightweight recording summaries, most recent first.

Persist a finalized recording.

Functions

Returns the configured storage backend module.

Returns the configured storage options.

Types

opts()

@type opts() :: keyword()

Callbacks

clear(opts)

@callback clear(opts()) :: :ok

Delete all recordings.

delete(binary, opts)

@callback delete(binary(), opts()) :: :ok | {:error, term()}

Delete a recording by ID.

get(binary, opts)

@callback get(binary(), opts()) :: {:ok, PhoenixReplay.Recording.t()} | :error

Retrieve a recording by ID.

init(opts)

@callback init(opts()) :: :ok | {:error, term()}

Initialize the backend (create tables, directories, etc).

list(opts)

@callback list(opts()) :: [PhoenixReplay.Recording.t()]

List all recordings, most recent first.

list_summaries(opts)

(optional)
@callback list_summaries(opts()) :: [map()]

List lightweight recording summaries, most recent first.

save(t, opts)

@callback save(PhoenixReplay.Recording.t(), opts()) :: :ok | {:error, term()}

Persist a finalized recording.

Functions

backend()

Returns the configured storage backend module.

storage_opts()

Returns the configured storage options.