TelemetryCollector

Collects execution metrics for background tasks.

Install a TelemetryCollector on your KmpWorker to track execution timing, success rates, retry counts, and error patterns across all tasks.

val telemetry = SqlDelightTelemetryCollector(database)
val worker = AndroidKmpWorker(context, telemetry = telemetry)

// Query history
val records = telemetry.getHistory(limit = 50)
val failedRecords = telemetry.getHistory(limit = 10, stateFilter = "FAILED")

Functions

Link copied to clipboard
abstract suspend fun clearHistory()

Removes all execution history records.

Link copied to clipboard
abstract suspend fun getHistory(limit: Int = 100, stateFilter: String? = null): List<ExecutionRecord>

Returns execution records, most recent first.

Link copied to clipboard
abstract suspend fun onTaskCompleted(taskId: String, state: TaskState, timestamp: Long, retryCount: Int)

Records the completion of a task execution.

Link copied to clipboard
abstract suspend fun onTaskStarted(taskId: String, timestamp: Long)

Records the start of a task execution.

Link copied to clipboard
abstract suspend fun pruneHistory(olderThanMillis: Long)

Removes records older than olderThanMillis milliseconds.