Skip to content

Commit

Permalink
Split splunk/otel into separate modules (#526)
Browse files Browse the repository at this point in the history
* split splunk/otel into separate modules

* add manifest

* remove rum version for now

* fix package

* fix build

* fix build
  • Loading branch information
breedx-splk authored Jun 6, 2023
1 parent 92275f4 commit 5666e4d
Show file tree
Hide file tree
Showing 112 changed files with 123 additions and 38 deletions.
84 changes: 84 additions & 0 deletions opentelemetry-android-instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
plugins {
id("com.android.library")
id("splunk.android-library-conventions")
id("splunk.errorprone-conventions")
}

android {
namespace = "opentelemetry.rum.instrumentation"

compileSdk = 33
buildToolsVersion = "30.0.3"

defaultConfig {
minSdk = 21
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
all {
resValue("string", "rum.version", "${project.version}")
}
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

compileOptions {
isCoreLibraryDesugaringEnabled = true

sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
}

testOptions {
unitTests.isReturnDefaultValues = true
unitTests.isIncludeAndroidResources = true
}
}

val otelVersion = "1.25.0"
val otelAlphaVersion = "$otelVersion-alpha"
val otelInstrumentationVersion = "1.25.0-SNAPSHOT"
val otelInstrumentationAlphaVersion = "1.25.0-alpha-SNAPSHOT"

dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.core:core:1.9.0")
implementation("androidx.navigation:navigation-fragment:2.5.3")

api(platform("io.opentelemetry:opentelemetry-bom:$otelVersion"))
implementation("io.opentelemetry:opentelemetry-sdk")
implementation("io.opentelemetry:opentelemetry-exporter-zipkin")
implementation("io.zipkin.reporter2:zipkin-sender-okhttp3")
implementation("io.opentelemetry:opentelemetry-exporter-logging")
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:$otelInstrumentationVersion")

implementation(platform("io.opentelemetry:opentelemetry-bom-alpha:$otelAlphaVersion"))
implementation("io.opentelemetry:opentelemetry-semconv")

api("io.opentelemetry:opentelemetry-api")

testImplementation("org.mockito:mockito-core:5.3.0")
testImplementation("org.mockito:mockito-junit-jupiter:5.3.0")
testImplementation(platform("org.junit:junit-bom:5.9.2"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.junit.vintage:junit-vintage-engine")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
testImplementation("org.robolectric:robolectric:4.10")
testImplementation("androidx.test:core:1.5.0")
testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation("org.awaitility:awaitility:4.2.0")

coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
}

tasks.withType<Test> {
useJUnitPlatform()
}

extra["pomName"] = "OpenTelemetry Android Instrumentation"
description = "A library for instrumenting Android applications with OpenTelemetry"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import android.app.Application;
import android.os.Build;

import com.splunk.android.rum.R;

import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.resources.ResourceBuilder;

import opentelemetry.rum.instrumentation.R;

import java.util.function.Supplier;

final class AndroidResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.opentelemetry.rum.internal;

import static io.opentelemetry.rum.internal.RumConstants.PREVIOUS_SESSION_ID_KEY;

import io.opentelemetry.api.trace.Tracer;

final class SessionIdChangeTracer implements SessionIdChangeListener {
Expand All @@ -31,7 +29,7 @@ final class SessionIdChangeTracer implements SessionIdChangeListener {
@Override
public void onChange(String oldSessionId, String newSessionId) {
tracer.spanBuilder("sessionId.change")
.setAttribute(PREVIOUS_SESSION_ID_KEY, oldSessionId)
.setAttribute(RumConstants.PREVIOUS_SESSION_ID_KEY, oldSessionId)
.startSpan()
.end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.opentelemetry.rum.internal;

import static io.opentelemetry.rum.internal.RumConstants.SESSION_ID_KEY;

import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
Expand All @@ -33,7 +31,7 @@ public SessionIdSpanAppender(SessionId sessionId) {

@Override
public void onStart(Context parentContext, ReadWriteSpan span) {
span.setAttribute(SESSION_ID_KEY, sessionId.getSessionId());
span.setAttribute(RumConstants.SESSION_ID_KEY, sessionId.getSessionId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package io.opentelemetry.rum.internal.instrumentation.fragment;

import static io.opentelemetry.rum.internal.RumConstants.SCREEN_NAME_KEY;

import androidx.fragment.app.Fragment;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.rum.internal.RumConstants;
import io.opentelemetry.rum.internal.util.ActiveSpan;

class FragmentTracer {
Expand Down Expand Up @@ -60,7 +59,7 @@ private Span createSpan(String spanName) {
.startSpan();
// do this after the span is started, so we can override the default screen.name set by the
// RumAttributeAppender.
span.setAttribute(SCREEN_NAME_KEY, screenName);
span.setAttribute(RumConstants.SCREEN_NAME_KEY, screenName);
return span;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.opentelemetry.rum.internal.instrumentation.network;

import static io.opentelemetry.rum.internal.RumConstants.OTEL_RUM_LOG_TAG;

import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
Expand All @@ -29,6 +27,8 @@

import androidx.annotation.NonNull;

import io.opentelemetry.rum.internal.RumConstants;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier;
Expand Down Expand Up @@ -81,7 +81,7 @@ void startMonitoring(
} catch (Exception e) {
// if this fails, we'll go without network change events.
Log.w(
OTEL_RUM_LOG_TAG,
RumConstants.OTEL_RUM_LOG_TAG,
"Failed to register network callbacks. Automatic network monitoring is disabled.",
e);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ private final class ConnectionMonitor extends ConnectivityManager.NetworkCallbac
@Override
public void onAvailable(@NonNull Network network) {
CurrentNetwork activeNetwork = refreshNetworkStatus();
Log.d(OTEL_RUM_LOG_TAG, " onAvailable: currentNetwork=" + activeNetwork);
Log.d(RumConstants.OTEL_RUM_LOG_TAG, " onAvailable: currentNetwork=" + activeNetwork);

notifyListeners(activeNetwork);
}
Expand All @@ -153,7 +153,7 @@ public void onLost(@NonNull Network network) {
// state at the right time during this event.
CurrentNetwork currentNetwork = NO_NETWORK;
CurrentNetworkProvider.this.currentNetwork = currentNetwork;
Log.d(OTEL_RUM_LOG_TAG, " onLost: currentNetwork=" + currentNetwork);
Log.d(RumConstants.OTEL_RUM_LOG_TAG, " onLost: currentNetwork=" + currentNetwork);

notifyListeners(currentNetwork);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import static android.view.FrameMetrics.DRAW_DURATION;
import static android.view.FrameMetrics.FIRST_DRAW_FRAME;

import static io.opentelemetry.rum.internal.RumConstants.OTEL_RUM_LOG_TAG;

import android.app.Activity;
import android.os.Build;
import android.os.Handler;
Expand All @@ -38,6 +36,7 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.rum.internal.DefaultingActivityLifecycleCallbacks;
import io.opentelemetry.rum.internal.RumConstants;

import java.time.Duration;
import java.time.Instant;
Expand Down Expand Up @@ -176,7 +175,7 @@ private void reportSlowRenders() {
try {
activities.forEach((activity, listener) -> reportSlow(listener));
} catch (Exception e) {
Log.w(OTEL_RUM_LOG_TAG, "Exception while processing frame metrics", e);
Log.w(RumConstants.OTEL_RUM_LOG_TAG, "Exception while processing frame metrics", e);
}
}

Expand All @@ -189,12 +188,12 @@ private void reportSlow(PerActivityListener listener) {
int count = durationToCountHistogram.get(duration);
if (duration > FROZEN_THRESHOLD_MS) {
Log.d(
OTEL_RUM_LOG_TAG,
RumConstants.OTEL_RUM_LOG_TAG,
"* FROZEN RENDER DETECTED: " + duration + " ms." + count + " times");
frozenCount += count;
} else if (duration > SLOW_THRESHOLD_MS) {
Log.d(
OTEL_RUM_LOG_TAG,
RumConstants.OTEL_RUM_LOG_TAG,
"* Slow render detected: " + duration + " ms. " + count + " times");
slowCount += count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

package io.opentelemetry.rum.internal.instrumentation.slowrendering;

import static io.opentelemetry.rum.internal.RumConstants.OTEL_RUM_LOG_TAG;

import android.os.Build;
import android.util.Log;

import io.opentelemetry.rum.internal.RumConstants;
import io.opentelemetry.rum.internal.instrumentation.InstrumentedApplication;

import java.time.Duration;
Expand Down Expand Up @@ -54,7 +53,7 @@ public static SlowRenderingDetectorBuilder builder() {
public void installOn(InstrumentedApplication instrumentedApplication) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Log.w(
OTEL_RUM_LOG_TAG,
RumConstants.OTEL_RUM_LOG_TAG,
"Slow/frozen rendering detection is not supported on platforms older than Android N (SDK version 24).");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package io.opentelemetry.rum.internal.instrumentation.slowrendering;

import static io.opentelemetry.rum.internal.RumConstants.OTEL_RUM_LOG_TAG;

import android.util.Log;

import io.opentelemetry.rum.internal.RumConstants;

import java.time.Duration;

/**
Expand All @@ -43,7 +43,7 @@ public final class SlowRenderingDetectorBuilder {
public SlowRenderingDetectorBuilder setSlowRenderingDetectionPollInterval(Duration interval) {
if (interval.toMillis() <= 0) {
Log.e(
OTEL_RUM_LOG_TAG,
RumConstants.OTEL_RUM_LOG_TAG,
"Invalid slowRenderingDetectionPollInterval: "
+ interval
+ "; must be positive");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package io.opentelemetry.rum.internal.instrumentation.startup;

import static io.opentelemetry.rum.internal.RumConstants.OTEL_RUM_LOG_TAG;
import static io.opentelemetry.rum.internal.RumConstants.START_TYPE_KEY;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
Expand All @@ -31,6 +28,7 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.rum.internal.DefaultingActivityLifecycleCallbacks;
import io.opentelemetry.rum.internal.RumConstants;
import io.opentelemetry.rum.internal.util.AnchoredClock;
import io.opentelemetry.sdk.common.Clock;

Expand Down Expand Up @@ -64,7 +62,7 @@ public Span start(Tracer tracer) {
final Span appStart =
tracer.spanBuilder("AppStart")
.setStartTimestamp(firstPossibleTimestamp, TimeUnit.NANOSECONDS)
.setAttribute(START_TYPE_KEY, "cold")
.setAttribute(RumConstants.START_TYPE_KEY, "cold")
.startSpan();
overallAppStartSpan = appStart;
return appStart;
Expand Down Expand Up @@ -99,7 +97,7 @@ private void startUiInit() {
}
uiInitStarted = true;
if (firstPossibleTimestamp + MAX_TIME_TO_UI_INIT < startupClock.now()) {
Log.d(OTEL_RUM_LOG_TAG, "Max time to UI init exceeded");
Log.d(RumConstants.OTEL_RUM_LOG_TAG, "Max time to UI init exceeded");
uiInitTooLate = true;
clear();
}
Expand Down Expand Up @@ -161,7 +159,7 @@ public StartFromBackgroundRunnable(AppStartupTimer startupTimer) {
public void run() {
// check whether an activity has been created
if (!startupTimer.uiInitStarted) {
Log.d(OTEL_RUM_LOG_TAG, "Detected background app start");
Log.d(RumConstants.OTEL_RUM_LOG_TAG, "Detected background app start");
startupTimer.isStartedFromBackground = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import android.content.pm.ApplicationInfo;
import android.os.Build;

import com.splunk.android.rum.R;

import io.opentelemetry.sdk.resources.Resource;

import opentelemetry.rum.instrumentation.R;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package io.opentelemetry.rum.internal.instrumentation.network;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rootProject.name = "Splunk Android RUM"

include(":opentelemetry-android-instrumentation")
include(":splunk-otel-android")
include(":splunk-otel-android-volley")
include(":sample-app")
3 changes: 2 additions & 1 deletion splunk-otel-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ val otelAlphaVersion = "$otelVersion-alpha"
val otelInstrumentationAlphaVersion = "1.27.0-alpha-SNAPSHOT"

dependencies {
implementation(project(":opentelemetry-android-instrumentation"))
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.21"))
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.core:core:1.10.1")
Expand Down Expand Up @@ -75,7 +76,7 @@ dependencies {
testImplementation("org.robolectric:robolectric:4.10.3")
testImplementation("androidx.test:core:1.5.0")
testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation("org.awaitility:awaitility:4.2.0")
testImplementation("com.google.guava:guava:31.1-jre")

coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ private Resource createSplunkResource() {
if (builder.deploymentEnvironment != null) {
resourceBuilder.put(DEPLOYMENT_ENVIRONMENT, builder.deploymentEnvironment);
}
// TODO: Use the splunk-specific version key and not the upstream one
return resourceBuilder.put(RUM_SDK_VERSION, detectRumVersion()).build();
}

Expand Down

0 comments on commit 5666e4d

Please sign in to comment.