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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.app.Application
import android.util.Log
import android.widget.ImageView
import com.launchdarkly.observability.api.ObservabilityOptions
import com.launchdarkly.observability.client.TelemetryInspector
import com.launchdarkly.observability.plugin.Observability
import com.launchdarkly.observability.replay.PrivacyProfile
import com.launchdarkly.observability.replay.ReplayOptions
Expand Down Expand Up @@ -42,7 +41,6 @@ open class BaseApplication : Application() {
logAdapter = LDAndroidLogging.adapter(),
)

var telemetryInspector: TelemetryInspector? = null
var testUrl: String? = null

open fun realInit() {
Expand Down Expand Up @@ -89,7 +87,6 @@ open class BaseApplication : Application() {
.build()

LDClient.init(this@BaseApplication, ldConfig, context, 1)
telemetryInspector = observabilityPlugin.getTelemetryInspector()

if (testUrl == null) {
// intervenes in E2E tests by trigger spans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.test.core.app.ApplicationProvider
import com.example.androidobservability.TestUtils.TelemetryType
import com.example.androidobservability.TestUtils.waitForTelemetryData
import com.launchdarkly.observability.api.ObservabilityOptions
import com.launchdarkly.observability.client.TelemetryInspector
import com.launchdarkly.observability.testing.InMemoryTelemetryInspector
import com.launchdarkly.observability.sdk.LDObserve
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.common.Attributes
Expand Down Expand Up @@ -46,7 +46,7 @@ class SamplingE2ETest {
val testCoroutineRule = TestCoroutineRule()

private val application = ApplicationProvider.getApplicationContext<Application>() as TestApplication
private var telemetryInspector: TelemetryInspector? = null
private var telemetryInspector: InMemoryTelemetryInspector? = null

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.androidobservability

import com.launchdarkly.observability.testing.InMemoryTelemetryInspector
import com.launchdarkly.sdk.android.LDClient
import io.opentelemetry.android.features.diskbuffering.SignalFromDiskExporter
import okhttp3.mockwebserver.MockResponse
Expand All @@ -10,6 +11,8 @@ class TestApplication : BaseApplication() {

private val host = "127.0.0.1"
var mockWebServer: MockWebServer? = null
var telemetryInspector: InMemoryTelemetryInspector? = null
private set

override fun onCreate() {
// The Application class won't be initialized unless initForTest() is executed. This helps us to set up
Expand Down Expand Up @@ -40,6 +43,9 @@ class TestApplication : BaseApplication() {

fun initForTest() {
setupMockServer()
val inspector = InMemoryTelemetryInspector()
telemetryInspector = inspector
observabilityOptions = observabilityOptions.copy(telemetryInspector = inspector)
super.realInit()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.androidobservability

import com.launchdarkly.observability.client.TelemetryInspector
import com.launchdarkly.observability.testing.InMemoryTelemetryInspector

object TestUtils {

fun waitForTelemetryData(
maxWaitMs: Long = 5000,
telemetryInspector: TelemetryInspector?,
telemetryInspector: InMemoryTelemetryInspector?,
telemetryType: TelemetryType
): Boolean {
val startTime = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ dependencies {
implementation("io.opentelemetry:opentelemetry-sdk-metrics:1.51.0")
implementation("io.opentelemetry:opentelemetry-sdk-logs:1.51.0")

// TODO: Evaluate risks associated with incubator APIs
// Required at runtime by io.opentelemetry.android:core, which uses incubator APIs
// internally for the logs bridge. Can be removed once the OTel Android SDK drops this dependency.
implementation("io.opentelemetry:opentelemetry-api-incubator:1.51.0-alpha")

// Testing exporters for telemetry inspection
implementation("io.opentelemetry:opentelemetry-sdk-testing:1.51.0")

// OTEL Android
implementation("io.opentelemetry.android:core:0.11.0-alpha")
Expand All @@ -61,13 +59,16 @@ dependencies {
implementation("io.opentelemetry.android.instrumentation:activity:0.11.0-alpha")

// Use JUnit Jupiter for testing.
// Testing exporters for telemetry inspection
testImplementation("io.opentelemetry:opentelemetry-sdk-testing:1.51.0")
testImplementation(platform("org.junit:junit-bom:5.13.4"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testImplementation("io.mockk:mockk:1.14.5")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2")

testFixturesApi("io.opentelemetry:opentelemetry-sdk-testing:1.51.0")
testFixturesImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.launchdarkly.observability.api

import com.launchdarkly.logging.LDLogAdapter
import com.launchdarkly.observability.BuildConfig
import com.launchdarkly.observability.client.TelemetryInspector
import com.launchdarkly.sdk.android.LDTimberLogging
import io.opentelemetry.api.common.Attributes
import kotlin.time.Duration
Expand All @@ -28,6 +29,9 @@ const val DEFAULT_BACKEND_URL = "https://pub.observability.app.launchdarkly.com"
* @property instrumentations Options for configuring automatic instrumentations. See [Instrumentations].
* @property logAdapter The log adapter to use. Defaults to using the LaunchDarkly SDK's LDTimberLogging.adapter(). Use LDAndroidLogging.adapter() to use the Android logging adapter.
* @property loggerName The name of the logger to use. Defaults to "LaunchDarklyObservabilityPlugin".
* @property telemetryInspector Optional [TelemetryInspector] for intercepting exported telemetry during testing.
* When provided together with [debug] = true, the inspector's exporters are wired into composite
* exporters so that test code can assert on the data that flows through the SDK.
*/
data class ObservabilityOptions(
val enabled: Boolean = true,
Expand All @@ -46,6 +50,7 @@ data class ObservabilityOptions(
val instrumentations: Instrumentations = Instrumentations(),
val logAdapter: LDLogAdapter = LDTimberLogging.adapter(), // This follows the LaunchDarkly SDK's default log adapter
val loggerName: String = "LaunchDarklyObservabilityPlugin",
val telemetryInspector: TelemetryInspector? = null,
){
/**
* Options for configuring traces.
Expand Down

This file was deleted.

Loading
Loading