The Telemetry interface provides a unified way to track application events, log non-fatal errors, and leave breadcrumbs for debugging. It abstracts the underlying crash reporting implementation (such as Bugsnag) and respects the crashReportingEnabled setting from AppPreferences.
Methods
initialize(): Sets up the telemetry system. If crash reporting is disabled in AppPreferences, this method does nothing.logNonFatal(e: Throwable): Logs a non-fatal error. It always logs the error to Logcat at ERROR priority, but only notifies the crash reporting service (e.g., Bugsnag) if crashReportingEnabled is true.leaveBreadcrumb(message: String, metadata: Map<String, Any>, type: BreadcrumbType): Adds a breadcrumb to the session to help reconstruct the state leading up to an error. Breadcrumbs are only sent to the crash reporting service if crashReportingEnabled is true.
Breadcrumb Types
When calling leaveBreadcrumb, use one of the following BreadcrumbType values to categorize the event:
Navigation: For tracking screen transitions.State: For tracking changes in application state.UserAction: For tracking specific user interactions.
// Example usage of Telemetry
telemetry.initialize()
try {
// ... some operation
} catch (e: Throwable) {
telemetry.logNonFatal(e)
}
telemetry.leaveBreadcrumb(
message = "User clicked login button",
metadata = mapOf("button_id" to "login_btn"),
type = Telemetry.BreadcrumbType.UserAction
)