API reference
API Reference
User Context
Attach or retrieve user-level context to correlate events.
CoralogixRum.setUserContext(
UserContext(
userId = "12345",
username = "john_doe",
metadata = mapOf("country" to "USA")
)
)
val context: UserContext = CoralogixRum.getUserContext()
the getUserContext returns a UserContext object with empty values if the Coralogix SDK is not initialized.
Application Context
Attach application context to correlate events.
CoralogixRum.setApplicationContext(
appName = "MyApp",
appVersion = "1.0.0"
)
Session ID
Retrieve the session id from the SDK.
val sessionId: String = CoralogixRum.getSessionId()
the getSessionId returns an empty String if the Coralogix SDK is not initialized.
New Session
Force-start a fresh RUM session on demand — typically on user logout — without re-initializing the SDK. A new session id is issued and the per-session state (snapshot state, error/action counts, Session Replay, view counter) resets, exactly like the automatic idle / max-age rotation.
CoralogixRum.createNewSession()
On a logout → login flow, pair it with setUserContext for the new user. Events in the new session keep the current view name; view_number restarts from the current view — it is re-stamped as view 0 immediately, so events on the current screen keep carrying view_number, and the next navigation to a different screen increments it to 1.
Labels
Attach or retrieve global labels applied to all events.
CoralogixRum.setLabels(
mapOf("environment" to "staging", "buildType" to "debug")
)
val labels: Map<String, Any?> = CoralogixRum.getLabels()
the getLabels returns an empty map if the Coralogix SDK is not initialized.
View Context
Attach a view context to correlate events.
CoralogixRum.setViewContext(viewName = "Main View")
Logging
Send structured logs with optional data and labels.
CoralogixRum.log(
severity = CoralogixLogSeverity.Info,
message = "User logged in successfully",
data = mapOf("userId" to "12345"), // optional
labels = mapOf("environment" to "staging") // optional
)
CoralogixLogSeverity is a sealed class with six levels:
| Severity | Level |
|---|---|
CoralogixLogSeverity.Debug | 1 |
CoralogixLogSeverity.Verbose | 2 |
CoralogixLogSeverity.Info | 3 |
CoralogixLogSeverity.Warn | 4 |
CoralogixLogSeverity.Error | 5 |
CoralogixLogSeverity.Critical | 6 |
Custom Measurements
Send arbitrary key-value pairs.
CoralogixRum.sendCustomMeasurement("image_upload_time_ms", 1480L)
Custom Time Measurement
Measure the duration of any operation by wrapping it with startTimeMeasure / endTimeMeasure. The SDK records the elapsed time and emits a Measurement event with the duration in milliseconds.
// Start timing — optionally attach labels that will appear on the event
CoralogixRum.startTimeMeasure("checkout-flow", mapOf("cart.items" to 3))
// … perform the operation …
// Stop timing — emits the measurement event
CoralogixRum.endTimeMeasure("checkout-flow")
Behaviour
- Duplicate starts are ignored. If
startTimeMeasureis called a second time with the same name beforeendTimeMeasure, the second call is a no-op and the original start time is preserved. - Labels are merged with SDK-level labels. Labels passed to
startTimeMeasureare merged withCoralogixOptions.labels(call-site labels take priority on conflicts). - Session idle discards in-flight measurements. If the session goes idle between
startandend, the measurement is silently dropped andendTimeMeasureis a no-op. - Unmatched
endTimeMeasureis a no-op. CallingendTimeMeasurewithout a priorstartTimeMeasure(or after the measurement was already ended) does nothing.
Error Reporting
Report handled or unhandled exceptions.
try {
riskyOperation()
} catch (t: Throwable) {
CoralogixRum.reportError(t)
}
Shutdown
Gracefully shut down the SDK when your app is terminated.
CoralogixRum.shutdown()