From 9ce98ebaffc8e55bfe8aa16f968d53d3f35fc071 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Mon, 9 Sep 2024 15:04:33 -0700 Subject: [PATCH] work in progress -- enable disk buffering --- gradle/libs.versions.toml | 1 + sample-app/build.gradle.kts | 4 -- splunk-otel-android/build.gradle.kts | 1 + .../main/java/com/splunk/rum/ConfigFlags.java | 12 ----- .../java/com/splunk/rum/RumInitializer.java | 9 +++- .../java/com/splunk/rum/SplunkRumBuilder.java | 48 ++++++------------- .../com/splunk/rum/SplunkRumBuilderTest.java | 33 ------------- 7 files changed, 25 insertions(+), 83 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 15b6fc69..eccea3c3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,6 +22,7 @@ opentelemetry-api = { module = "io.opentelemetry:opentelemetry-api", version.ref opentelemetry-api-incubator = { module = "io.opentelemetry:opentelemetry-api-incubator" } opentelemetry-api-events = { module = "io.opentelemetry:opentelemetry-api-events", version.ref = "opentelemetry-core-alpha" } opentelemetry-android-agent = { module = "io.opentelemetry.android:android-agent", version.ref = "opentelemetry-android" } +opentelemetry-android-instrumentation-commonapi = { module = "io.opentelemetry.android:instrumentation-common-api", version.ref = "opentelemetry-android" } opentelemetry-instrumenter-api = { module = "io.opentelemetry.instrumentation:opentelemetry-instrumentation-api", version.ref = "opentelemetry-inst" } opentelemetry-instrumenter-api-incubator = { module = "io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator", version.ref = "opentelemetry-inst-alpha" } opentelemetry-instrumentation-okhttp = { module = "io.opentelemetry.instrumentation:opentelemetry-okhttp-3.0", version.ref = "opentelemetry-inst-alpha" } diff --git a/sample-app/build.gradle.kts b/sample-app/build.gradle.kts index eddeefab..442952fc 100644 --- a/sample-app/build.gradle.kts +++ b/sample-app/build.gradle.kts @@ -72,11 +72,7 @@ composeCompiler { } repositories { - // TODO: Remove after android-agent 0.7.0-alpha is released maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } -// mavenCentral() -// google() -// gradlePluginPortal() } dependencies { diff --git a/splunk-otel-android/build.gradle.kts b/splunk-otel-android/build.gradle.kts index ba3ce209..749bdf7b 100644 --- a/splunk-otel-android/build.gradle.kts +++ b/splunk-otel-android/build.gradle.kts @@ -43,6 +43,7 @@ dependencies { api(platform(libs.opentelemetry.instrumentation.bom)) api(platform(libs.opentelemetry.bom)) api(libs.opentelemetry.android.agent) + api(libs.opentelemetry.android.instrumentation.commonapi) // not included in agent implementation(libs.opentelemetry.sdk) implementation(libs.opentelemetry.api.incubator) diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/ConfigFlags.java b/splunk-otel-android/src/main/java/com/splunk/rum/ConfigFlags.java index d290a9aa..2b1d8790 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/ConfigFlags.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/ConfigFlags.java @@ -102,18 +102,6 @@ boolean isReactNativeSupportEnabled() { return reactNativeSupportEnabled; } - void enableOtlpExporter() { - exportUsingOtlp = true; - } - - void disableOtlpExporter() { - exportUsingOtlp = false; - } - - boolean shouldUseOtlpExporter() { - return exportUsingOtlp; - } - @NonNull @Override public String toString() { diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java b/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java index d98819ce..cd0b46e5 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java @@ -44,6 +44,7 @@ import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.OpenTelemetryRumBuilder; import io.opentelemetry.android.config.OtelRumConfig; +import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfiguration; import io.opentelemetry.android.instrumentation.AndroidInstrumentationLoader; import io.opentelemetry.android.instrumentation.activity.ActivityLifecycleInstrumentation; import io.opentelemetry.android.instrumentation.activity.startup.AppStartupTimer; @@ -90,6 +91,11 @@ SplunkRum initialize(Looper mainLooper) { new GlobalAttributesSupplier(builder.globalAttributes); config.setGlobalAttributes(globalAttributeSupplier); + config.setDiskBufferingConfiguration(DiskBufferingConfiguration.builder() + .setEnabled(true) + .setMaxCacheSize(100_000_000) + .build()); + // TODO: Note/document this instrumentation is now opt-in via application classpath via build settings // if (!builder.isNetworkMonitorEnabled()) { // config.disableNetworkChangeMonitoring(); @@ -316,7 +322,8 @@ SpanExporter buildSpanExporter(SpanExporter delegate) { // Wire up the logging exporter, if enabled. if (builder.isDebugEnabled()) { initializationEvents.emit("debugSpanExporterInitialized"); - return SpanExporter.composite(LoggingSpanExporter.create(), filteredExporter); + SpanExporter result = SpanExporter.composite(LoggingSpanExporter.create(), filteredExporter); + return result; } return filteredExporter; } diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java index ead999bb..69d6c838 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRumBuilder.java @@ -111,18 +111,11 @@ public SplunkRumBuilder setRealm(String realm) { "beaconEndpoint has already been set. Realm configuration will be ignored."); return this; } - this.beaconEndpoint = "https://rum-ingest." + realm + ".signalfx.com/v1/rum"; this.realm = realm; - if (shouldUseOtlpExporter()) { - configureBeaconForOtlp(); - } + this.beaconEndpoint = "https://rum-ingest." + this.realm + ".signalfx.com/v1/rumotlp"; return this; } - private void configureBeaconForOtlp() { - this.beaconEndpoint = "https://rum-ingest." + realm + ".signalfx.com/v1/rumotlp"; - } - /** * Sets the RUM auth token to be used by the RUM library. * @@ -155,14 +148,7 @@ public SplunkRumBuilder enableDebug() { * @return {@code this} */ public SplunkRumBuilder enableDiskBuffering() { - if (shouldUseOtlpExporter()) { - Log.w(SplunkRum.LOG_TAG, "OTLP export is not yet compatible with disk buffering!"); - Log.w( - SplunkRum.LOG_TAG, - "Because disk buffering is enabled, OTLP export is now disabled!"); - configFlags.disableOtlpExporter(); - } - + // TODO: Default to enabled, switch this perhaps to allow disabling configFlags.enableDiskBuffering(); return this; } @@ -380,19 +366,19 @@ public SplunkRumBuilder enableBackgroundInstrumentationDeferredUntilForeground() * * @return {@code this} */ - public SplunkRumBuilder enableExperimentalOtlpExporter() { - if (isDiskBufferingEnabled()) { - Log.w(SplunkRum.LOG_TAG, "OTLP export is not yet compatible with disk buffering!"); - Log.w(SplunkRum.LOG_TAG, "Please disable disk buffering in order to use OTLP export."); - Log.w(SplunkRum.LOG_TAG, "OTLP is not enabled."); - return this; - } - configFlags.enableOtlpExporter(); - if (this.realm != null) { - configureBeaconForOtlp(); - } - return this; - } +// public SplunkRumBuilder enableExperimentalOtlpExporter() { +// if (isDiskBufferingEnabled()) { +// Log.w(SplunkRum.LOG_TAG, "OTLP export is not yet compatible with disk buffering!"); +// Log.w(SplunkRum.LOG_TAG, "Please disable disk buffering in order to use OTLP export."); +// Log.w(SplunkRum.LOG_TAG, "OTLP is not enabled."); +// return this; +// } +// configFlags.enableOtlpExporter(); +// if (this.realm != null) { +// configureBeaconForOtlp(); +// } +// return this; +// } // one day maybe these can use kotlin delegation ConfigFlags getConfigFlags() { @@ -429,10 +415,6 @@ boolean isDiskBufferingEnabled() { return configFlags.isDiskBufferingEnabled(); } - boolean shouldUseOtlpExporter() { - return configFlags.shouldUseOtlpExporter(); - } - boolean isReactNativeSupportEnabled() { return configFlags.isReactNativeSupportEnabled(); } diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumBuilderTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumBuilderTest.java index 92491614..162ea93c 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumBuilderTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumBuilderTest.java @@ -91,37 +91,4 @@ void beaconOverridesRealm() { SplunkRum.builder().setRealm("us0").setBeaconEndpoint("http://beacon"); assertEquals("http://beacon", builder.beaconEndpoint); } - - @Test - void otlpNotEnabledByDefault() { - SplunkRumBuilder builder = SplunkRum.builder().setRealm("jp0"); - assertThat(builder.getConfigFlags().shouldUseOtlpExporter()).isFalse(); - } - - @Test - void enableOtlp() { - SplunkRumBuilder builder = - SplunkRum.builder().setRealm("jp0").enableExperimentalOtlpExporter(); - assertThat(builder.getConfigFlags().shouldUseOtlpExporter()).isTrue(); - } - - @Test - void otlpFailsWhenDiskBufferingEnabled() { - SplunkRumBuilder builder = - SplunkRum.builder() - .setRealm("us0") - .enableDiskBuffering() - .enableExperimentalOtlpExporter(); - assertThat(builder.getConfigFlags().shouldUseOtlpExporter()).isFalse(); - } - - @Test - void enableDiskBufferAfterOtlp() { - SplunkRumBuilder builder = - SplunkRum.builder() - .setRealm("us0") - .enableExperimentalOtlpExporter() - .enableDiskBuffering(); - assertThat(builder.getConfigFlags().shouldUseOtlpExporter()).isFalse(); - } }