SessionCapture
Captures session data for crash reports, manual export, and DevTools streaming.
SessionCapture is the shared nexus for all tooling signals: dispatched actions, traced logic events, and crashes all flow through this single instance. Capture calls only enqueue a record; a background worker performs JSON encoding and storage writes off the dispatch path, batching consecutive records into single storage writes.
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.captureDispatchedAction(action, resultState)
capture.captureLogicStarted(logicEvent)
// Crashes are reported once and fan out to every consumer
capture.reportCrash(exception)
// Manual export (flushes pending records first)
val json = capture.exportSession()The exported JSON format is compatible with DevTools ghost device import.
Parameters
Maximum number of actions to retain (older actions are dropped)
Maximum number of logic events to retain (older events are dropped)
Properties
Live stream of captured actions, emitted by the worker after encoding. DevTools consumes this instead of re-serializing state per action.
Functions
Provides the store's serializers so the worker can encode module states. Called by ToolingLogic during initialization.
Captures a pre-built action event.
Captures a dispatched action and its resulting module state. State encoding happens on the worker, off the dispatch path.
Captures the initial full state snapshot at session start. Encoding happens on the worker, off the dispatch path.
Captures a logic method completed event.
Captures a logic method failed event.
Captures a logic method started event.
Encodes a state tree one module at a time with the encoder the capture uses for its deltas.
Reports the throwable as a crash and exports the session including it. Typically called by platform crash handlers for uncaught exceptions.
Exports the current session as a JSON string.
Gets the captured crash info if any.
Gets the client ID for this session.
Gets the captured initial state JSON.
Gets the current session history.
Records a completed network exchange, materialising its full bodies before they age out.
Reports a crash to the nexus: stores it for export and emits it on crashes.
Reports a crash from a throwable.
Suggests an export file name carrying client identity and app version. The prefix defaults to crash when a crash has been captured, session otherwise.