Skip to content

Commit

Permalink
let network monitor installation happen in upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk committed Dec 8, 2023
1 parent ab350e5 commit 52ca27a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import io.opentelemetry.android.instrumentation.crash.CrashReporter;
import io.opentelemetry.android.instrumentation.lifecycle.AndroidLifecycleInstrumentation;
import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider;
import io.opentelemetry.android.instrumentation.network.NetworkAttributesSpanAppender;
import io.opentelemetry.android.instrumentation.network.NetworkChangeMonitor;
import io.opentelemetry.android.instrumentation.slowrendering.SlowRenderingDetector;
import io.opentelemetry.android.instrumentation.startup.AppStartupTimer;
Expand All @@ -53,7 +52,6 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.resources.ResourceBuilder;
import io.opentelemetry.sdk.trace.SpanLimits;
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
Expand Down Expand Up @@ -102,7 +100,8 @@ SplunkRum initialize(Looper mainLooper) {
otelRumBuilder.mergeResource(createSplunkResource());
initializationEvents.emit("resourceInitialized");

CurrentNetworkProvider currentNetworkProvider = CurrentNetworkProvider.createAndStart(application);
CurrentNetworkProvider currentNetworkProvider =
CurrentNetworkProvider.createAndStart(application);
otelRumBuilder.setCurrentNetworkProvider(currentNetworkProvider);
initializationEvents.emit("connectionUtilInitialized");

Expand Down Expand Up @@ -184,9 +183,6 @@ SplunkRum initialize(Looper mainLooper) {
if (builder.isAnrDetectionEnabled()) {
installAnrDetector(otelRumBuilder, mainLooper);
}
if (builder.isNetworkMonitorEnabled()) {
installNetworkMonitor(otelRumBuilder, currentNetworkProvider);
}
if (builder.isSlowRenderingDetectionEnabled()) {
installSlowRenderingDetector(otelRumBuilder);
}
Expand Down Expand Up @@ -282,16 +278,6 @@ private void installAnrDetector(OpenTelemetryRumBuilder otelRumBuilder, Looper m
});
}

private void installNetworkMonitor(
OpenTelemetryRumBuilder otelRumBuilder, CurrentNetworkProvider currentNetworkProvider) {
otelRumBuilder.addInstrumentation(
instrumentedApplication -> {
NetworkChangeMonitor.create(currentNetworkProvider)
.installOn(instrumentedApplication);
initializationEvents.emit("networkMonitorInitialized");
});
}

private void installSlowRenderingDetector(OpenTelemetryRumBuilder otelRumBuilder) {
otelRumBuilder.addInstrumentation(
instrumentedApplication -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import androidx.annotation.Nullable;
import com.splunk.rum.internal.GlobalAttributesSupplier;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider;
import io.opentelemetry.android.instrumentation.startup.AppStartupTimer;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -40,7 +39,6 @@
import io.opentelemetry.sdk.OpenTelemetrySdk;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import okhttp3.Call;
import okhttp3.OkHttpClient;

Expand Down Expand Up @@ -91,9 +89,7 @@ public static SplunkRumBuilder builder() {
}

// for testing purposes
static SplunkRum initialize(
SplunkRumBuilder builder,
Application application) {
static SplunkRum initialize(SplunkRumBuilder builder, Application application) {
if (INSTANCE != null) {
Log.w(LOG_TAG, "Singleton SplunkRum instance has already been initialized.");
return INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.app.Application;
import android.util.Log;
import androidx.annotation.Nullable;
import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -82,8 +81,7 @@ SpanExporter buildFilteringExporter(
return testExporter;
}
};
SplunkRum splunkRum =
testInitializer.initialize(mainLooper);
SplunkRum splunkRum = testInitializer.initialize(mainLooper);
startupTimer.runCompletionCallback();
splunkRum.flushSpans();

Expand Down Expand Up @@ -137,8 +135,7 @@ SpanExporter buildFilteringExporter(
return testExporter;
}
};
SplunkRum splunkRum =
testInitializer.initialize(mainLooper);
SplunkRum splunkRum = testInitializer.initialize(mainLooper);
splunkRum.flushSpans();

testExporter.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ void initialization_onlyOnce() {

when(application.getApplicationContext()).thenReturn(context);

SplunkRum singleton =
SplunkRum.initialize(splunkRumBuilder, application);
SplunkRum singleton = SplunkRum.initialize(splunkRumBuilder, application);
SplunkRum sameInstance = splunkRumBuilder.build(application);

assertSame(singleton, sameInstance);
Expand All @@ -117,8 +116,7 @@ void getInstance() {

when(application.getApplicationContext()).thenReturn(context);

SplunkRum singleton =
SplunkRum.initialize(splunkRumBuilder, application);
SplunkRum singleton = SplunkRum.initialize(splunkRumBuilder, application);
assertSame(singleton, SplunkRum.getInstance());
}

Expand All @@ -141,8 +139,7 @@ void nonNullMethods() {
.setRumAccessToken("abracadabra")
.disableAnrDetection();

SplunkRum splunkRum =
SplunkRum.initialize(splunkRumBuilder, application);
SplunkRum splunkRum = SplunkRum.initialize(splunkRumBuilder, application);
assertNotNull(splunkRum.getOpenTelemetry());
assertNotNull(splunkRum.getRumSessionId());
}
Expand Down Expand Up @@ -235,8 +232,7 @@ void integrateWithBrowserRum() {
.setRumAccessToken("abracadabra")
.disableAnrDetection();

SplunkRum splunkRum =
SplunkRum.initialize(splunkRumBuilder, application);
SplunkRum splunkRum = SplunkRum.initialize(splunkRumBuilder, application);
splunkRum.integrateWithBrowserRum(webView);

verify(webView)
Expand Down

0 comments on commit 52ca27a

Please sign in to comment.