Native Android SDK Integration
Integrate the HEAL EUM SDK with native Android, OkHttp, and Retrofit using privacy-safe defaults.
This section explains how to integrate the HEAL EUM Android SDK into a native Android application that uses OkHttp or Retrofit for API calls. The SDK captures API call traces, adds trace propagation headers, and sends telemetry data to the configured HEAL OTLP Collector endpoint.
Supported Requirements#
| Item | Support |
|---|---|
| Android version | Android 8.0 and above |
| Minimum SDK | Compatible with the minSdk 26 requirement |
| API library | OkHttp supported |
| Retrofit | Supported when Retrofit uses an OkHttpClient with the HEAL interceptor |
| Encrypted API calls | Supported for tracing metadata and configured headers. The SDK does not decrypt request/response payloads |
| Trace propagation | Supports W3C traceparent / tracestate headers |
| Telemetry export | Sends spans to the configured OTLP collector endpoint |
Step 1: Add the SDK Dependency#
Add the HEAL EUM SDK dependency provided by the HEAL team. If an AAR file is provided, place it under the app module, for example:
app/libs/healeum-sdk.aar
Then add the SDK AAR plus its runtime dependencies.
Important
Because healeum-sdk.aar is shared as a local .aar file, Gradle does not automatically download the SDK dependency libraries. The app must declare the dependencies shown below in its own app/build.gradle.kts or app/build.gradle file.
Use the full dependency strings when sharing this guide with application developers:
dependencies {
implementation(files("libs/healeum-sdk.aar"))
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("io.opentelemetry.android:android-agent:0.9.1-alpha")
implementation("io.opentelemetry.android:instrumentation-sessions:0.9.1-alpha")
implementation("io.opentelemetry:opentelemetry-exporter-otlp:1.46.0")
implementation("io.opentelemetry:opentelemetry-api-incubator:1.46.0-alpha")
implementation("androidx.startup:startup-runtime:1.2.0")
implementation("com.google.android.gms:play-services-location:21.1.0")
implementation("androidx.core:core-ktx:1.13.1")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
}
Note
Do not copy internal aliases such as libs.okhttp or libs.android.agent into another project unless that project already defines the same aliases. A Gradle version catalog is an optional file, usually gradle/libs.versions.toml, where a project stores dependency names and versions centrally — implementation(libs.okhttp) only works when libs.okhttp is defined there. A project without the alias must use the full dependency string instead: implementation("com.squareup.okhttp3:okhttp:4.12.0")
Dependency purpose:
| Dependency | Required? | Purpose |
|---|---|---|
com.squareup.okhttp3:okhttp:4.12.0 |
Yes | Required for HealHttpClientInterceptor and API call instrumentation |
io.opentelemetry.android:android-agent:0.9.1-alpha |
Yes | OpenTelemetry Android RUM runtime |
io.opentelemetry.android:instrumentation-sessions:0.9.1-alpha |
Yes | Session instrumentation |
io.opentelemetry:opentelemetry-exporter-otlp:1.46.0 |
Yes | OTLP trace/log export |
io.opentelemetry:opentelemetry-api-incubator:1.46.0-alpha |
Yes | Event/log APIs used by the SDK |
androidx.startup:startup-runtime:1.2.0 |
For manifest auto-init | Needed when using HEALEUMAppStartup. Not needed if the app only calls HEALEUMInstrumentation.install(...) manually |
com.google.android.gms:play-services-location:21.1.0 |
For auto location | Needed only when autoLocationEnabled = true |
androidx.core:core-ktx:1.13.1 |
Yes | Android/Kotlin compatibility helpers used by the SDK |
com.android.tools:desugar_jdk_libs:2.1.4 |
Yes | Required with coreLibraryDesugaring(...) |
Also enable Java 8 desugaring in the app module:
android {
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
Note
If the SDK is provided through Maven or Artifactory, use the dependency coordinates shared by the HEAL team instead of the AAR line.
The SDK package import is:
import com.heal.eum.HEALEUMInstrumentation
Step 2: Android Manifest Permissions#
Add the internet permission. Location permissions are required only if automatic location capture is enabled.
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required only when autoLocationEnabled = true and the approved use case needs it -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Transport security
Use an HTTPS OTLP endpoint in production. If an explicitly approved non-production test requires HTTP, restrict any temporary network-security exception to the collector host and remove it before release.
Privacy-safe defaults
Keep location capture and unrestricted header capture disabled by default. Allowlist only non-sensitive operational attributes approved for monitoring. Never capture authorization headers, cookies, payment data, request or response bodies, mobile numbers, customer identifiers, or other direct personal identifiers.
Step 3: Initialize the HEAL EUM SDK#
Initialize the SDK once during app startup, preferably in the Application class:
import com.heal.eum.HEALEUMInstrumentation
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val cfg = HEALEUMInstrumentation.Config(
httpTracesEndpoint = "https://your-collector-host/v1/traces",
serviceName = "YourApp-android",
debugLoggingEnabled = false,
debugLogHeaders = false,
customVariableKeys = setOf(
"journeyName", "appVersion", "deviceType", "environment"
),
captureAllHeaders = false,
createHttpSpansInInterceptor = true,
autoLocationEnabled = false,
locationIntervalMs = 30_000L,
locationHighAccuracy = false
)
HEALEUMInstrumentation.install(this, cfg)
}
}
Register the Application class in AndroidManifest.xml:
<application
android:name=".MyApplication"
... >
</application>
Warning
Use debugLoggingEnabled = true and debugLogHeaders = true only during testing. Keep both disabled in production unless requested by the HEAL team.
Optional: AndroidX Startup Initialization#
If the app team prefers manifest-based initialization instead of Application.onCreate(), add this provider inside the app's <application> tag:
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false">
<meta-data
android:name="com.heal.eum.HEALEUMAppStartup"
android:value="androidx.startup" />
</provider>
Then add the SDK configuration as manifest metadata:
<meta-data android:name="heal.eum.http.traces"
android:value="https://your-collector-host/v1/traces" />
<meta-data android:name="heal.eum.service.name"
android:value="YourApp-android" />
<meta-data android:name="heal.eum.custom.variables.keys"
android:value="journeyName,appVersion,deviceType,environment" />
<meta-data android:name="heal.eum.createHttpSpansInInterceptor"
android:value="true" />
<meta-data android:name="heal.eum.autoLocation.enabled"
android:value="false" />
<meta-data android:name="heal.eum.autoLocation.intervalMs"
android:value="30000" />
Important
Use either manual initialization or AndroidX Startup — not both.
Step 4: Attach the HEAL Interceptor to OkHttp#
Every OkHttpClient used for API calls must include the HEAL interceptor:
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(HEALEUMInstrumentation.HealHttpClientInterceptor())
.build()
If the application creates multiple OkHttpClient instances, attach the interceptor to each one.
Step 5: Retrofit Integration#
For Retrofit, pass the instrumented OkHttpClient to the Retrofit builder:
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(HEALEUMInstrumentation.HealHttpClientInterceptor())
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build()
Location Capture#
If autoLocationEnabled = true, request the minimum runtime location permission required by the approved use case. When it is false, the SDK must not collect location.
autoLocationEnabled = false
Verification Steps#
After integration:
- Launch the app.
- Perform one API call from the target user journey.
- Check Android Logcat for HEAL EUM startup logs if debug logging is enabled.
- Confirm the API call continues to work normally.
- Confirm spans are received at the OTLP collector.
- Confirm span attributes include the approved non-sensitive values, such as
journeyName,appVersion, andenvironment, and HTTP status. - Confirm backend services receive
traceparentwhen distributed tracing is enabled.
Minimal Example#
import com.heal.eum.HEALEUMInstrumentation
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val cfg = HEALEUMInstrumentation.Config(
httpTracesEndpoint = "https://your-collector-host/v1/traces",
serviceName = "YourApp-android",
customVariableKeys = setOf("journeyName", "appVersion", "environment"),
createHttpSpansInInterceptor = true
)
HEALEUMInstrumentation.install(this, cfg)
}
}
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(HEALEUMInstrumentation.HealHttpClientInterceptor())
.build()
Notes for the Developer Team#
- The SDK must be initialized once only.
- The interceptor must be attached before API calls are made.
- The SDK does not change API request or response payloads.
- The SDK injects trace context headers for distributed tracing.
- Keep unrestricted header capture disabled. Allowlist only the approved non-sensitive header names required for the monitoring purpose.