# Sessions and user context

Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fapple%2Fios%2Ffeatures%2Fsessions-and-user-context.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fapple%2Fios%2Ffeatures%2Fsessions-and-user-context.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

### Session Recording[​](#session-recording "Direct link to Session Recording")

See the [Session Recording Guide](https://coralogix.com/docs/user-guides/rum/sdk-installation/apple/ios/SessionReplay/Sources/Docs.md) for installation steps and examples.

### Error Reporting[​](#error-reporting "Direct link to 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[​](#user-context "Direct link to 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",

                             userEmail: "jane.doe@example.com",

                             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[​](#new-session-on-logout "Direct link to 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.
