From 9d434ff5cea1df09d989fe1eb53d47ffb506f554 Mon Sep 17 00:00:00 2001 From: jason plumb <75337021+breedx-splk@users.noreply.github.com> Date: Tue, 20 Jun 2023 06:19:38 -0700 Subject: [PATCH] migrate RuntimeDetailsExtractor to otel package (#575) --- .../opentelemetry/rum/internal/RumConstants.java | 6 ++++++ .../rum/internal}/RuntimeDetailsExtractor.java | 16 ++++++++++------ .../internal}/RuntimeDetailsExtractorTest.java | 11 +++++++---- .../main/java/com/splunk/rum/RumInitializer.java | 1 + .../src/main/java/com/splunk/rum/SplunkRum.java | 5 ----- 5 files changed, 24 insertions(+), 15 deletions(-) rename {splunk-otel-android/src/main/java/com/splunk/rum => opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal}/RuntimeDetailsExtractor.java (80%) rename {splunk-otel-android/src/test/java/com/splunk/rum => opentelemetry-android-instrumentation/src/test/java/io/opentelemetry/rum/internal}/RuntimeDetailsExtractorTest.java (82%) diff --git a/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/RumConstants.java b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/RumConstants.java index f2305e53f..84ca83711 100644 --- a/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/RumConstants.java +++ b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/RumConstants.java @@ -16,6 +16,8 @@ package io.opentelemetry.rum.internal; +import static io.opentelemetry.api.common.AttributeKey.doubleKey; +import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; import io.opentelemetry.api.common.AttributeKey; @@ -34,6 +36,10 @@ public class RumConstants { public static final AttributeKey RUM_SDK_VERSION = stringKey("rum.sdk.version"); + public static final AttributeKey STORAGE_SPACE_FREE_KEY = longKey("storage.free"); + public static final AttributeKey HEAP_FREE_KEY = longKey("heap.free"); + public static final AttributeKey BATTERY_PERCENT_KEY = doubleKey("battery.percent"); + public static final AttributeKey PREVIOUS_SESSION_ID_KEY = stringKey("rum.session.previous_id"); diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/RuntimeDetailsExtractor.java b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/RuntimeDetailsExtractor.java similarity index 80% rename from splunk-otel-android/src/main/java/com/splunk/rum/RuntimeDetailsExtractor.java rename to opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/RuntimeDetailsExtractor.java index 44cdca87a..36125d091 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/RuntimeDetailsExtractor.java +++ b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/RuntimeDetailsExtractor.java @@ -14,7 +14,11 @@ * limitations under the License. */ -package com.splunk.rum; +package io.opentelemetry.rum.internal; + +import static io.opentelemetry.rum.internal.RumConstants.BATTERY_PERCENT_KEY; +import static io.opentelemetry.rum.internal.RumConstants.HEAP_FREE_KEY; +import static io.opentelemetry.rum.internal.RumConstants.STORAGE_SPACE_FREE_KEY; import android.content.BroadcastReceiver; import android.content.Context; @@ -27,13 +31,13 @@ import java.io.File; /** Represents details about the runtime environment at a time */ -final class RuntimeDetailsExtractor extends BroadcastReceiver +public final class RuntimeDetailsExtractor extends BroadcastReceiver implements AttributesExtractor { private @Nullable volatile Double batteryPercent = null; private final File filesDir; - static RuntimeDetailsExtractor create(Context context) { + public static RuntimeDetailsExtractor create(Context context) { IntentFilter batteryChangedFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); File filesDir = context.getFilesDir(); RuntimeDetailsExtractor runtimeDetails = new RuntimeDetailsExtractor<>(filesDir); @@ -57,12 +61,12 @@ public void onStart( AttributesBuilder attributes, io.opentelemetry.context.Context parentContext, RQ request) { - attributes.put(SplunkRum.STORAGE_SPACE_FREE_KEY, getCurrentStorageFreeSpaceInBytes()); - attributes.put(SplunkRum.HEAP_FREE_KEY, getCurrentFreeHeapInBytes()); + attributes.put(STORAGE_SPACE_FREE_KEY, getCurrentStorageFreeSpaceInBytes()); + attributes.put(HEAP_FREE_KEY, getCurrentFreeHeapInBytes()); Double currentBatteryPercent = getCurrentBatteryPercent(); if (currentBatteryPercent != null) { - attributes.put(SplunkRum.BATTERY_PERCENT_KEY, currentBatteryPercent); + attributes.put(BATTERY_PERCENT_KEY, currentBatteryPercent); } } diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/RuntimeDetailsExtractorTest.java b/opentelemetry-android-instrumentation/src/test/java/io/opentelemetry/rum/internal/RuntimeDetailsExtractorTest.java similarity index 82% rename from splunk-otel-android/src/test/java/com/splunk/rum/RuntimeDetailsExtractorTest.java rename to opentelemetry-android-instrumentation/src/test/java/io/opentelemetry/rum/internal/RuntimeDetailsExtractorTest.java index 3414fbc09..2dbae3ea4 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/RuntimeDetailsExtractorTest.java +++ b/opentelemetry-android-instrumentation/src/test/java/io/opentelemetry/rum/internal/RuntimeDetailsExtractorTest.java @@ -14,9 +14,12 @@ * limitations under the License. */ -package com.splunk.rum; +package io.opentelemetry.rum.internal; import static io.opentelemetry.context.Context.root; +import static io.opentelemetry.rum.internal.RumConstants.BATTERY_PERCENT_KEY; +import static io.opentelemetry.rum.internal.RumConstants.HEAP_FREE_KEY; +import static io.opentelemetry.rum.internal.RumConstants.STORAGE_SPACE_FREE_KEY; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.mockito.Mockito.when; @@ -54,8 +57,8 @@ void shouldCollectRuntimeDetails() { details.onStart(attributes, root(), null); assertThat(attributes.build()) .hasSize(3) - .containsEntry(SplunkRum.STORAGE_SPACE_FREE_KEY, 4200L) - .containsKey(SplunkRum.HEAP_FREE_KEY) - .containsEntry(SplunkRum.BATTERY_PERCENT_KEY, 69.0); + .containsEntry(STORAGE_SPACE_FREE_KEY, 4200L) + .containsKey(HEAP_FREE_KEY) + .containsEntry(BATTERY_PERCENT_KEY, 69.0); } } 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 2a108b690..ff0b39743 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 @@ -39,6 +39,7 @@ import io.opentelemetry.rum.internal.GlobalAttributesSpanAppender; import io.opentelemetry.rum.internal.OpenTelemetryRum; import io.opentelemetry.rum.internal.OpenTelemetryRumBuilder; +import io.opentelemetry.rum.internal.RuntimeDetailsExtractor; import io.opentelemetry.rum.internal.SessionIdRatioBasedSampler; import io.opentelemetry.rum.internal.instrumentation.activity.VisibleScreenTracker; import io.opentelemetry.rum.internal.instrumentation.anr.AnrDetector; 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 4664364d6..710afe521 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 @@ -17,7 +17,6 @@ package com.splunk.rum; import static io.opentelemetry.api.common.AttributeKey.doubleKey; -import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; import android.app.Application; @@ -58,10 +57,6 @@ public class SplunkRum { static final AttributeKey LOCATION_LATITUDE_KEY = doubleKey("location.lat"); static final AttributeKey LOCATION_LONGITUDE_KEY = doubleKey("location.long"); - static final AttributeKey STORAGE_SPACE_FREE_KEY = longKey("storage.free"); - static final AttributeKey HEAP_FREE_KEY = longKey("heap.free"); - static final AttributeKey BATTERY_PERCENT_KEY = doubleKey("battery.percent"); - static final String COMPONENT_APPSTART = "appstart"; static final String COMPONENT_UI = "ui"; static final String COMPONENT_CRASH = "crash";