SessionCapture

class SessionCapture(maxActions: Int = 1000, maxLogicEvents: Int = 2000)

Captures session data for crash reports and manual export.

Events are stored in file-backed JSONL storage (when filesystem is available) to avoid holding large state snapshots in memory. Falls back to in-memory storage on platforms without filesystem access (e.g., wasmJs browser).

Usage:

val capture = SessionCapture(maxActions = 500, maxLogicEvents = 1000)
capture.start("client-id", "MyApp", "Android")

// Capture events as they happen (typically called by middleware/observers)
capture.captureAction(actionEvent)
capture.captureLogicStarted(logicEvent)

// Manual export (no crash)
val json = capture.exportSession()

// Export with crash info
val crashJson = capture.exportCrashSession(exception)

The exported JSON format is compatible with DevTools ghost device import.

Parameters

maxActions

Maximum number of actions to retain (older actions are dropped)

maxLogicEvents

Maximum number of logic events to retain (older events are dropped)

Constructors

Link copied to clipboard
constructor(maxActions: Int = 1000, maxLogicEvents: Int = 2000)

Functions

Link copied to clipboard

Captures an action dispatched event.

Link copied to clipboard

Captures crash information from a logic method failure. This should be called when a logic failure represents a fatal crash.

Link copied to clipboard

Captures crash information from a throwable. This is typically called by the crash handler for uncaught exceptions.

Link copied to clipboard
fun captureInitialState(stateJson: String)

Captures the initial full state snapshot at session start.

Link copied to clipboard

Captures a logic method completed event.

Link copied to clipboard

Captures a logic method failed event.

Link copied to clipboard

Captures a logic method started event.

Link copied to clipboard
fun clear()

Clears all captured data but keeps the session active.

Link copied to clipboard

Exports the current session with crash information as a JSON string. Captures the crash from the throwable before exporting.

Link copied to clipboard

Exports the current session as a JSON string. Automatically includes any captured crash information.

Link copied to clipboard

Exports the current session as a JSON string, including crash info from parameters. This is kept for DevTools compatibility where crash info is created externally.

Link copied to clipboard

Gets the captured crash info if any.

Link copied to clipboard

Gets the client ID for this session.

Link copied to clipboard

Gets the captured initial state JSON.

Link copied to clipboard

Gets the current session history.

Link copied to clipboard

Checks if session capture has been started.

Link copied to clipboard
fun start(clientId: String, clientName: String, platform: String)

Starts a new session capture.

Link copied to clipboard
fun stop()

Stops the session capture.