Skip to main content

API reference

API Reference

User Context

Attach or retrieve user-level context to correlate events.

CoralogixRum.setUserContext(
UserContext(
userId = "12345",
username = "john_doe",
email = "user@example.com",
metadata = mapOf("country" to "USA")
)
)

val context: UserContext = CoralogixRum.getUserContext()
Note

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()
Note

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()
Note

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:

SeverityLevel
CoralogixLogSeverity.Debug1
CoralogixLogSeverity.Verbose2
CoralogixLogSeverity.Info3
CoralogixLogSeverity.Warn4
CoralogixLogSeverity.Error5
CoralogixLogSeverity.Critical6

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 startTimeMeasure is called a second time with the same name before endTimeMeasure, the second call is a no-op and the original start time is preserved.
  • Labels are merged with SDK-level labels. Labels passed to startTimeMeasure are merged with CoralogixOptions.labels (call-site labels take priority on conflicts).
  • Session idle discards in-flight measurements. If the session goes idle between start and end, the measurement is silently dropped and endTimeMeasure is a no-op.
  • Unmatched endTimeMeasure is a no-op. Calling endTimeMeasure without a prior startTimeMeasure (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()
Last updated on