WebsockexNova.Gun.Helpers.StateTracer (WebsockexNova v0.1.1)
View SourceProvides detailed tracing capabilities for connection state transitions.
This module implements event tracing for WebSocket connection state changes, allowing for easier debugging and monitoring of the connection lifecycle.
Features:
- Records all state transitions with timestamps
- Tracks connection statistics (uptime, reconnection frequency)
- Provides a searchable history of connection events
- Can output trace events to a file or monitoring system
- Supports optional correlation IDs for distributed tracing
Summary
Functions
Exports the trace history to a file.
Gets connection statistics from the trace context.
Gets the full trace history from the connection state.
Initializes a new trace context in the connection state.
Traces a state transition event.
Functions
@spec export_trace(WebsockexNova.Gun.ConnectionState.t(), Path.t()) :: :ok | {:error, term()}
Exports the trace history to a file.
Parameters
state
- The connection statepath
- File path for the export
Returns
:ok
on success, {:error, reason}
on failure
@spec get_statistics(WebsockexNova.Gun.ConnectionState.t()) :: map()
Gets connection statistics from the trace context.
Parameters
state
- The connection state
Returns
Map of connection statistics
@spec get_trace_history(WebsockexNova.Gun.ConnectionState.t()) :: [map()]
Gets the full trace history from the connection state.
Parameters
state
- The connection state
Returns
List of trace events in chronological order (oldest first)
@spec init_trace(WebsockexNova.Gun.ConnectionState.t(), String.t() | nil) :: map()
Initializes a new trace context in the connection state.
Parameters
state
- The current connection statetrace_id
- Optional trace ID for distributed tracing (generates one if nil)
Returns
Updated connection state with trace context
@spec trace_transition( WebsockexNova.Gun.ConnectionState.t(), atom(), atom(), atom(), map() ) :: map()
Traces a state transition event.
Parameters
state
- The current connection stateevent_type
- The type of event (:connect, :disconnect, :upgrade, etc.)from_status
- Previous connection statusto_status
- New connection statusmetadata
- Additional contextual information about the event
Returns
Updated connection state with the event recorded