Skip to content

Commit

Permalink
migrate RuntimeDetailsExtractor to otel package (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk authored Jun 20, 2023
1 parent 557185f commit 9d434ff
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +36,10 @@ public class RumConstants {

public static final AttributeKey<String> RUM_SDK_VERSION = stringKey("rum.sdk.version");

public static final AttributeKey<Long> STORAGE_SPACE_FREE_KEY = longKey("storage.free");
public static final AttributeKey<Long> HEAP_FREE_KEY = longKey("heap.free");
public static final AttributeKey<Double> BATTERY_PERCENT_KEY = doubleKey("battery.percent");

public static final AttributeKey<String> PREVIOUS_SESSION_ID_KEY =
stringKey("rum.session.previous_id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,13 +31,13 @@
import java.io.File;

/** Represents details about the runtime environment at a time */
final class RuntimeDetailsExtractor<RQ, RS> extends BroadcastReceiver
public final class RuntimeDetailsExtractor<RQ, RS> extends BroadcastReceiver
implements AttributesExtractor<RQ, RS> {

private @Nullable volatile Double batteryPercent = null;
private final File filesDir;

static <RQ, RS> RuntimeDetailsExtractor<RQ, RS> create(Context context) {
public static <RQ, RS> RuntimeDetailsExtractor<RQ, RS> create(Context context) {
IntentFilter batteryChangedFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
File filesDir = context.getFilesDir();
RuntimeDetailsExtractor<RQ, RS> runtimeDetails = new RuntimeDetailsExtractor<>(filesDir);
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,10 +57,6 @@ public class SplunkRum {
static final AttributeKey<Double> LOCATION_LATITUDE_KEY = doubleKey("location.lat");
static final AttributeKey<Double> LOCATION_LONGITUDE_KEY = doubleKey("location.long");

static final AttributeKey<Long> STORAGE_SPACE_FREE_KEY = longKey("storage.free");
static final AttributeKey<Long> HEAP_FREE_KEY = longKey("heap.free");
static final AttributeKey<Double> BATTERY_PERCENT_KEY = doubleKey("battery.percent");

static final String COMPONENT_APPSTART = "appstart";
static final String COMPONENT_UI = "ui";
static final String COMPONENT_CRASH = "crash";
Expand Down

0 comments on commit 9d434ff

Please sign in to comment.