MetricsService

Service for sending OpenTelemetry metrics to OTLP endpoint Completely failsafe - all operations are non-blocking and errors are silently handled Singleton object like SentryHelper for direct access

Functions

Link copied to clipboard
fun initialize(context: Context)

Initialize the metrics service. Should be called once during SDK initialization.

Link copied to clipboard

Send device information metrics on SDK initialization

Link copied to clipboard
fun sendEvent(metric: MetricKeys, value: Long = 1, labels: Map<String, String> = emptyMap())

Send a metric event with optional labels COMPLETELY FAILSAFE - will never crash or block

Link copied to clipboard
fun sendGaugeMetric(metric: MetricKeys, value: Long, labels: Map<String, String> = emptyMap())

Send a gauge metric (for values that can go up or down) Used for things like duration, memory usage, active connections

Link copied to clipboard
fun setBotKey(key: String)

Update bot_key when SDK initializes

Link copied to clipboard
fun setBotName(name: String)

Update bot_name when settings load

Link copied to clipboard
fun setChatId(chatId: String)

Update chat_id when chat session starts

Link copied to clipboard
fun setEnabled(enabled: Boolean)

Enable or disable metrics sending (INTERNAL USE ONLY) Set synchronously to avoid race condition where sendEvent() checks isEnabled before the async coroutine has set it. This ensures metrics sent immediately after setEnabled(true) are not silently dropped.

Link copied to clipboard

Enable or disable app lifecycle event tracking (foreground/background) Call this when SDK starts (true) or disconnects (false)

Link copied to clipboard

Check if app lifecycle tracking is enabled

Link copied to clipboard
fun trackAPIRequest(endpoint: String, method: String, statusCode: Int)
Link copied to clipboard
fun trackButtonClick(buttonId: String, screen: String)
Link copied to clipboard
fun trackChatMessage(direction: String, messageType: String, sender: String? = null)
Link copied to clipboard
fun trackCurrentScreenTap(x: Float, y: Float, screenWidth: Int, screenHeight: Int)
Link copied to clipboard
fun trackCustomEvent(eventType: String, category: String? = null, action: String? = null, detail: String? = null)
Link copied to clipboard
fun trackError(errorType: String, errorCode: String? = null, screen: String? = null)
Link copied to clipboard
fun trackScreenTap(screenName: String, x: Float, y: Float, screenWidth: Int, screenHeight: Int)
Link copied to clipboard
fun trackScreenView(screenName: String, previousScreen: String? = null, duration: Int? = null)
Link copied to clipboard
fun trackScroll(screenName: String, direction: String)
Link copied to clipboard
fun trackSessionEnd(reason: String, duration: Int)
Link copied to clipboard
Link copied to clipboard
fun trackSocketStatus(status: String, reconnectAttempt: Int = 0)