Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions e2e/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import java.util.Properties

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
id("net.bytebuddy.byte-buddy-gradle-plugin") version "1.17.6"
}

val localProperties = Properties().apply {
val localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localPropertiesFile.inputStream().use { load(it) }
}
}

android {
namespace = "com.example.androidobservability"
compileSdk = 36
Expand All @@ -16,6 +25,22 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField(
"String",
"LAUNCHDARKLY_MOBILE_KEY",
"\"${localProperties.getProperty("launchdarkly.mobileKey", "")}\""
)
buildConfigField(
"String",
"OTLP_ENDPOINT",
"\"${localProperties.getProperty("launchdarkly.otlpEndpoint", "").ifEmpty { "https://otel.observability.app.launchdarkly.com:4318" }}\""
)
buildConfigField(
"String",
"BACKEND_URL",
"\"${localProperties.getProperty("launchdarkly.backendUrl", "").ifEmpty { "https://pub.observability.app.launchdarkly.com" }}\""
)
}

buildTypes {
Expand All @@ -36,6 +61,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
packaging {
resources {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.androidobservability

import android.app.Application
import android.util.Log
import android.widget.ImageView
import com.launchdarkly.observability.api.ObservabilityOptions
import com.launchdarkly.observability.client.TelemetryInspector
Expand All @@ -18,20 +19,21 @@ import com.launchdarkly.sdk.android.LDConfig
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.common.Attributes
import com.launchdarkly.observability.sdk.LDReplay
import com.launchdarkly.sdk.android.FeatureFlagChangeListener

open class BaseApplication : Application() {

companion object {
// TODO O11Y-376: Update this credential to be driven by env variable or gradle property
// Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly SDK mobile key.
const val LAUNCHDARKLY_MOBILE_KEY = "MOBILE_KEY_GOES_HERE"
const val LAUNCHDARKLY_MOBILE_KEY = BuildConfig.LAUNCHDARKLY_MOBILE_KEY
}

var observabilityOptions = ObservabilityOptions(
resourceAttributes = Attributes.of(
AttributeKey.stringKey("example"), "value"
),
debug = true,
otlpEndpoint = BuildConfig.OTLP_ENDPOINT,
backendUrl = BuildConfig.BACKEND_URL,
tracesApi = ObservabilityOptions.TracesApi.enabled(),
metricsApi = ObservabilityOptions.MetricsApi.enabled(),
instrumentations = ObservabilityOptions.Instrumentations(
Expand Down Expand Up @@ -89,9 +91,22 @@ open class BaseApplication : Application() {
LDClient.init(this@BaseApplication, ldConfig, context)
telemetryInspector = observabilityPlugin.getTelemetryInspector()

flagEvaluation()

LDReplay.start()
}

fun flagEvaluation() {
val flagKey = "feature1"
val value = LDClient.get().boolVariation(flagKey, false)
Log.i("flag", "sync ${flagKey} value= ${value}")
val listener = FeatureFlagChangeListener {
val newValue = LDClient.get().boolVariation(flagKey, false)
Log.i("flag", "listened ${flagKey} value= ${newValue}")
}
LDClient.get().registerFeatureFlagListener(flagKey, listener)
}

override fun onCreate() {
super.onCreate()
realInit()
Expand Down
Loading