From 422aa4ef41ffa7b329ed626feca582e723861df8 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 30 Nov 2023 15:53:41 -0800 Subject: [PATCH 01/17] use GlobalAttributeSpanAppender via upstream mechanism --- .../src/main/java/com/splunk/rum/SplunkRum.java | 1 + .../src/test/java/com/splunk/rum/SplunkRumTest.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java index 5a9922f7..d2f6fdb1 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java @@ -26,6 +26,7 @@ import android.util.Log; import android.webkit.WebView; import androidx.annotation.Nullable; + import com.splunk.rum.internal.GlobalAttributesSupplier; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider; diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java index b80abf2c..fd268865 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java @@ -36,6 +36,9 @@ import android.content.Context; import android.location.Location; import android.webkit.WebView; + +import com.splunk.rum.internal.GlobalAttributesSupplier; + import com.splunk.rum.internal.GlobalAttributesSupplier; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider; From f7697d1f92c0fe2a6d8d85d4c3bdf4435c5dea52 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 30 Nov 2023 17:08:58 -0800 Subject: [PATCH 02/17] let upstream handle global attributes --- .../src/main/java/com/splunk/rum/RumInitializer.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) 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 b8e05336..9a6d4f9f 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 @@ -22,13 +22,14 @@ import static com.splunk.rum.SplunkRum.COMPONENT_KEY; import static com.splunk.rum.SplunkRum.COMPONENT_UI; import static com.splunk.rum.SplunkRum.RUM_TRACER_NAME; +import static java.util.Objects.requireNonNull; import static io.opentelemetry.android.RumConstants.APP_START_SPAN_NAME; import static io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor.constant; import static io.opentelemetry.semconv.ResourceAttributes.DEPLOYMENT_ENVIRONMENT; -import static java.util.Objects.requireNonNull; import android.app.Application; import android.os.Looper; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.splunk.rum.internal.GlobalAttributesSupplier; @@ -59,12 +60,6 @@ import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.sdk.trace.samplers.Sampler; -import java.time.Duration; -import java.util.Collection; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.logging.Level; import zipkin2.reporter.Sender; import zipkin2.reporter.okhttp3.OkHttpSender; @@ -95,8 +90,7 @@ SplunkRum initialize( initializationEvents.begin(); OtelRumConfig config = new OtelRumConfig(); - GlobalAttributesSupplier globalAttributeSupplier = - new GlobalAttributesSupplier(builder.globalAttributes); + GlobalAttributesSupplier globalAttributeSupplier = new GlobalAttributesSupplier(builder.globalAttributes); config.setGlobalAttributes(globalAttributeSupplier); OpenTelemetryRumBuilder otelRumBuilder = OpenTelemetryRum.builder(application, config); From c233ef7442165cf5001136bf2ec09c6f95754664 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Mon, 4 Dec 2023 09:59:07 -0800 Subject: [PATCH 03/17] spotless --- .../src/main/java/com/splunk/rum/RumInitializer.java | 6 +++--- .../src/main/java/com/splunk/rum/SplunkRum.java | 1 - .../src/test/java/com/splunk/rum/SplunkRumTest.java | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) 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 9a6d4f9f..bd0f2fae 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 @@ -22,14 +22,13 @@ import static com.splunk.rum.SplunkRum.COMPONENT_KEY; import static com.splunk.rum.SplunkRum.COMPONENT_UI; import static com.splunk.rum.SplunkRum.RUM_TRACER_NAME; -import static java.util.Objects.requireNonNull; import static io.opentelemetry.android.RumConstants.APP_START_SPAN_NAME; import static io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor.constant; import static io.opentelemetry.semconv.ResourceAttributes.DEPLOYMENT_ENVIRONMENT; +import static java.util.Objects.requireNonNull; import android.app.Application; import android.os.Looper; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.splunk.rum.internal.GlobalAttributesSupplier; @@ -90,7 +89,8 @@ SplunkRum initialize( initializationEvents.begin(); OtelRumConfig config = new OtelRumConfig(); - GlobalAttributesSupplier globalAttributeSupplier = new GlobalAttributesSupplier(builder.globalAttributes); + GlobalAttributesSupplier globalAttributeSupplier = + new GlobalAttributesSupplier(builder.globalAttributes); config.setGlobalAttributes(globalAttributeSupplier); OpenTelemetryRumBuilder otelRumBuilder = OpenTelemetryRum.builder(application, config); diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java index d2f6fdb1..5a9922f7 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java @@ -26,7 +26,6 @@ import android.util.Log; import android.webkit.WebView; import androidx.annotation.Nullable; - import com.splunk.rum.internal.GlobalAttributesSupplier; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider; diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java index fd268865..3ad176cd 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java @@ -36,7 +36,6 @@ import android.content.Context; import android.location.Location; import android.webkit.WebView; - import com.splunk.rum.internal.GlobalAttributesSupplier; import com.splunk.rum.internal.GlobalAttributesSupplier; From 7a28257f02473f65bc834ccd85bdba30a5e67b7b Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 7 Dec 2023 15:55:57 -0800 Subject: [PATCH 04/17] spotless --- .../src/main/java/com/splunk/rum/RumInitializer.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 bd0f2fae..b8e05336 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 @@ -59,6 +59,12 @@ import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.sdk.trace.samplers.Sampler; +import java.time.Duration; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.logging.Level; import zipkin2.reporter.Sender; import zipkin2.reporter.okhttp3.OkHttpSender; From 26437d8eb00a8e5f4ad13ec2885932e0eb929e62 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 7 Dec 2023 16:16:57 -0800 Subject: [PATCH 05/17] move creation closer to ussage --- .../java/com/splunk/rum/RumInitializer.java | 7 ++----- .../src/main/java/com/splunk/rum/SplunkRum.java | 5 ++--- .../java/com/splunk/rum/SplunkRumBuilder.java | 2 +- .../java/com/splunk/rum/RumInitializerTest.java | 12 +++--------- .../test/java/com/splunk/rum/SplunkRumTest.java | 17 ++++------------- 5 files changed, 12 insertions(+), 31 deletions(-) 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 b8e05336..cd07fcdb 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 @@ -87,9 +87,7 @@ class RumInitializer { this.initializationEvents = new InitializationEvents(startupTimer); } - SplunkRum initialize( - Function currentNetworkProviderFactory, - Looper mainLooper) { + SplunkRum initialize(Looper mainLooper) { VisibleScreenTracker visibleScreenTracker = new VisibleScreenTracker(); initializationEvents.begin(); @@ -104,8 +102,7 @@ SplunkRum initialize( otelRumBuilder.mergeResource(createSplunkResource()); initializationEvents.emit("resourceInitialized"); - CurrentNetworkProvider currentNetworkProvider = - currentNetworkProviderFactory.apply(application); + CurrentNetworkProvider currentNetworkProvider = CurrentNetworkProvider.createAndStart(application); initializationEvents.emit("connectionUtilInitialized"); // TODO: How truly important is the order of these span processors? The location of event diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java index 5a9922f7..0f54c1c0 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java @@ -93,8 +93,7 @@ public static SplunkRumBuilder builder() { // for testing purposes static SplunkRum initialize( SplunkRumBuilder builder, - Application application, - Function currentNetworkProviderFactory) { + Application application) { if (INSTANCE != null) { Log.w(LOG_TAG, "Singleton SplunkRum instance has already been initialized."); return INSTANCE; @@ -105,7 +104,7 @@ static SplunkRum initialize( } else { INSTANCE = new RumInitializer(builder, application, startupTimer) - .initialize(currentNetworkProviderFactory, Looper.getMainLooper()); + .initialize(Looper.getMainLooper()); } if (builder.isDebugEnabled()) { 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 3664fb8a..0642a559 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 @@ -312,7 +312,7 @@ public SplunkRum build(Application application) { throw new IllegalStateException( "You must provide a rumAccessToken, a realm (or full beaconEndpoint), and an applicationName to create a valid Config instance."); } - return SplunkRum.initialize(this, application, CurrentNetworkProvider::createAndStart); + return SplunkRum.initialize(this, application); } /** diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java index 0b63e0dd..b8657d14 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java @@ -83,8 +83,7 @@ SpanExporter buildFilteringExporter( } }; SplunkRum splunkRum = - testInitializer.initialize( - app -> mock(CurrentNetworkProvider.class, RETURNS_DEEP_STUBS), mainLooper); + testInitializer.initialize(mainLooper); startupTimer.runCompletionCallback(); splunkRum.flushSpans(); @@ -139,8 +138,7 @@ SpanExporter buildFilteringExporter( } }; SplunkRum splunkRum = - testInitializer.initialize( - app -> mock(CurrentNetworkProvider.class, RETURNS_DEEP_STUBS), mainLooper); + testInitializer.initialize(mainLooper); splunkRum.flushSpans(); testExporter.reset(); @@ -232,10 +230,6 @@ void shouldTranslateExceptionEventsToSpanAttributes() { when(application.getApplicationContext()).thenReturn(context); - CurrentNetworkProvider currentNetworkProvider = - mock(CurrentNetworkProvider.class, RETURNS_DEEP_STUBS); - when(currentNetworkProvider.refreshNetworkStatus().isOnline()).thenReturn(true); - AppStartupTimer appStartupTimer = new AppStartupTimer(); RumInitializer initializer = new RumInitializer(splunkRumBuilder, application, appStartupTimer) { @@ -245,7 +239,7 @@ SpanExporter getCoreSpanExporter(String endpoint) { } }; - SplunkRum splunkRum = initializer.initialize(app -> currentNetworkProvider, mainLooper); + SplunkRum splunkRum = initializer.initialize(mainLooper); appStartupTimer.runCompletionCallback(); Exception e = new IllegalArgumentException("booom!"); diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java index 3ad176cd..c53595dd 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java @@ -40,7 +40,6 @@ import com.splunk.rum.internal.GlobalAttributesSupplier; import io.opentelemetry.android.OpenTelemetryRum; -import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.trace.Span; @@ -82,8 +81,6 @@ public void setup() { @Test void initialization_onlyOnce() { Application application = mock(Application.class, RETURNS_DEEP_STUBS); - CurrentNetworkProvider currentNetworkProvider = - mock(CurrentNetworkProvider.class, RETURNS_DEEP_STUBS); Context context = mock(Context.class); SplunkRumBuilder splunkRumBuilder = @@ -96,7 +93,7 @@ void initialization_onlyOnce() { when(application.getApplicationContext()).thenReturn(context); SplunkRum singleton = - SplunkRum.initialize(splunkRumBuilder, application, app -> currentNetworkProvider); + SplunkRum.initialize(splunkRumBuilder, application); SplunkRum sameInstance = splunkRumBuilder.build(application); assertSame(singleton, sameInstance); @@ -111,8 +108,6 @@ void getInstance_preConfig() { @Test void getInstance() { Application application = mock(Application.class, RETURNS_DEEP_STUBS); - CurrentNetworkProvider currentNetworkProvider = - mock(CurrentNetworkProvider.class, RETURNS_DEEP_STUBS); Context context = mock(Context.class); SplunkRumBuilder splunkRumBuilder = @@ -125,7 +120,7 @@ void getInstance() { when(application.getApplicationContext()).thenReturn(context); SplunkRum singleton = - SplunkRum.initialize(splunkRumBuilder, application, app -> currentNetworkProvider); + SplunkRum.initialize(splunkRumBuilder, application); assertSame(singleton, SplunkRum.getInstance()); } @@ -137,8 +132,6 @@ void newBuilder() { @Test void nonNullMethods() { Application application = mock(Application.class, RETURNS_DEEP_STUBS); - CurrentNetworkProvider currentNetworkProvider = - mock(CurrentNetworkProvider.class, RETURNS_DEEP_STUBS); Context context = mock(Context.class); when(application.getApplicationContext()).thenReturn(context); @@ -151,7 +144,7 @@ void nonNullMethods() { .disableAnrDetection(); SplunkRum splunkRum = - SplunkRum.initialize(splunkRumBuilder, application, app -> currentNetworkProvider); + SplunkRum.initialize(splunkRumBuilder, application); assertNotNull(splunkRum.getOpenTelemetry()); assertNotNull(splunkRum.getRumSessionId()); } @@ -232,8 +225,6 @@ void createAndEnd() { @Test void integrateWithBrowserRum() { Application application = mock(Application.class, RETURNS_DEEP_STUBS); - CurrentNetworkProvider currentNetworkProvider = - mock(CurrentNetworkProvider.class, RETURNS_DEEP_STUBS); Context context = mock(Context.class); WebView webView = mock(WebView.class); @@ -247,7 +238,7 @@ void integrateWithBrowserRum() { .disableAnrDetection(); SplunkRum splunkRum = - SplunkRum.initialize(splunkRumBuilder, application, app -> currentNetworkProvider); + SplunkRum.initialize(splunkRumBuilder, application); splunkRum.integrateWithBrowserRum(webView); verify(webView) From c99d62babcf223f853c1a6e8f0029567f59a3c25 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 7 Dec 2023 16:46:29 -0800 Subject: [PATCH 06/17] leverage upstream for NetworkAttributeSpanAppender --- .../src/main/java/com/splunk/rum/RumInitializer.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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 cd07fcdb..52a7fbbe 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 @@ -103,19 +103,12 @@ SplunkRum initialize(Looper mainLooper) { initializationEvents.emit("resourceInitialized"); CurrentNetworkProvider currentNetworkProvider = CurrentNetworkProvider.createAndStart(application); + otelRumBuilder.setCurrentNetworkProvider(currentNetworkProvider); initializationEvents.emit("connectionUtilInitialized"); // TODO: How truly important is the order of these span processors? The location of event // generation should probably not be altered... - // Add span processor that appends network attributes. - otelRumBuilder.addTracerProviderCustomizer( - (tracerProviderBuilder, app) -> { - SpanProcessor networkAttributesSpanAppender = - NetworkAttributesSpanAppender.create(currentNetworkProvider); - return tracerProviderBuilder.addSpanProcessor(networkAttributesSpanAppender); - }); - // Add batch span processor otelRumBuilder.addTracerProviderCustomizer( (tracerProviderBuilder, app) -> { From cf54c8b9cdff8af06446f6db710f10e9a542f154 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 7 Dec 2023 16:52:42 -0800 Subject: [PATCH 07/17] let network monitor installation happen in upstream. --- .../java/com/splunk/rum/RumInitializer.java | 18 ++---------------- .../main/java/com/splunk/rum/SplunkRum.java | 6 +----- .../java/com/splunk/rum/SplunkRumBuilder.java | 1 - .../com/splunk/rum/RumInitializerTest.java | 7 ++----- .../java/com/splunk/rum/SplunkRumTest.java | 12 ++++-------- 5 files changed, 9 insertions(+), 35 deletions(-) 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 52a7fbbe..0f417958 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 @@ -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; @@ -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; @@ -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"); @@ -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); } @@ -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 -> { diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java index 0f54c1c0..90b59165 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkRum.java @@ -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; @@ -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; @@ -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; 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 0642a559..07f17bf2 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 @@ -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; diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java index b8657d14..70e73f29 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java @@ -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; @@ -82,8 +81,7 @@ SpanExporter buildFilteringExporter( return testExporter; } }; - SplunkRum splunkRum = - testInitializer.initialize(mainLooper); + SplunkRum splunkRum = testInitializer.initialize(mainLooper); startupTimer.runCompletionCallback(); splunkRum.flushSpans(); @@ -137,8 +135,7 @@ SpanExporter buildFilteringExporter( return testExporter; } }; - SplunkRum splunkRum = - testInitializer.initialize(mainLooper); + SplunkRum splunkRum = testInitializer.initialize(mainLooper); splunkRum.flushSpans(); testExporter.reset(); diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java index c53595dd..decc6248 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java @@ -92,8 +92,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); @@ -119,8 +118,7 @@ void getInstance() { when(application.getApplicationContext()).thenReturn(context); - SplunkRum singleton = - SplunkRum.initialize(splunkRumBuilder, application); + SplunkRum singleton = SplunkRum.initialize(splunkRumBuilder, application); assertSame(singleton, SplunkRum.getInstance()); } @@ -143,8 +141,7 @@ void nonNullMethods() { .setRumAccessToken("abracadabra") .disableAnrDetection(); - SplunkRum splunkRum = - SplunkRum.initialize(splunkRumBuilder, application); + SplunkRum splunkRum = SplunkRum.initialize(splunkRumBuilder, application); assertNotNull(splunkRum.getOpenTelemetry()); assertNotNull(splunkRum.getRumSessionId()); } @@ -237,8 +234,7 @@ void integrateWithBrowserRum() { .setRumAccessToken("abracadabra") .disableAnrDetection(); - SplunkRum splunkRum = - SplunkRum.initialize(splunkRumBuilder, application); + SplunkRum splunkRum = SplunkRum.initialize(splunkRumBuilder, application); splunkRum.integrateWithBrowserRum(webView); verify(webView) From 0f34a7e77d965b61297e40e33b5813f4a7fe3b92 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 30 Nov 2023 15:53:41 -0800 Subject: [PATCH 08/17] use GlobalAttributeSpanAppender via upstream mechanism --- .../src/test/java/com/splunk/rum/SplunkRumTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java index decc6248..b160c9d1 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java @@ -36,6 +36,9 @@ import android.content.Context; import android.location.Location; import android.webkit.WebView; + +import com.splunk.rum.internal.GlobalAttributesSupplier; + import com.splunk.rum.internal.GlobalAttributesSupplier; import com.splunk.rum.internal.GlobalAttributesSupplier; From f004a305b585ee8c78e62a1b23307b3944fd253b Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 30 Nov 2023 17:08:58 -0800 Subject: [PATCH 09/17] let upstream handle global attributes --- .../src/main/java/com/splunk/rum/RumInitializer.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) 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 0f417958..093a9b09 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 @@ -22,13 +22,14 @@ import static com.splunk.rum.SplunkRum.COMPONENT_KEY; import static com.splunk.rum.SplunkRum.COMPONENT_UI; import static com.splunk.rum.SplunkRum.RUM_TRACER_NAME; +import static java.util.Objects.requireNonNull; import static io.opentelemetry.android.RumConstants.APP_START_SPAN_NAME; import static io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor.constant; import static io.opentelemetry.semconv.ResourceAttributes.DEPLOYMENT_ENVIRONMENT; -import static java.util.Objects.requireNonNull; import android.app.Application; import android.os.Looper; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.splunk.rum.internal.GlobalAttributesSupplier; @@ -57,12 +58,6 @@ import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.sdk.trace.samplers.Sampler; -import java.time.Duration; -import java.util.Collection; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.logging.Level; import zipkin2.reporter.Sender; import zipkin2.reporter.okhttp3.OkHttpSender; @@ -91,8 +86,7 @@ SplunkRum initialize(Looper mainLooper) { initializationEvents.begin(); OtelRumConfig config = new OtelRumConfig(); - GlobalAttributesSupplier globalAttributeSupplier = - new GlobalAttributesSupplier(builder.globalAttributes); + GlobalAttributesSupplier globalAttributeSupplier = new GlobalAttributesSupplier(builder.globalAttributes); config.setGlobalAttributes(globalAttributeSupplier); OpenTelemetryRumBuilder otelRumBuilder = OpenTelemetryRum.builder(application, config); From ebdac89015652e989d75ac61b2e51adac325f6f1 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Mon, 4 Dec 2023 09:59:07 -0800 Subject: [PATCH 10/17] spotless --- .../src/main/java/com/splunk/rum/RumInitializer.java | 6 +++--- .../src/test/java/com/splunk/rum/SplunkRumTest.java | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) 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 093a9b09..e2f0dfc1 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 @@ -22,14 +22,13 @@ import static com.splunk.rum.SplunkRum.COMPONENT_KEY; import static com.splunk.rum.SplunkRum.COMPONENT_UI; import static com.splunk.rum.SplunkRum.RUM_TRACER_NAME; -import static java.util.Objects.requireNonNull; import static io.opentelemetry.android.RumConstants.APP_START_SPAN_NAME; import static io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor.constant; import static io.opentelemetry.semconv.ResourceAttributes.DEPLOYMENT_ENVIRONMENT; +import static java.util.Objects.requireNonNull; import android.app.Application; import android.os.Looper; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.splunk.rum.internal.GlobalAttributesSupplier; @@ -86,7 +85,8 @@ SplunkRum initialize(Looper mainLooper) { initializationEvents.begin(); OtelRumConfig config = new OtelRumConfig(); - GlobalAttributesSupplier globalAttributeSupplier = new GlobalAttributesSupplier(builder.globalAttributes); + GlobalAttributesSupplier globalAttributeSupplier = + new GlobalAttributesSupplier(builder.globalAttributes); config.setGlobalAttributes(globalAttributeSupplier); OpenTelemetryRumBuilder otelRumBuilder = OpenTelemetryRum.builder(application, config); diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java index b160c9d1..6630e00b 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java @@ -36,7 +36,6 @@ import android.content.Context; import android.location.Location; import android.webkit.WebView; - import com.splunk.rum.internal.GlobalAttributesSupplier; import com.splunk.rum.internal.GlobalAttributesSupplier; From 1ea31c8655888254b4064aa3c5e1ff09536ca367 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 7 Dec 2023 15:55:57 -0800 Subject: [PATCH 11/17] spotless --- .../src/main/java/com/splunk/rum/RumInitializer.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 e2f0dfc1..0f417958 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 @@ -57,6 +57,12 @@ import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.sdk.trace.samplers.Sampler; +import java.time.Duration; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.logging.Level; import zipkin2.reporter.Sender; import zipkin2.reporter.okhttp3.OkHttpSender; From 64fed7de10bb09c63e0f07ea209b83c46d52775b Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 7 Dec 2023 16:16:57 -0800 Subject: [PATCH 12/17] move creation closer to ussage --- .../src/main/java/com/splunk/rum/RumInitializer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 0f417958..af3c70d4 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 @@ -100,8 +100,7 @@ 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"); From 15ec902821d86bde5c13de197b69f1015fced8c7 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Fri, 8 Dec 2023 09:51:18 -0800 Subject: [PATCH 13/17] spotless --- .../src/main/java/com/splunk/rum/RumInitializer.java | 1 - 1 file changed, 1 deletion(-) 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 af3c70d4..950634da 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 @@ -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.NetworkChangeMonitor; import io.opentelemetry.android.instrumentation.slowrendering.SlowRenderingDetector; import io.opentelemetry.android.instrumentation.startup.AppStartupTimer; import io.opentelemetry.api.trace.Tracer; From 7e624b5331f1410b94f61c6357dc82d859d930b6 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 12 Dec 2023 11:08:39 -0800 Subject: [PATCH 14/17] spotless --- .../src/main/java/com/splunk/rum/RumInitializer.java | 3 ++- .../src/test/java/com/splunk/rum/SplunkRumTest.java | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-) 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 950634da..81e7137b 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 @@ -99,7 +99,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"); diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java index 6630e00b..8602ffb3 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkRumTest.java @@ -36,10 +36,6 @@ import android.content.Context; import android.location.Location; import android.webkit.WebView; -import com.splunk.rum.internal.GlobalAttributesSupplier; - -import com.splunk.rum.internal.GlobalAttributesSupplier; - import com.splunk.rum.internal.GlobalAttributesSupplier; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.api.common.Attributes; From 8241ba4bba3edb04fdd9b6cf708a99c74bf89b1e Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 12 Dec 2023 11:31:44 -0800 Subject: [PATCH 15/17] no longer generate the event (will happen in upstream again eventually) --- .../src/test/java/com/splunk/rum/RumInitializerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java index 70e73f29..daf5212d 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java @@ -105,7 +105,6 @@ SpanExporter buildFilteringExporter( checkEventExists(events, "activityLifecycleCallbacksInitialized"); checkEventExists(events, "crashReportingInitialized"); checkEventExists(events, "anrMonitorInitialized"); - checkEventExists(events, "networkMonitorInitialized"); } private void checkEventExists(List events, String eventName) { From 911dcb9998ef938ebd2e814a0694367b04ba6e97 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 12 Dec 2023 11:43:40 -0800 Subject: [PATCH 16/17] pass builder setting into upstream config --- .../src/main/java/com/splunk/rum/RumInitializer.java | 3 +++ 1 file changed, 3 insertions(+) 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 81e7137b..730b5a62 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 @@ -93,6 +93,9 @@ SplunkRum initialize(Looper mainLooper) { GlobalAttributesSupplier globalAttributeSupplier = new GlobalAttributesSupplier(builder.globalAttributes); config.setGlobalAttributes(globalAttributeSupplier); + if(!builder.isNetworkMonitorEnabled()){ + config.disableNetworkChangeMonitoring(); + } OpenTelemetryRumBuilder otelRumBuilder = OpenTelemetryRum.builder(application, config); From 3977551d1c97d8e963e4edfe2bfe73019351ce6a Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 12 Dec 2023 11:46:17 -0800 Subject: [PATCH 17/17] spotless --- .../src/main/java/com/splunk/rum/RumInitializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 730b5a62..7fc577ad 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 @@ -93,7 +93,7 @@ SplunkRum initialize(Looper mainLooper) { GlobalAttributesSupplier globalAttributeSupplier = new GlobalAttributesSupplier(builder.globalAttributes); config.setGlobalAttributes(globalAttributeSupplier); - if(!builder.isNetworkMonitorEnabled()){ + if (!builder.isNetworkMonitorEnabled()) { config.disableNetworkChangeMonitoring(); }