Skip to content

Commit

Permalink
work in progress -- enable disk buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk committed Sep 9, 2024
1 parent c028810 commit 9ce98eb
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 83 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 0 additions & 4 deletions sample-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions splunk-otel-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions splunk-otel-android/src/main/java/com/splunk/rum/ConfigFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -429,10 +415,6 @@ boolean isDiskBufferingEnabled() {
return configFlags.isDiskBufferingEnabled();
}

boolean shouldUseOtlpExporter() {
return configFlags.shouldUseOtlpExporter();
}

boolean isReactNativeSupportEnabled() {
return configFlags.isReactNativeSupportEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 9ce98eb

Please sign in to comment.