Sessions and user context
Session Recording
See the Session Recording Guide for installation steps and examples.
Error Reporting
Report handled errors, caught exceptions, or custom error messages manually — this is separate from the automatic crash / unhandled-exception capture. Each call produces an error event in RUM.
// An NSException you caught
coralogixRum.reportError(exception: someNSException)
// A Swift Error / NSError
do {
try riskyOperation()
} catch {
coralogixRum.reportError(error: error)
}
// A custom message with optional structured data
coralogixRum.reportError(message: "Checkout failed",
data: ["cart_size": 3, "reason": "timeout"])
// Bundle an error together with structured `data` and per-event `labels`
// in a single call — no separate log() needed.
coralogixRum.reportError(error: error,
data: ["cart_size": 3, "reason": "timeout"],
labels: ["team": "payments"])
data and labels are optional on every reportError(error:), reportError(error: NSError), and reportError(exception:) overload. data is attached to the error event and labels are merged into the event's labels.
User Context
Attach the current user's identity to every subsequent event. Call it after sign-in; pass a new UserContext to replace it (e.g. on account switch), and an empty context (or nil) to clear it on sign-out.
coralogixRum.setUserContext(
userContext: UserContext(userId: "user-123",
userName: "Jane Doe",
userMetadata: ["plan": "premium", "role": "admin"])
)
Each call — including a clear — also promotes the next exported event to a snapshot event carrying the new identity, so session-level user information in Coralogix refreshes immediately instead of waiting for the next error, navigation, or one-minute snapshot.
New Session on Logout
Force-start a fresh RUM session on demand — typically on user logout — without a full shutdown() + init(). A new session ID is issued and the per-session state (views, error/click counters, snapshot throttle, Session Replay) resets, exactly like the automatic idle / max-age rotation.
// e.g. when the user logs out
coralogixRum.createNewSession()
On a logout → login flow, pair it with setUserContext for the new user. The current view carries into the new session automatically (as view #0), so events keep their view context without any extra call.