Skip to content

Android

This guide shows you how to easily integrate the Coralogix RUM SDK into your native Android apps.

Coralogix Android SDK supports Android 7.0+ (API level 24) and above.

Features

In addition to capturing errors, including ANRs, this SDK can intercept network calls (supported only for OkHttpClient), send log messages with customized severity levels, report errors, and track your customers' page transitions.

Installation

STEP 1. Add the Maven Central Repository to your project. Then, add the dependency to your module's build.gradle.

dependencies {
    implementation 'com.coralogix:android-sdk:1.0.2'
}

STEP 2. Sync your project.

Note: If you encounter a dependency that requires Java 8+ APIs, such as enabling core library desugaring to ensure compatibility across Android versions, see Troubleshooting for next steps.

Initialization

Initialize the Coralogix SDK with the application context.

In the initialization snippet, set mandatory fields: applicationName, coralogixDomain, publicKey, environment.

import com.coralogix.android.sdk.CoralogixDomain
import com.coralogix.android.sdk.CoralogixOptions
import com.coralogix.android.sdk.CoralogixRum

val config = CoralogixOptions(
    applicationName = "MyApp",
    coralogixDomain = CoralogixDomain.EU2,
    publicKey = "my_public_key",
    environment = "dev"
)

class DemoApplication : Application() {
    override fun onCreate() {
        super.onCreate()
       CoralogixRum.initialize(this, config)
    }

}

Refer to the following fields for CoralogixOptions.

PropertyTypeDescriptionRequiredExample
applicationNameStringName of the applicationYes"MyApp"
coralogixDomainCoralogixDomainThe region associated with your Coralogix domainYesUS1, US2, EU1, EU2, API, AP2, AP3
publicKeyStringCoralogix token, publicly visible public_key valueYes"my_public_key"
labelsMap<String,String>An optional set of labels that are added to every span for enrichment purposesNolabels = mapOf("payment" to "visa")
environmentStringSpecify the environment, such as development, staging, or productionYes"production"
versionStringVersion of the applicationNo"v.1.0"
userContextUserContextUser context information, such as user ID, name, email, and additional metadataNoUserContext(user_id = "123", user_name = "User", user_email = "[email protected]", user_metadata = mapOf("role" to "Admin"))
view_contextViewContextDescription of current activityNo"MyActivityName"
instrumentationsMap<InstrumentationKeys, Boolean>Map to turn on/off specific instrumentation. Defaults to all true.Noinstrumentations = mapOf(InstrumentationKeys.NETWORK to false)
ignoreUrlsList<String>A list of URLs to ignore for logging and monitoring purposes. Supports strings and regular expressions for matching.NoignoreUrls = listOf("https://jsonplaceholder\\.typicode\\.com/.*", ".*\\.svg", ".*\\.ico")
ignoreErrorsList<String>List of error patterns to be ignored for logging and monitoring. Supports strings and regular expressions for matching.NoignoreErrors = listOf("^IllegalArgumentException$", "IOException", "ANR")
collectIPDataBooleanAllow the option to send IP address to identify session country. Defaults to true.Notrue
sessionSampleRateNumberPercentage of overall sessions being tracked. Defaults to 100%.No100%
traceParentInHeaderBooleanAdd trace context propagation in headers across service boundaries. Defaults to false.Notrue
fpsSamplingMinutesNumberInterval (in minutes) for collecting and logging frame rate data for performance tracking. Defaults to 5 min.No10
beforeSendlambda functionEnable event access and modification before sending to Coralogix, supporting content modification, and event discarding.NobeforeSend = { event -> if (event.userContext?.user_email?.endsWith("@example.com", ignoreCase = true) == true) {event.copy(userContext = event.userContext?.copy(user_email = "sensetive-info",),)} else {event}},

Configuration

Instrumentation

You can enable or disable specific instrumentation features using the instrumentations map. By default, all instrumentations are enabled.

Example

instrumentations = mapOf(
    InstrumentationKeys.NETWORK to false  // Disables network instrumentation
)

InstrumentationKeys enum:

  • ERROR - Monitors error events
  • NETWORK - ntercepts network calls (supported only for OkHttpClient) and, optionally, propagates trace context in headers across service boundaries
  • NAVIGATION - Tracks app navigations
  • ANR - Automatically detects Application Not Responsive (ANR) events
  • MOBILE VITALS – Automatically tracks cold/warm start times and Frame Rate (FPS)

Ignoring errors and URLs

  • Ignore errors: Use ignoreErrors to exclude errors matching specific criteria. Supports strings and regular expressions.
    "^IllegalArgumentException$",
         "IOException",
         "ANR"
  • Ignore URLs: Use ignoreUrls to exclude URLs matching specific patterns from being traced.
"<https://jsonplaceholder>\\\\.typicode\\\\.com/.*",
        ".*\\\\.svg",
        ".*\\\\.ico",

Network interception

To enable RUM to intercept network events, add CoralogixOkHttpInterceptor to your OkHttpClient.

Note: Only OkHttpClient is supported currently.

import com.coralogix.android.sdk.okhttp.CoralogixOkHttpInterceptor
import okhttp3.OkHttpClient

object OkHttpClientDemo {
    val client: OkHttpClient = OkHttpClient.Builder()
        .addInterceptor(**CoralogixOkHttpInterceptor**())
        .build()
}

Integration functions

This section lists public functions used to interact with the Coralogix RUM SDK.

Set user context

Provide user context dynamically as user metadata becomes available.

Example

CoralogixRum.setUserContext(
     UserContext(
                user_id = "123",
                user_name = "User User",
                user_email = "[email protected]",
                user_metadata = mapOf("role" to "Admin")
            )
)

Set labels

Update labels dynamically during runtime.

Example

CoralogixRum.setLabels(
    labels = mapOf(
        "environment" to "production",
        "version" to "1.0.2"
    )
)

Set view context

If you track page transitions, the ViewContext will be set to the activity/fragment name by default. Manually update as necessary.

Example

CoralogixRum.setViewContext(
    view_name = "CustomViewName"
)

Log messages

Send log messages with customized severity levels.

Example

CoralogixRum.log(
    CoralogixLogSeverity.Error,
    "Custom log message error"
)

CoralogixLogSeverity defines severity levels for logs in the Coralogix system.

CaseRaw ValueSeverity Level
debug1Debug
verbose2Verbose
info3Informational
warn4Warning
error5Error
critical6Critical

Report errors

Report errors appear in the Coralogix platform with level 5 severity.

Example

CoralogixRum.reportError("custom error")

Troubleshooting

If you encounter a dependency that requires Java 8+ APIs, such as enabling core library desugaring to ensure compatibility across Android versions, do the following:

STEP 1. Update compileOptions by adding the following to your build.gradle file.

android {
    compileOptions {

        **isCoreLibraryDesugaringEnabled = true**
    }

}

STEP 2. Add Desugaring Dependency by including the library in your dependencies.

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
}

This enables modern Java features on older Android versions.

Support

Need help?

Our world-class customer success team is available 24/7 to walk you through your setup and answer any questions that may come up.

Feel free to reach out to us via our in-app chat or by sending us an email to [email protected].