Skip to content

Commit 37eae48

Browse files
committed
feat: Add Android launch time instrumentation
This commit introduces automatic instrumentation for Android application launch times. It measures and reports two key metrics: - Time to Initial Display (TTID) - Time to Full Display (TTFD) The instrumentation classifies launches as `cold`, `warm`, or `hot` and records the durations as histogram metrics (`app.launch.duration.ttid` and `app.launch.duration.ttfd`). These metrics include attributes for the launch type and the specific activity being launched. The implementation also includes: - Adding a dependency on `androidx.activity`. - Updating the Android compile SDK version to 36 (Required for the dependency added)
1 parent 70ba248 commit 37eae48

File tree

4 files changed

+454
-4
lines changed

4 files changed

+454
-4
lines changed

e2e/android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
android {
99
namespace = "com.example.androidobservability"
10-
compileSdk = 35
10+
compileSdk = 36
1111

1212
defaultConfig {
1313
applicationId = "com.example.androidobservability"

sdk/@launchdarkly/observability-android/lib/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ dependencies {
2323
implementation("com.launchdarkly:launchdarkly-android-client-sdk:5.9.0")
2424
implementation("com.jakewharton.timber:timber:5.0.1")
2525

26+
// Android
27+
implementation("androidx.activity:activity:1.11.0")
28+
2629
// Coroutines
2730
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
2831
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")
@@ -69,7 +72,7 @@ tasks.withType<Test> {
6972

7073
android {
7174
namespace = "com.launchdarkly.observability"
72-
compileSdk = 35
75+
compileSdk = 36
7376

7477
buildFeatures {
7578
buildConfig = true

sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/client/InstrumentationManager.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class InstrumentationManager(
7676
private const val BATCH_SCHEDULE_DELAY_MS = 1000L
7777
private const val BATCH_EXPORTER_TIMEOUT_MS = 5000L
7878
private const val BATCH_MAX_EXPORT_SIZE = 10
79-
private const val METRICS_EXPORT_INTERVAL_SECONDS = 10L
79+
private const val METRICS_EXPORT_INTERVAL_MS = 10_000L
8080
private const val FLUSH_TIMEOUT_SECONDS = 5L
8181
}
8282

@@ -135,6 +135,13 @@ class InstrumentationManager(
135135
otelMeter = otelRUM.openTelemetry.meterProvider.get(INSTRUMENTATION_SCOPE_NAME)
136136
otelLogger = otelRUM.openTelemetry.logsBridge.get(INSTRUMENTATION_SCOPE_NAME)
137137
otelTracer = otelRUM.openTelemetry.tracerProvider.get(INSTRUMENTATION_SCOPE_NAME)
138+
139+
if (!options.disableTraces) {
140+
LaunchTimeInstrumentation(
141+
application = application,
142+
metricRecorder = this::recordHistogram
143+
)
144+
}
138145
}
139146

140147
private fun createOtelRumConfig(): OtelRumConfig {
@@ -277,7 +284,7 @@ class InstrumentationManager(
277284
private fun createPeriodicMetricReader(metricExporter: MetricExporter): PeriodicMetricReader {
278285
// Configure a periodic reader that pushes metrics every 10 seconds.
279286
return PeriodicMetricReader.builder(metricExporter)
280-
.setInterval(METRICS_EXPORT_INTERVAL_SECONDS, TimeUnit.SECONDS)
287+
.setInterval(METRICS_EXPORT_INTERVAL_MS, TimeUnit.MILLISECONDS)
281288
.build()
282289
}
283290

0 commit comments

Comments
 (0)