Skip to content

Commit 1f6e616

Browse files
committed
chore: adds skeleton Android observability plugin with barebones metric, log, error support
1 parent 662b71e commit 1f6e616

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1847
-0
lines changed

e2e/android/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

e2e/android/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

e2e/android/app/build.gradle.kts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
5+
}
6+
7+
android {
8+
namespace = "com.example.androidobservability"
9+
compileSdk = 35
10+
11+
defaultConfig {
12+
applicationId = "com.example.androidobservability"
13+
minSdk = 24
14+
targetSdk = 35
15+
versionCode = 1
16+
versionName = "1.0"
17+
18+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
21+
buildTypes {
22+
release {
23+
isMinifyEnabled = false
24+
proguardFiles(
25+
getDefaultProguardFile("proguard-android-optimize.txt"),
26+
"proguard-rules.pro"
27+
)
28+
}
29+
}
30+
compileOptions {
31+
sourceCompatibility = JavaVersion.VERSION_11
32+
targetCompatibility = JavaVersion.VERSION_11
33+
}
34+
kotlinOptions {
35+
jvmTarget = "11"
36+
}
37+
buildFeatures {
38+
compose = true
39+
}
40+
}
41+
42+
dependencies {
43+
implementation("com.launchdarkly:launchdarkly-android-client-sdk:5.9.0")
44+
45+
implementation("io.opentelemetry:opentelemetry-api:1.51.0")
46+
implementation("io.opentelemetry:opentelemetry-sdk:1.51.0")
47+
implementation("io.opentelemetry:opentelemetry-exporter-otlp:1.51.0")
48+
implementation("io.opentelemetry:opentelemetry-sdk-metrics:1.51.0")
49+
50+
implementation(project(":observability-android"))
51+
implementation(libs.androidx.core.ktx)
52+
implementation(libs.androidx.lifecycle.runtime.ktx)
53+
implementation(libs.androidx.activity.compose)
54+
implementation(platform(libs.androidx.compose.bom))
55+
implementation(libs.androidx.ui)
56+
implementation(libs.androidx.ui.graphics)
57+
implementation(libs.androidx.ui.tooling.preview)
58+
implementation(libs.androidx.material3)
59+
testImplementation(libs.junit)
60+
androidTestImplementation(libs.androidx.junit)
61+
androidTestImplementation(libs.androidx.espresso.core)
62+
androidTestImplementation(platform(libs.androidx.compose.bom))
63+
androidTestImplementation(libs.androidx.ui.test.junit4)
64+
debugImplementation(libs.androidx.ui.tooling)
65+
debugImplementation(libs.androidx.ui.test.manifest)
66+
}

e2e/android/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.androidobservability
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.androidobservability", appContext.packageName)
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:name=".BaseApplication"
7+
android:usesCleartextTraffic="true"
8+
android:allowBackup="true"
9+
android:dataExtractionRules="@xml/data_extraction_rules"
10+
android:fullBackupContent="@xml/backup_rules"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/Theme.AndroidObservability"
16+
tools:targetApi="31">
17+
<activity
18+
android:name=".MainActivity"
19+
android:exported="true"
20+
android:label="@string/app_name"
21+
android:theme="@style/Theme.AndroidObservability">
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
25+
<category android:name="android.intent.category.LAUNCHER" />
26+
</intent-filter>
27+
</activity>
28+
</application>
29+
30+
</manifest>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.example.androidobservability
2+
3+
import android.app.Application
4+
import com.launchdarkly.sdk.ContextKind
5+
import com.launchdarkly.sdk.LDContext
6+
import com.launchdarkly.sdk.android.Components
7+
import com.launchdarkly.sdk.android.LDClient
8+
import com.launchdarkly.sdk.android.LDConfig
9+
import com.launchdarkly.observability.plugin.Observability
10+
import com.launchdarkly.sdk.android.integrations.Plugin
11+
import java.util.Collections
12+
13+
class BaseApplication : Application() {
14+
15+
companion object {
16+
// Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly SDK mobile key.
17+
const val LAUNCHDARKLY_MOBILE_KEY = "MOBILE_KEY_GOES_HERE"
18+
}
19+
20+
override fun onCreate() {
21+
super.onCreate()
22+
23+
// Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly mobile key found on the LaunchDarkly
24+
// dashboard in the start guide.
25+
// If you want to disable the Auto EnvironmentAttributes functionality.
26+
// Use AutoEnvAttributes.Disabled as the argument to the Builder
27+
val ldConfig = LDConfig.Builder(LDConfig.Builder.AutoEnvAttributes.Enabled)
28+
.mobileKey(LAUNCHDARKLY_MOBILE_KEY)
29+
.plugins(Components.plugins().setPlugins(
30+
Collections.singletonList<Plugin>(Observability())
31+
))
32+
.build()
33+
34+
// Set up the context properties. This context should appear on your LaunchDarkly context
35+
// dashboard soon after you run the demo.
36+
val context = LDContext.builder(ContextKind.DEFAULT, "example-user-key")
37+
.anonymous(true)
38+
.build()
39+
40+
LDClient.init(this@BaseApplication, ldConfig, context)
41+
}
42+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.example.androidobservability
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.activity.enableEdgeToEdge
7+
import androidx.activity.viewModels
8+
import androidx.compose.foundation.layout.Column
9+
import androidx.compose.foundation.layout.fillMaxSize
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.material3.Button
12+
import androidx.compose.material3.Scaffold
13+
import androidx.compose.material3.Text
14+
import androidx.compose.runtime.Composable
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.lifecycle.Lifecycle
18+
import androidx.lifecycle.lifecycleScope
19+
import androidx.lifecycle.repeatOnLifecycle
20+
import com.example.androidobservability.ui.theme.AndroidObservabilityTheme
21+
import kotlinx.coroutines.launch
22+
23+
class MainActivity : ComponentActivity() {
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
val viewModel: ViewModel by viewModels()
27+
enableEdgeToEdge()
28+
setContent {
29+
AndroidObservabilityTheme {
30+
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
31+
Column {
32+
Text(
33+
text = "Hello Telemetry",
34+
modifier = Modifier.padding(innerPadding)
35+
)
36+
Button(
37+
onClick = {
38+
viewModel.triggerMetric()
39+
}
40+
) {
41+
Text("Trigger Metric")
42+
}
43+
Button(
44+
onClick = {
45+
viewModel.triggerError()
46+
}
47+
) {
48+
Text("Trigger Error")
49+
}
50+
Button(
51+
onClick = {
52+
viewModel.triggerLog()
53+
}
54+
) {
55+
Text("Trigger Log")
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
64+
@Composable
65+
fun Greeting(name: String, modifier: Modifier = Modifier) {
66+
Text(
67+
text = "Hello $name!",
68+
modifier = modifier
69+
)
70+
}
71+
72+
@Preview(showBackground = true)
73+
@Composable
74+
fun GreetingPreview() {
75+
AndroidObservabilityTheme {
76+
Greeting("Android")
77+
}
78+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.example.androidobservability
2+
3+
import LDObserve
4+
import androidx.lifecycle.ViewModel
5+
import com.launchdarkly.observability.interfaces.Metric
6+
import io.opentelemetry.api.common.AttributeKey
7+
import io.opentelemetry.api.common.Attributes
8+
9+
class ViewModel : ViewModel() {
10+
fun triggerMetric() {
11+
LDObserve.recordMetric(Metric("test", 50.0))
12+
}
13+
14+
fun triggerError() {
15+
LDObserve.recordError(
16+
Error("Manual error womp womp"),
17+
Attributes.of(AttributeKey.stringKey("FakeAttribute"), "FakeVal")
18+
)
19+
}
20+
21+
fun triggerLog() {
22+
LDObserve.recordLog(
23+
"Test Log",
24+
"debug",
25+
Attributes.of(AttributeKey.stringKey("FakeAttribute"), "FakeVal")
26+
)
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.androidobservability.ui.theme
2+
3+
import androidx.compose.ui.graphics.Color
4+
5+
val Purple80 = Color(0xFFD0BCFF)
6+
val PurpleGrey80 = Color(0xFFCCC2DC)
7+
val Pink80 = Color(0xFFEFB8C8)
8+
9+
val Purple40 = Color(0xFF6650a4)
10+
val PurpleGrey40 = Color(0xFF625b71)
11+
val Pink40 = Color(0xFF7D5260)

0 commit comments

Comments
 (0)