diff --git a/android-agent/build.gradle.kts b/android-agent/build.gradle.kts index b46831d87..a162286fe 100644 --- a/android-agent/build.gradle.kts +++ b/android-agent/build.gradle.kts @@ -4,83 +4,24 @@ plugins { } android { - namespace = "io.opentelemetry.android" - - buildToolsVersion = "34.0.0" - - defaultConfig { - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - buildConfigField("String", "OTEL_ANDROID_VERSION", "\"$version\"") - } - - buildTypes { - all { - resValue("string", "rum.version", "${project.version}") - } - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro", - ) - } - } - - androidComponents { - onVariants { - if (it.buildType == "release") { // The one we choose to release - project.tasks.register("createReleaseBuild", Copy::class) { - from(it.artifacts.get(com.android.build.api.artifact.SingleArtifact.AAR)) - into(project.layout.buildDirectory.dir("outputs/aar")) - rename(".+", "opentelemetry-android.aar") - } - } - } - } - - project.afterEvaluate { - tasks.named("assembleRelease") { - finalizedBy("createReleaseBuild") - } - } - - testOptions { - unitTests.isReturnDefaultValues = true - unitTests.isIncludeAndroidResources = true - } - - buildFeatures { - buildConfig = true - } - - sourceSets { - getByName("test") { - kotlin.srcDirs("src/integrationTest/kotlin") - } - } + namespace = "io.opentelemetry.android.agent" } dependencies { - implementation(project(":common")) - implementation(project(":instrumentation:common-api")) - implementation(libs.androidx.core) - implementation(libs.androidx.navigation.fragment) - implementation(libs.androidx.lifecycle.process) - - api(platform(libs.opentelemetry.platform)) - api(libs.opentelemetry.api) - implementation(libs.opentelemetry.sdk) - implementation(libs.opentelemetry.exporter.logging) + api(project(":core")) implementation(libs.opentelemetry.instrumentation.api) - implementation(libs.opentelemetry.semconv.incubating) - implementation(libs.opentelemetry.diskBuffering) - testImplementation(libs.opentelemetry.api.incubator) - testImplementation(libs.androidx.test.core) - testImplementation(libs.awaitility) - testImplementation(libs.robolectric) - testImplementation(libs.androidx.junit.ktx) + + // Default instrumentations: + api(project(":instrumentation:activity")) + api(project(":instrumentation:fragment")) + api(project(":instrumentation:crash")) + api(project(":instrumentation:startup")) + api(project(":instrumentation:slowrendering")) + api(project(":instrumentation:anr")) + api(project(":instrumentation:network")) } -extra["pomName"] = "OpenTelemetry Android Instrumentation" -description = "A library for instrumenting Android applications with OpenTelemetry" +extra["pomName"] = "OpenTelemetry Android Agent" +description = + "A library that contains all the commonly needed instrumentation for Android apps in a " + + "convenient way with minimum configuration needed." diff --git a/android-agent/src/main/kotlin/io/opentelemetry/android/agent/OtelRumConfigExtensions.kt b/android-agent/src/main/kotlin/io/opentelemetry/android/agent/OtelRumConfigExtensions.kt new file mode 100644 index 000000000..9bf17d895 --- /dev/null +++ b/android-agent/src/main/kotlin/io/opentelemetry/android/agent/OtelRumConfigExtensions.kt @@ -0,0 +1,80 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.android.agent + +import io.opentelemetry.android.config.OtelRumConfig +import io.opentelemetry.android.instrumentation.AndroidInstrumentationRegistry +import io.opentelemetry.android.instrumentation.activity.ActivityLifecycleInstrumentation +import io.opentelemetry.android.instrumentation.anr.AnrInstrumentation +import io.opentelemetry.android.instrumentation.common.ScreenNameExtractor +import io.opentelemetry.android.instrumentation.crash.CrashDetails +import io.opentelemetry.android.instrumentation.crash.CrashReporterInstrumentation +import io.opentelemetry.android.instrumentation.fragment.FragmentLifecycleInstrumentation +import io.opentelemetry.android.instrumentation.network.NetworkChangeInstrumentation +import io.opentelemetry.android.instrumentation.slowrendering.SlowRenderingInstrumentation +import io.opentelemetry.android.internal.services.network.data.CurrentNetwork +import io.opentelemetry.api.trace.Tracer +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor +import java.time.Duration + +/** + * Convenience functions to allow configuring the default instrumentations through the [OtelRumConfig] object, for example: + * + * ``` + * OtelRumConfig() + * .setSessionTimeout(Duration.ofSeconds(10)) // Real OtelRumConfig function + * .setSlowRenderingDetectionPollInterval(Duration.ofSeconds(5)) // Extension function + * .disableScreenAttributes() // Real OtelRumConfig function + * ``` + */ + +fun OtelRumConfig.setActivityTracerCustomizer(customizer: (Tracer) -> Tracer): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(ActivityLifecycleInstrumentation::class.java) + ?.setTracerCustomizer(customizer) + return this +} + +fun OtelRumConfig.setActivityNameExtractor(screenNameExtractor: ScreenNameExtractor): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(ActivityLifecycleInstrumentation::class.java) + ?.setScreenNameExtractor(screenNameExtractor) + return this +} + +fun OtelRumConfig.setFragmentTracerCustomizer(customizer: (Tracer) -> Tracer): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(FragmentLifecycleInstrumentation::class.java) + ?.setTracerCustomizer(customizer) + return this +} + +fun OtelRumConfig.setFragmentNameExtractor(screenNameExtractor: ScreenNameExtractor): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(FragmentLifecycleInstrumentation::class.java) + ?.setScreenNameExtractor(screenNameExtractor) + return this +} + +fun OtelRumConfig.addAnrAttributesExtractor(extractor: AttributesExtractor, Void>): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(AnrInstrumentation::class.java) + ?.addAttributesExtractor(extractor) + return this +} + +fun OtelRumConfig.addCrashAttributesExtractor(extractor: AttributesExtractor): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(CrashReporterInstrumentation::class.java) + ?.addAttributesExtractor(extractor) + return this +} + +fun OtelRumConfig.addNetworkChangeAttributesExtractor(extractor: AttributesExtractor): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(NetworkChangeInstrumentation::class.java) + ?.addAttributesExtractor(extractor) + return this +} + +fun OtelRumConfig.setSlowRenderingDetectionPollInterval(interval: Duration): OtelRumConfig { + AndroidInstrumentationRegistry.get().get(SlowRenderingInstrumentation::class.java) + ?.setSlowRenderingDetectionPollInterval(interval) + return this +} diff --git a/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts b/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts index d1d2a91a0..afcdf8bc4 100644 --- a/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts @@ -45,7 +45,7 @@ tasks.withType { val libs = extensions.getByType().named("libs") dependencies { implementation(libs.findLibrary("findbugs-jsr305").get()) - compileOnly(libs.findLibrary("auto-service-annotations").get()) + implementation(libs.findLibrary("auto-service-annotations").get()) kapt(libs.findLibrary("auto-service-processor").get()) testImplementation(libs.findLibrary("assertj-core").get()) testImplementation(libs.findBundle("mocking").get()) diff --git a/common/build.gradle.kts b/common/build.gradle.kts deleted file mode 100644 index 6510c879c..000000000 --- a/common/build.gradle.kts +++ /dev/null @@ -1,20 +0,0 @@ -plugins { - id("otel.android-library-conventions") - id("otel.publish-conventions") -} - -description = "OpenTelemetry Android common" - -android { - namespace = "io.opentelemetry.android.common" - - defaultConfig { - consumerProguardFiles("consumer-rules.pro") - } -} - -dependencies { - api(platform(libs.opentelemetry.platform)) - api(libs.opentelemetry.api) - implementation(libs.androidx.core) -} diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 000000000..a4ec4e38d --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,84 @@ +plugins { + id("otel.android-library-conventions") + id("otel.publish-conventions") +} + +android { + namespace = "io.opentelemetry.android" + + buildToolsVersion = "34.0.0" + + defaultConfig { + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + buildConfigField("String", "OTEL_ANDROID_VERSION", "\"$version\"") + } + + buildTypes { + all { + resValue("string", "rum.version", "${project.version}") + } + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro", + ) + } + } + + androidComponents { + onVariants { + if (it.buildType == "release") { // The one we choose to release + project.tasks.register("createReleaseBuild", Copy::class) { + from(it.artifacts.get(com.android.build.api.artifact.SingleArtifact.AAR)) + into(project.layout.buildDirectory.dir("outputs/aar")) + rename(".+", "opentelemetry-android.aar") + } + } + } + } + + project.afterEvaluate { + tasks.named("assembleRelease") { + finalizedBy("createReleaseBuild") + } + } + + testOptions { + unitTests.isReturnDefaultValues = true + unitTests.isIncludeAndroidResources = true + } + + buildFeatures { + buildConfig = true + } + + sourceSets { + getByName("test") { + kotlin.srcDirs("src/integrationTest/kotlin") + } + } +} + +dependencies { + implementation(libs.androidx.core) + implementation(libs.androidx.navigation.fragment) + implementation(libs.androidx.lifecycle.process) + + api(platform(libs.opentelemetry.platform)) + api(libs.opentelemetry.api) + implementation(libs.opentelemetry.sdk) + implementation(libs.opentelemetry.exporter.logging) + implementation(libs.opentelemetry.instrumentation.api) + implementation(libs.opentelemetry.semconv.incubating) + implementation(libs.opentelemetry.diskBuffering) + testImplementation(libs.opentelemetry.api.incubator) + testImplementation(libs.androidx.test.core) + testImplementation(libs.awaitility) + testImplementation(libs.robolectric) + testImplementation(libs.androidx.junit.ktx) +} + +extra["pomName"] = "OpenTelemetry Android Instrumentation" +description = "A library for instrumenting Android applications with OpenTelemetry" diff --git a/android-agent/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt b/core/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt similarity index 100% rename from android-agent/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt rename to core/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt diff --git a/android-agent/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml similarity index 100% rename from android-agent/src/main/AndroidManifest.xml rename to core/src/main/AndroidManifest.xml diff --git a/android-agent/src/main/java/io/opentelemetry/android/AndroidResource.java b/core/src/main/java/io/opentelemetry/android/AndroidResource.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/AndroidResource.java rename to core/src/main/java/io/opentelemetry/android/AndroidResource.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/GlobalAttributesSpanAppender.java b/core/src/main/java/io/opentelemetry/android/GlobalAttributesSpanAppender.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/GlobalAttributesSpanAppender.java rename to core/src/main/java/io/opentelemetry/android/GlobalAttributesSpanAppender.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/NoopOpenTelemetryRum.java b/core/src/main/java/io/opentelemetry/android/NoopOpenTelemetryRum.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/NoopOpenTelemetryRum.java rename to core/src/main/java/io/opentelemetry/android/NoopOpenTelemetryRum.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRum.java b/core/src/main/java/io/opentelemetry/android/OpenTelemetryRum.java similarity index 88% rename from android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRum.java rename to core/src/main/java/io/opentelemetry/android/OpenTelemetryRum.java index c04633bf3..8fd0cbafd 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRum.java +++ b/core/src/main/java/io/opentelemetry/android/OpenTelemetryRum.java @@ -43,7 +43,7 @@ static OpenTelemetryRumBuilder builder(Application application) { * SDK as a parameter. */ static OpenTelemetryRumBuilder builder(Application application, OtelRumConfig config) { - return new OpenTelemetryRumBuilder(application, config); + return OpenTelemetryRumBuilder.create(application, config); } /** @@ -58,10 +58,15 @@ static OpenTelemetryRumBuilder builder(Application application, OtelRumConfig co * * @param application The {@link Application} that is being instrumented. * @param openTelemetrySdk The {@link OpenTelemetrySdk} that the user has already created. + * @param discoverInstrumentations TRUE to look for instrumentations in the classpath and + * applying them automatically. */ static SdkPreconfiguredRumBuilder builder( - Application application, OpenTelemetrySdk openTelemetrySdk) { - return new SdkPreconfiguredRumBuilder(application, openTelemetrySdk); + Application application, + OpenTelemetrySdk openTelemetrySdk, + boolean discoverInstrumentations) { + return new SdkPreconfiguredRumBuilder( + application, openTelemetrySdk, discoverInstrumentations); } /** Returns a no-op implementation of {@link OpenTelemetryRum}. */ diff --git a/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java b/core/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java similarity index 95% rename from android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java rename to core/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java index 05b272d5e..715d51ca7 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java +++ b/core/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java @@ -14,7 +14,7 @@ import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfiguration; import io.opentelemetry.android.features.diskbuffering.SignalFromDiskExporter; import io.opentelemetry.android.features.diskbuffering.scheduler.ExportScheduleHandler; -import io.opentelemetry.android.instrumentation.common.InstrumentedApplication; +import io.opentelemetry.android.instrumentation.AndroidInstrumentation; import io.opentelemetry.android.internal.features.networkattrs.NetworkAttributesSpanAppender; import io.opentelemetry.android.internal.features.persistence.DiskManager; import io.opentelemetry.android.internal.features.persistence.SimpleTemporaryFileProvider; @@ -74,10 +74,7 @@ public final class OpenTelemetryRumBuilder { private final List> loggerProviderCustomizers = new ArrayList<>(); private final OtelRumConfig config; - - private final List> instrumentationInstallers = - new ArrayList<>(); - + private final List instrumentations = new ArrayList<>(); private final List> otelSdkReadyListeners = new ArrayList<>(); private Function spanExporterCustomizer = a -> a; private Function @@ -92,10 +89,14 @@ private static TextMapPropagator buildDefaultPropagator() { W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance()); } - OpenTelemetryRumBuilder(Application application, OtelRumConfig config) { + public static OpenTelemetryRumBuilder create(Application application, OtelRumConfig config) { + return new OpenTelemetryRumBuilder( + application, config, new SessionIdTimeoutHandler(config.getSessionTimeout())); + } + + OpenTelemetryRumBuilder( + Application application, OtelRumConfig config, SessionIdTimeoutHandler timeoutHandler) { this.application = application; - final SessionIdTimeoutHandler timeoutHandler = - new SessionIdTimeoutHandler(config.getSessionTimeout()); this.sessionId = new SessionId(timeoutHandler); this.resource = AndroidResource.createDefault(application); this.config = config; @@ -184,14 +185,12 @@ public OpenTelemetryRumBuilder addLoggerProviderCustomizer( } /** - * Adds an instrumentation installer function that will be run on an {@link - * InstrumentedApplication} instance as a part of the {@link #build()} method call. + * Adds an instrumentation to be applied as a part of the {@link #build()} method call. * * @return {@code this} */ - public OpenTelemetryRumBuilder addInstrumentation( - Consumer instrumentationInstaller) { - instrumentationInstallers.add(instrumentationInstaller); + public OpenTelemetryRumBuilder addInstrumentation(AndroidInstrumentation instrumentation) { + instrumentations.add(instrumentation); return this; } @@ -319,8 +318,12 @@ OpenTelemetryRum build(ServiceManager serviceManager) { SdkPreconfiguredRumBuilder delegate = new SdkPreconfiguredRumBuilder( - application, sdk, sessionId, serviceManager::getAppLifecycleService); - instrumentationInstallers.forEach(delegate::addInstrumentation); + application, + sdk, + sessionId, + serviceManager::getAppLifecycleService, + config.shouldDiscoverInstrumentations()); + instrumentations.forEach(delegate::addInstrumentation); serviceManager.start(); return delegate.build(); } diff --git a/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumImpl.java b/core/src/main/java/io/opentelemetry/android/OpenTelemetryRumImpl.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumImpl.java rename to core/src/main/java/io/opentelemetry/android/OpenTelemetryRumImpl.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/RuntimeDetailsExtractor.java b/core/src/main/java/io/opentelemetry/android/RuntimeDetailsExtractor.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/RuntimeDetailsExtractor.java rename to core/src/main/java/io/opentelemetry/android/RuntimeDetailsExtractor.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/ScreenAttributesSpanProcessor.java b/core/src/main/java/io/opentelemetry/android/ScreenAttributesSpanProcessor.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/ScreenAttributesSpanProcessor.java rename to core/src/main/java/io/opentelemetry/android/ScreenAttributesSpanProcessor.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.kt b/core/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.kt similarity index 62% rename from android-agent/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.kt rename to core/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.kt index 2803ce596..5ab869129 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.kt +++ b/core/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.kt @@ -6,11 +6,11 @@ package io.opentelemetry.android import android.app.Application -import io.opentelemetry.android.instrumentation.common.InstrumentedApplication +import io.opentelemetry.android.instrumentation.AndroidInstrumentation +import io.opentelemetry.android.instrumentation.AndroidInstrumentationRegistry import io.opentelemetry.android.internal.services.ServiceManager import io.opentelemetry.android.internal.services.applifecycle.AppLifecycleService import io.opentelemetry.sdk.OpenTelemetrySdk -import java.util.function.Consumer class SdkPreconfiguredRumBuilder @JvmOverloads @@ -24,18 +24,18 @@ class SdkPreconfiguredRumBuilder appLifecycleServiceProvider: () -> AppLifecycleService = { ServiceManager.get().getAppLifecycleService() }, + private val discoverInstrumentations: Boolean, ) { - private val instrumentationInstallers: MutableList> = - ArrayList() + private val instrumentations = mutableListOf() private val appLifecycleService by lazy { appLifecycleServiceProvider.invoke() } /** - * Adds an instrumentation installer function that will be run on an [ ] instance as a part of the [.build] method call. + * Adds an instrumentation to be applied as a part of the [build] method call. * * @return `this` */ - fun addInstrumentation(instrumentationInstaller: Consumer): SdkPreconfiguredRumBuilder { - instrumentationInstallers.add(instrumentationInstaller) + fun addInstrumentation(instrumentation: AndroidInstrumentation): SdkPreconfiguredRumBuilder { + instrumentations.add(instrumentation) return this } @@ -56,13 +56,21 @@ class SdkPreconfiguredRumBuilder val tracer = sdk.getTracer(OpenTelemetryRum::class.java.simpleName) sessionId.setSessionIdChangeListener(SessionIdChangeTracer(tracer)) - // InstrumentedApplication instrumentedApplication = - // new InstrumentedApplicationImpl(application, sdk, - // applicationStateWatcher); - // for (Consumer installer : instrumentationInstallers) { - // installer.accept(instrumentedApplication); TODO to be replaced by calls to - // AndroidInstrumentation.install - // } - return OpenTelemetryRumImpl(sdk, sessionId) + val openTelemetryRum = OpenTelemetryRumImpl(sdk, sessionId) + + // Install instrumentations + for (instrumentation in getInstrumentations()) { + instrumentation.install(application, openTelemetryRum) + } + + return openTelemetryRum + } + + private fun getInstrumentations(): List { + if (discoverInstrumentations) { + instrumentations.addAll(AndroidInstrumentationRegistry.get().getAll()) + } + + return instrumentations } } diff --git a/android-agent/src/main/java/io/opentelemetry/android/SessionId.java b/core/src/main/java/io/opentelemetry/android/SessionId.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/SessionId.java rename to core/src/main/java/io/opentelemetry/android/SessionId.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/SessionIdChangeListener.java b/core/src/main/java/io/opentelemetry/android/SessionIdChangeListener.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/SessionIdChangeListener.java rename to core/src/main/java/io/opentelemetry/android/SessionIdChangeListener.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/SessionIdChangeTracer.java b/core/src/main/java/io/opentelemetry/android/SessionIdChangeTracer.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/SessionIdChangeTracer.java rename to core/src/main/java/io/opentelemetry/android/SessionIdChangeTracer.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/SessionIdRatioBasedSampler.java b/core/src/main/java/io/opentelemetry/android/SessionIdRatioBasedSampler.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/SessionIdRatioBasedSampler.java rename to core/src/main/java/io/opentelemetry/android/SessionIdRatioBasedSampler.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/SessionIdSpanAppender.java b/core/src/main/java/io/opentelemetry/android/SessionIdSpanAppender.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/SessionIdSpanAppender.java rename to core/src/main/java/io/opentelemetry/android/SessionIdSpanAppender.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java b/core/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java rename to core/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java diff --git a/common/src/main/java/io/opentelemetry/android/common/RumConstants.java b/core/src/main/java/io/opentelemetry/android/common/RumConstants.java similarity index 100% rename from common/src/main/java/io/opentelemetry/android/common/RumConstants.java rename to core/src/main/java/io/opentelemetry/android/common/RumConstants.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java b/core/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java similarity index 88% rename from android-agent/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java rename to core/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java index 0d69d6dff..5b277383b 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java +++ b/core/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java @@ -23,6 +23,7 @@ public class OtelRumConfig { private boolean includeNetworkAttributes = true; private boolean generateSdkInitializationEvents = true; private boolean includeScreenAttributes = true; + private boolean discoverInstrumentations = true; private DiskBufferingConfiguration diskBufferingConfiguration = DiskBufferingConfiguration.builder().build(); private Duration sessionTimeout = Duration.ofMinutes(15); @@ -101,6 +102,24 @@ public DiskBufferingConfiguration getDiskBufferingConfiguration() { return diskBufferingConfiguration; } + /** + * Return {@link Boolean#TRUE} if the RUM initialization should look for instrumentations in the + * classpath and apply them automatically. + */ + public boolean shouldDiscoverInstrumentations() { + return discoverInstrumentations; + } + + /** + * Call this to disable the automatic search for instrumentations in the classpath. + * + * @return this + */ + public OtelRumConfig disableInstrumentationDiscovery() { + discoverInstrumentations = false; + return this; + } + /** * Sets the parameters for caching signals in disk in order to export them later. * diff --git a/android-agent/src/main/java/io/opentelemetry/android/export/AttributeModifyingSpanExporter.java b/core/src/main/java/io/opentelemetry/android/export/AttributeModifyingSpanExporter.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/export/AttributeModifyingSpanExporter.java rename to core/src/main/java/io/opentelemetry/android/export/AttributeModifyingSpanExporter.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/export/FilteringSpanExporter.java b/core/src/main/java/io/opentelemetry/android/export/FilteringSpanExporter.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/export/FilteringSpanExporter.java rename to core/src/main/java/io/opentelemetry/android/export/FilteringSpanExporter.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/export/FilteringSpanExporterBuilder.java b/core/src/main/java/io/opentelemetry/android/export/FilteringSpanExporterBuilder.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/export/FilteringSpanExporterBuilder.java rename to core/src/main/java/io/opentelemetry/android/export/FilteringSpanExporterBuilder.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/export/ModifiedSpanData.java b/core/src/main/java/io/opentelemetry/android/export/ModifiedSpanData.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/export/ModifiedSpanData.java rename to core/src/main/java/io/opentelemetry/android/export/ModifiedSpanData.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/export/SpanDataModifier.java b/core/src/main/java/io/opentelemetry/android/export/SpanDataModifier.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/export/SpanDataModifier.java rename to core/src/main/java/io/opentelemetry/android/export/SpanDataModifier.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/DiskBufferingConfiguration.java b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/DiskBufferingConfiguration.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/DiskBufferingConfiguration.java rename to core/src/main/java/io/opentelemetry/android/features/diskbuffering/DiskBufferingConfiguration.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt rename to core/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt rename to core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt rename to core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/ExportScheduleHandler.kt b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/ExportScheduleHandler.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/ExportScheduleHandler.kt rename to core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/ExportScheduleHandler.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentation.kt b/core/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentation.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentation.kt rename to core/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentation.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistry.kt b/core/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistry.kt similarity index 80% rename from android-agent/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistry.kt rename to core/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistry.kt index 408ea8157..45d66bec0 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistry.kt +++ b/core/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistry.kt @@ -34,13 +34,19 @@ interface AndroidInstrumentationRegistry { fun register(instrumentation: AndroidInstrumentation) companion object { - private val instance: AndroidInstrumentationRegistry by lazy { - AndroidInstrumentationRegistryImpl() - } + private var instance: AndroidInstrumentationRegistry? = null @JvmStatic fun get(): AndroidInstrumentationRegistry { - return instance + if (instance == null) { + instance = AndroidInstrumentationRegistryImpl() + } + return instance!! + } + + @JvmStatic + fun resetForTest() { + instance = null } } } diff --git a/android-agent/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImpl.kt b/core/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImpl.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImpl.kt rename to core/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImpl.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractor.java b/core/src/main/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractor.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractor.java rename to core/src/main/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractor.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppender.java b/core/src/main/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppender.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppender.java rename to core/src/main/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppender.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/features/persistence/DiskManager.kt b/core/src/main/java/io/opentelemetry/android/internal/features/persistence/DiskManager.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/features/persistence/DiskManager.kt rename to core/src/main/java/io/opentelemetry/android/internal/features/persistence/DiskManager.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt b/core/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt rename to core/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/initialization/InitializationEvents.kt b/core/src/main/java/io/opentelemetry/android/internal/initialization/InitializationEvents.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/initialization/InitializationEvents.kt rename to core/src/main/java/io/opentelemetry/android/internal/initialization/InitializationEvents.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt b/core/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt rename to core/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/CacheStorage.java b/core/src/main/java/io/opentelemetry/android/internal/services/CacheStorage.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/CacheStorage.java rename to core/src/main/java/io/opentelemetry/android/internal/services/CacheStorage.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/Preferences.java b/core/src/main/java/io/opentelemetry/android/internal/services/Preferences.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/Preferences.java rename to core/src/main/java/io/opentelemetry/android/internal/services/Preferences.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/ServiceManager.kt b/core/src/main/java/io/opentelemetry/android/internal/services/ServiceManager.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/ServiceManager.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/ServiceManager.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt b/core/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/Startable.java b/core/src/main/java/io/opentelemetry/android/internal/services/Startable.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/Startable.java rename to core/src/main/java/io/opentelemetry/android/internal/services/Startable.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt b/core/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateListener.java b/core/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateListener.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateListener.java rename to core/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateListener.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcher.kt b/core/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcher.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcher.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcher.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/CarrierFinder.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/CarrierFinder.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/CarrierFinder.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/CarrierFinder.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProvider.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProvider.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProvider.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProvider.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/NetworkChangeListener.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/NetworkChangeListener.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/NetworkChangeListener.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/NetworkChangeListener.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/data/Carrier.kt b/core/src/main/java/io/opentelemetry/android/internal/services/network/data/Carrier.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/data/Carrier.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/network/data/Carrier.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/data/CurrentNetwork.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/data/CurrentNetwork.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/data/CurrentNetwork.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/data/CurrentNetwork.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/data/NetworkState.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/data/NetworkState.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/data/NetworkState.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/data/NetworkState.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetector.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetector.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetector.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetector.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetector.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetector.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetector.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetector.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetector.java b/core/src/main/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetector.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetector.java rename to core/src/main/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetector.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt b/core/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkService.kt b/core/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkService.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkService.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkService.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt b/core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/DefaultingActivityLifecycleCallbacks.java b/core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/DefaultingActivityLifecycleCallbacks.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/DefaultingActivityLifecycleCallbacks.java rename to core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/DefaultingActivityLifecycleCallbacks.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.java b/core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.java rename to core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.java b/core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.java rename to core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegisterer.java b/core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegisterer.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegisterer.java rename to core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegisterer.java diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt b/core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt rename to core/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/internal/tools/time/SystemTime.kt b/core/src/main/java/io/opentelemetry/android/internal/tools/time/SystemTime.kt similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/internal/tools/time/SystemTime.kt rename to core/src/main/java/io/opentelemetry/android/internal/tools/time/SystemTime.kt diff --git a/android-agent/src/main/java/io/opentelemetry/android/package-info.java b/core/src/main/java/io/opentelemetry/android/package-info.java similarity index 100% rename from android-agent/src/main/java/io/opentelemetry/android/package-info.java rename to core/src/main/java/io/opentelemetry/android/package-info.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/AndroidResourceTest.java b/core/src/test/java/io/opentelemetry/android/AndroidResourceTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/AndroidResourceTest.java rename to core/src/test/java/io/opentelemetry/android/AndroidResourceTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/GlobalAttributesSpanAppenderTest.java b/core/src/test/java/io/opentelemetry/android/GlobalAttributesSpanAppenderTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/GlobalAttributesSpanAppenderTest.java rename to core/src/test/java/io/opentelemetry/android/GlobalAttributesSpanAppenderTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/OpenTelemetryRumBuilderTest.java b/core/src/test/java/io/opentelemetry/android/OpenTelemetryRumBuilderTest.java similarity index 89% rename from android-agent/src/test/java/io/opentelemetry/android/OpenTelemetryRumBuilderTest.java rename to core/src/test/java/io/opentelemetry/android/OpenTelemetryRumBuilderTest.java index fb95f78b2..b5f56d680 100644 --- a/android-agent/src/test/java/io/opentelemetry/android/OpenTelemetryRumBuilderTest.java +++ b/core/src/test/java/io/opentelemetry/android/OpenTelemetryRumBuilderTest.java @@ -13,12 +13,15 @@ import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.notNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import android.app.Activity; @@ -30,6 +33,8 @@ import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfiguration; import io.opentelemetry.android.features.diskbuffering.SignalFromDiskExporter; import io.opentelemetry.android.features.diskbuffering.scheduler.ExportScheduleHandler; +import io.opentelemetry.android.instrumentation.AndroidInstrumentation; +import io.opentelemetry.android.instrumentation.AndroidInstrumentationRegistry; import io.opentelemetry.android.internal.initialization.InitializationEvents; import io.opentelemetry.android.internal.services.CacheStorage; import io.opentelemetry.android.internal.services.Preferences; @@ -73,7 +78,6 @@ import java.util.function.Function; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -111,8 +115,9 @@ public void setup() { @After public void tearDown() throws Exception { SignalFromDiskExporter.resetForTesting(); - mocks.close(); InitializationEvents.resetForTest(); + AndroidInstrumentationRegistry.resetForTest(); + mocks.close(); } @Test @@ -187,27 +192,43 @@ public void shouldBuildLogRecordProvider() { assertThat(payload.get(0)).isEqualTo(expected); } - @Ignore("To be updated once AndroidInstrumentation is fully implemented") @Test public void shouldInstallInstrumentation() { - OpenTelemetryRum.builder(application, buildConfig()) - .addInstrumentation( - instrumentedApplication -> { - assertThat(instrumentedApplication.getApplication()) - .isSameAs(application); - // - // instrumentedApplication.registerApplicationStateListener(listener); - // TODO update with AndroidInstrumentation - }) - .build(); + ServiceManager serviceManager = createServiceManager(); + SessionIdTimeoutHandler timeoutHandler = mock(); + AndroidInstrumentation localInstrumentation = mock(); + AndroidInstrumentation classpathInstrumentation = mock(); + AndroidInstrumentationRegistry.get().register(classpathInstrumentation); - verify(application).registerActivityLifecycleCallbacks(activityCallbacksCaptor.capture()); + new OpenTelemetryRumBuilder(application, buildConfig(), timeoutHandler) + .addInstrumentation(localInstrumentation) + .build(serviceManager); - activityCallbacksCaptor.getValue().onActivityStarted(activity); - verify(listener).onApplicationForegrounded(); + verify(serviceManager.getAppLifecycleService()).registerListener(timeoutHandler); - activityCallbacksCaptor.getValue().onActivityStopped(activity); - verify(listener).onApplicationBackgrounded(); + verify(localInstrumentation).install(eq(application), notNull()); + verify(classpathInstrumentation).install(eq(application), notNull()); + } + + @Test + public void shouldInstallInstrumentation_excludingClasspathImplsWhenRequestedInConfig() { + ServiceManager serviceManager = createServiceManager(); + SessionIdTimeoutHandler timeoutHandler = mock(); + AndroidInstrumentation localInstrumentation = mock(); + AndroidInstrumentation classpathInstrumentation = mock(); + AndroidInstrumentationRegistry.get().register(classpathInstrumentation); + + new OpenTelemetryRumBuilder( + application, + buildConfig().disableInstrumentationDiscovery(), + timeoutHandler) + .addInstrumentation(localInstrumentation) + .build(serviceManager); + + verify(serviceManager.getAppLifecycleService()).registerListener(timeoutHandler); + + verify(localInstrumentation).install(eq(application), notNull()); + verifyNoInteractions(classpathInstrumentation); } @Test diff --git a/android-agent/src/test/java/io/opentelemetry/android/RuntimeDetailsExtractorTest.java b/core/src/test/java/io/opentelemetry/android/RuntimeDetailsExtractorTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/RuntimeDetailsExtractorTest.java rename to core/src/test/java/io/opentelemetry/android/RuntimeDetailsExtractorTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/ScreenAttributesSpanProcessorTest.java b/core/src/test/java/io/opentelemetry/android/ScreenAttributesSpanProcessorTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/ScreenAttributesSpanProcessorTest.java rename to core/src/test/java/io/opentelemetry/android/ScreenAttributesSpanProcessorTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/SessionIdChangeTracerTest.java b/core/src/test/java/io/opentelemetry/android/SessionIdChangeTracerTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/SessionIdChangeTracerTest.java rename to core/src/test/java/io/opentelemetry/android/SessionIdChangeTracerTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/SessionIdRatioBasedSamplerTest.java b/core/src/test/java/io/opentelemetry/android/SessionIdRatioBasedSamplerTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/SessionIdRatioBasedSamplerTest.java rename to core/src/test/java/io/opentelemetry/android/SessionIdRatioBasedSamplerTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/SessionIdSpanAppenderTest.java b/core/src/test/java/io/opentelemetry/android/SessionIdSpanAppenderTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/SessionIdSpanAppenderTest.java rename to core/src/test/java/io/opentelemetry/android/SessionIdSpanAppenderTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/SessionIdTest.java b/core/src/test/java/io/opentelemetry/android/SessionIdTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/SessionIdTest.java rename to core/src/test/java/io/opentelemetry/android/SessionIdTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java b/core/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java rename to core/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/export/AttributeModifyingSpanExporterTest.java b/core/src/test/java/io/opentelemetry/android/export/AttributeModifyingSpanExporterTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/export/AttributeModifyingSpanExporterTest.java rename to core/src/test/java/io/opentelemetry/android/export/AttributeModifyingSpanExporterTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/export/FilteringSpanExporterTest.java b/core/src/test/java/io/opentelemetry/android/export/FilteringSpanExporterTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/export/FilteringSpanExporterTest.java rename to core/src/test/java/io/opentelemetry/android/export/FilteringSpanExporterTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/export/ModifiedSpanDataTest.java b/core/src/test/java/io/opentelemetry/android/export/ModifiedSpanDataTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/export/ModifiedSpanDataTest.java rename to core/src/test/java/io/opentelemetry/android/export/ModifiedSpanDataTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/export/SpanDataModifierTest.java b/core/src/test/java/io/opentelemetry/android/export/SpanDataModifierTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/export/SpanDataModifierTest.java rename to core/src/test/java/io/opentelemetry/android/export/SpanDataModifierTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/export/TestSpanHelper.java b/core/src/test/java/io/opentelemetry/android/export/TestSpanHelper.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/export/TestSpanHelper.java rename to core/src/test/java/io/opentelemetry/android/export/TestSpanHelper.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandlerTest.kt b/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandlerTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandlerTest.kt rename to core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandlerTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt b/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt rename to core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt b/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt rename to core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImplTest.kt b/core/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImplTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImplTest.kt rename to core/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryImplTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryTest.kt b/core/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryTest.kt rename to core/src/test/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationRegistryTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/instrumentation/TestAndroidInstrumentation.kt b/core/src/test/java/io/opentelemetry/android/instrumentation/TestAndroidInstrumentation.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/instrumentation/TestAndroidInstrumentation.kt rename to core/src/test/java/io/opentelemetry/android/instrumentation/TestAndroidInstrumentation.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractorTest.java b/core/src/test/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractorTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractorTest.java rename to core/src/test/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractorTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppenderTest.java b/core/src/test/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppenderTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppenderTest.java rename to core/src/test/java/io/opentelemetry/android/internal/features/networkattrs/NetworkAttributesSpanAppenderTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/features/persistence/DiskManagerTest.kt b/core/src/test/java/io/opentelemetry/android/internal/features/persistence/DiskManagerTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/features/persistence/DiskManagerTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/features/persistence/DiskManagerTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProviderTest.kt b/core/src/test/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProviderTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProviderTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProviderTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/initialization/InitializationEventsTest.kt b/core/src/test/java/io/opentelemetry/android/internal/initialization/InitializationEventsTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/initialization/InitializationEventsTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/initialization/InitializationEventsTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/initialization/TestInitializationEvents.kt b/core/src/test/java/io/opentelemetry/android/internal/initialization/TestInitializationEvents.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/initialization/TestInitializationEvents.kt rename to core/src/test/java/io/opentelemetry/android/internal/initialization/TestInitializationEvents.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppenderTest.kt b/core/src/test/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppenderTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppenderTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppenderTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/ServiceManagerImplTest.kt b/core/src/test/java/io/opentelemetry/android/internal/services/ServiceManagerImplTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/ServiceManagerImplTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/services/ServiceManagerImplTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleServiceTest.kt b/core/src/test/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleServiceTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleServiceTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleServiceTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcherTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcherTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcherTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateWatcherTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/network/CarrierFinderTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/network/CarrierFinderTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/network/CarrierFinderTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/network/CarrierFinderTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProviderTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProviderTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProviderTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/network/CurrentNetworkProviderTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetectorTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetectorTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetectorTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/network/detector/NetworkDetectorTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetectorTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetectorTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetectorTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/network/detector/PostApi28NetworkDetectorTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetectorTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetectorTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetectorTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/network/detector/SimpleNetworkDetectorTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt b/core/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkServiceTest.kt b/core/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkServiceTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkServiceTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicWorkServiceTest.kt diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenServiceTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenServiceTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenServiceTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenServiceTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBindingTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBindingTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBindingTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBindingTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBindingTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBindingTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBindingTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBindingTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegistererTest.java b/core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegistererTest.java similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegistererTest.java rename to core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/RumFragmentActivityRegistererTest.java diff --git a/android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTrackerTest.kt b/core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTrackerTest.kt similarity index 100% rename from android-agent/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTrackerTest.kt rename to core/src/test/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTrackerTest.kt diff --git a/android-agent/src/test/resources/META-INF/services/io.opentelemetry.android.instrumentation.AndroidInstrumentation b/core/src/test/resources/META-INF/services/io.opentelemetry.android.instrumentation.AndroidInstrumentation similarity index 100% rename from android-agent/src/test/resources/META-INF/services/io.opentelemetry.android.instrumentation.AndroidInstrumentation rename to core/src/test/resources/META-INF/services/io.opentelemetry.android.instrumentation.AndroidInstrumentation diff --git a/android-agent/src/test/resources/META-INF/services/io.opentelemetry.android.internal.initialization.InitializationEvents b/core/src/test/resources/META-INF/services/io.opentelemetry.android.internal.initialization.InitializationEvents similarity index 100% rename from android-agent/src/test/resources/META-INF/services/io.opentelemetry.android.internal.initialization.InitializationEvents rename to core/src/test/resources/META-INF/services/io.opentelemetry.android.internal.initialization.InitializationEvents diff --git a/demo-app/src/main/java/io/opentelemetry/android/demo/OtelDemoApplication.kt b/demo-app/src/main/java/io/opentelemetry/android/demo/OtelDemoApplication.kt index 71dd1a0d5..fa0726f60 100644 --- a/demo-app/src/main/java/io/opentelemetry/android/demo/OtelDemoApplication.kt +++ b/demo-app/src/main/java/io/opentelemetry/android/demo/OtelDemoApplication.kt @@ -10,6 +10,7 @@ import android.app.Application import android.util.Log import io.opentelemetry.android.OpenTelemetryRum import io.opentelemetry.android.OpenTelemetryRumBuilder +import io.opentelemetry.android.agent.setSlowRenderingDetectionPollInterval import io.opentelemetry.android.config.OtelRumConfig import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfiguration import io.opentelemetry.api.common.AttributeKey.stringKey @@ -19,6 +20,7 @@ import io.opentelemetry.api.trace.Tracer import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider +import java.time.Duration import kotlin.math.log const val TAG = "otel.demo" diff --git a/instrumentation/activity/build.gradle.kts b/instrumentation/activity/build.gradle.kts index 19ddee44a..894287c91 100644 --- a/instrumentation/activity/build.gradle.kts +++ b/instrumentation/activity/build.gradle.kts @@ -16,9 +16,8 @@ android { dependencies { api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) - api(project(":common")) api(project(":instrumentation:common-api")) - api(project(":android-agent")) + api(project(":core")) implementation(libs.opentelemetry.sdk) implementation(libs.androidx.core) implementation(libs.androidx.navigation.fragment) diff --git a/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityLifecycleInstrumentation.kt b/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityLifecycleInstrumentation.kt index 154927a04..fd1efce35 100644 --- a/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityLifecycleInstrumentation.kt +++ b/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityLifecycleInstrumentation.kt @@ -7,6 +7,7 @@ package io.opentelemetry.android.instrumentation.activity import android.app.Application import android.os.Build +import com.google.auto.service.AutoService import io.opentelemetry.android.OpenTelemetryRum import io.opentelemetry.android.instrumentation.AndroidInstrumentation import io.opentelemetry.android.instrumentation.activity.startup.AppStartupTimer @@ -16,6 +17,7 @@ import io.opentelemetry.android.internal.services.ServiceManager import io.opentelemetry.android.internal.services.visiblescreen.activities.DefaultingActivityLifecycleCallbacks import io.opentelemetry.api.trace.Tracer +@AutoService(AndroidInstrumentation::class) class ActivityLifecycleInstrumentation : AndroidInstrumentation { private val startupTimer: AppStartupTimer by lazy { AppStartupTimer() } private var screenNameExtractor: ScreenNameExtractor = ScreenNameExtractor.DEFAULT diff --git a/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityTracer.java b/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityTracer.java index 405beb2e2..4c9dd69f1 100644 --- a/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityTracer.java +++ b/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityTracer.java @@ -12,8 +12,8 @@ import android.app.Activity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import io.opentelemetry.android.common.ActiveSpan; import io.opentelemetry.android.instrumentation.activity.startup.AppStartupTimer; +import io.opentelemetry.android.instrumentation.common.ActiveSpan; import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenService; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.Span; diff --git a/instrumentation/activity/src/test/java/io/opentelemetry/android/instrumentation/activity/ActivityTracerTest.java b/instrumentation/activity/src/test/java/io/opentelemetry/android/instrumentation/activity/ActivityTracerTest.java index 4ed1848bd..d6f770f76 100644 --- a/instrumentation/activity/src/test/java/io/opentelemetry/android/instrumentation/activity/ActivityTracerTest.java +++ b/instrumentation/activity/src/test/java/io/opentelemetry/android/instrumentation/activity/ActivityTracerTest.java @@ -14,8 +14,8 @@ import static org.mockito.Mockito.when; import android.app.Activity; -import io.opentelemetry.android.common.ActiveSpan; import io.opentelemetry.android.instrumentation.activity.startup.AppStartupTimer; +import io.opentelemetry.android.instrumentation.common.ActiveSpan; import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenService; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension; diff --git a/instrumentation/anr/build.gradle.kts b/instrumentation/anr/build.gradle.kts index ce7e66425..e14774d1d 100644 --- a/instrumentation/anr/build.gradle.kts +++ b/instrumentation/anr/build.gradle.kts @@ -20,7 +20,7 @@ android { dependencies { api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) - api(project(":android-agent")) + api(project(":core")) implementation(libs.androidx.core) implementation(libs.opentelemetry.semconv) implementation(libs.opentelemetry.sdk) diff --git a/instrumentation/anr/src/main/java/io/opentelemetry/android/instrumentation/anr/AnrInstrumentation.java b/instrumentation/anr/src/main/java/io/opentelemetry/android/instrumentation/anr/AnrInstrumentation.java index f9be192dc..0188f06b8 100644 --- a/instrumentation/anr/src/main/java/io/opentelemetry/android/instrumentation/anr/AnrInstrumentation.java +++ b/instrumentation/anr/src/main/java/io/opentelemetry/android/instrumentation/anr/AnrInstrumentation.java @@ -8,6 +8,7 @@ import android.app.Application; import android.os.Looper; import androidx.annotation.NonNull; +import com.google.auto.service.AutoService; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.instrumentation.AndroidInstrumentation; import io.opentelemetry.android.internal.services.ServiceManager; @@ -18,6 +19,7 @@ import java.util.concurrent.ScheduledExecutorService; /** Entry point for {@link AnrDetector}. */ +@AutoService(AndroidInstrumentation.class) public final class AnrInstrumentation implements AndroidInstrumentation { final List> additionalExtractors = diff --git a/instrumentation/common-api/build.gradle.kts b/instrumentation/common-api/build.gradle.kts index 8592bbc1f..6eef21d41 100644 --- a/instrumentation/common-api/build.gradle.kts +++ b/instrumentation/common-api/build.gradle.kts @@ -14,6 +14,7 @@ android { } dependencies { + api(project(":core")) api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) implementation(libs.androidx.navigation.fragment) diff --git a/common/src/main/java/io/opentelemetry/android/common/ActiveSpan.java b/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/ActiveSpan.java similarity index 93% rename from common/src/main/java/io/opentelemetry/android/common/ActiveSpan.java rename to instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/ActiveSpan.java index f54ec68bc..49d700cfb 100644 --- a/common/src/main/java/io/opentelemetry/android/common/ActiveSpan.java +++ b/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/ActiveSpan.java @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.android.common; +package io.opentelemetry.android.instrumentation.common; import androidx.annotation.Nullable; +import io.opentelemetry.android.common.RumConstants; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Scope; import java.util.function.Supplier; diff --git a/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/ApplicationStateListener.java b/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/ApplicationStateListener.java deleted file mode 100644 index ce9376557..000000000 --- a/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/ApplicationStateListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.android.instrumentation.common; - -/** - * Listener interface that is called whenever the instrumented application is brought to foreground - * from the background, or vice versa. - * - *

This class is internal and is hence not for public use. Its APIs are unstable and can change - * at any time. - */ -public interface ApplicationStateListener { - - /** - * Called whenever the application is brought to the foreground (i.e. first activity starts). - */ - void onApplicationForegrounded(); - - /** Called whenever the application is brought to the background (i.e. last activity stops). */ - void onApplicationBackgrounded(); -} diff --git a/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/InstrumentedApplication.java b/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/InstrumentedApplication.java deleted file mode 100644 index c2ad7a834..000000000 --- a/instrumentation/common-api/src/main/java/io/opentelemetry/android/instrumentation/common/InstrumentedApplication.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.android.instrumentation.common; - -import android.app.Application; -import io.opentelemetry.sdk.OpenTelemetrySdk; - -/** - * Provides access to the {@linkplain OpenTelemetrySdk OpenTelemetry SDK}, the instrumented {@link - * Application}, allows registering {@linkplain ApplicationStateListener listeners}. - * - *

This class is internal and is hence not for public use. Its APIs are unstable and can change - * at any time. - */ -public interface InstrumentedApplication { - - /** Returns the instrumented {@link Application}. */ - Application getApplication(); - - /** Returns the {@link OpenTelemetrySdk} instance. */ - OpenTelemetrySdk getOpenTelemetrySdk(); - - /** - * Registers the passed {@link ApplicationStateListener} - from now on it will be called - * whenever the application is moved from background to foreground, and vice versa. - * - *

Users of this method should take care to avoid passing the same listener instance multiple - * times; duplicates are not trimmed. - */ - void registerApplicationStateListener(ApplicationStateListener listener); -} diff --git a/instrumentation/crash/build.gradle.kts b/instrumentation/crash/build.gradle.kts index b9edf7115..427682984 100644 --- a/instrumentation/crash/build.gradle.kts +++ b/instrumentation/crash/build.gradle.kts @@ -16,7 +16,7 @@ android { dependencies { api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) - api(project(":android-agent")) + api(project(":core")) implementation(libs.androidx.core) implementation(libs.opentelemetry.semconv.incubating) implementation(libs.opentelemetry.sdk) diff --git a/instrumentation/crash/src/main/java/io/opentelemetry/android/instrumentation/crash/CrashReporterInstrumentation.java b/instrumentation/crash/src/main/java/io/opentelemetry/android/instrumentation/crash/CrashReporterInstrumentation.java index 286244c61..36713627a 100644 --- a/instrumentation/crash/src/main/java/io/opentelemetry/android/instrumentation/crash/CrashReporterInstrumentation.java +++ b/instrumentation/crash/src/main/java/io/opentelemetry/android/instrumentation/crash/CrashReporterInstrumentation.java @@ -7,6 +7,7 @@ import android.app.Application; import androidx.annotation.NonNull; +import com.google.auto.service.AutoService; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.RuntimeDetailsExtractor; import io.opentelemetry.android.instrumentation.AndroidInstrumentation; @@ -16,6 +17,7 @@ import java.util.List; /** Entrypoint for installing the crash reporting instrumentation. */ +@AutoService(AndroidInstrumentation.class) public final class CrashReporterInstrumentation implements AndroidInstrumentation { private final List> additionalExtractors = new ArrayList<>(); diff --git a/instrumentation/fragment/build.gradle.kts b/instrumentation/fragment/build.gradle.kts index 8c737246e..45b98b701 100644 --- a/instrumentation/fragment/build.gradle.kts +++ b/instrumentation/fragment/build.gradle.kts @@ -17,8 +17,7 @@ dependencies { api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) api(project(":instrumentation:common-api")) - api(project(":android-agent")) - api(project(":common")) + api(project(":core")) implementation(libs.androidx.core) api(libs.androidx.navigation.fragment) implementation(libs.opentelemetry.sdk) diff --git a/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentLifecycleInstrumentation.kt b/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentLifecycleInstrumentation.kt index 2eeb0ad75..d5676c984 100644 --- a/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentLifecycleInstrumentation.kt +++ b/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentLifecycleInstrumentation.kt @@ -8,6 +8,7 @@ package io.opentelemetry.android.instrumentation.fragment import android.app.Application import android.app.Application.ActivityLifecycleCallbacks import android.os.Build +import com.google.auto.service.AutoService import io.opentelemetry.android.OpenTelemetryRum import io.opentelemetry.android.instrumentation.AndroidInstrumentation import io.opentelemetry.android.instrumentation.common.Constants.INSTRUMENTATION_SCOPE @@ -16,6 +17,7 @@ import io.opentelemetry.android.internal.services.ServiceManager import io.opentelemetry.android.internal.services.visiblescreen.fragments.RumFragmentActivityRegisterer import io.opentelemetry.api.trace.Tracer +@AutoService(AndroidInstrumentation::class) class FragmentLifecycleInstrumentation : AndroidInstrumentation { private var screenNameExtractor = ScreenNameExtractor.DEFAULT private var tracerCustomizer: (Tracer) -> Tracer = { it } diff --git a/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracer.java b/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracer.java index df11cd0ff..cd3e8efa3 100644 --- a/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracer.java +++ b/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracer.java @@ -6,8 +6,8 @@ package io.opentelemetry.android.instrumentation.fragment; import androidx.fragment.app.Fragment; -import io.opentelemetry.android.common.ActiveSpan; import io.opentelemetry.android.common.RumConstants; +import io.opentelemetry.android.instrumentation.common.ActiveSpan; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.Tracer; diff --git a/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/RumFragmentLifecycleCallbacks.java b/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/RumFragmentLifecycleCallbacks.java index 7d4b8e3bd..bc0ce6486 100644 --- a/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/RumFragmentLifecycleCallbacks.java +++ b/instrumentation/fragment/src/main/java/io/opentelemetry/android/instrumentation/fragment/RumFragmentLifecycleCallbacks.java @@ -12,7 +12,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; -import io.opentelemetry.android.common.ActiveSpan; +import io.opentelemetry.android.instrumentation.common.ActiveSpan; import io.opentelemetry.android.instrumentation.common.ScreenNameExtractor; import io.opentelemetry.api.trace.Tracer; import java.util.HashMap; diff --git a/instrumentation/fragment/src/test/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracerTest.java b/instrumentation/fragment/src/test/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracerTest.java index 3dfbde599..b9b1999e1 100644 --- a/instrumentation/fragment/src/test/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracerTest.java +++ b/instrumentation/fragment/src/test/java/io/opentelemetry/android/instrumentation/fragment/FragmentTracerTest.java @@ -12,7 +12,7 @@ import static org.mockito.Mockito.when; import androidx.fragment.app.Fragment; -import io.opentelemetry.android.common.ActiveSpan; +import io.opentelemetry.android.instrumentation.common.ActiveSpan; import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenService; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension; diff --git a/instrumentation/network/build.gradle.kts b/instrumentation/network/build.gradle.kts index 651b4afe2..5635231cd 100644 --- a/instrumentation/network/build.gradle.kts +++ b/instrumentation/network/build.gradle.kts @@ -21,7 +21,7 @@ android { dependencies { api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) - api(project(":android-agent")) + api(project(":core")) api(project(":instrumentation:common-api")) implementation(libs.androidx.core) implementation(libs.opentelemetry.semconv.incubating) diff --git a/instrumentation/network/src/main/java/io/opentelemetry/android/instrumentation/network/NetworkChangeInstrumentation.java b/instrumentation/network/src/main/java/io/opentelemetry/android/instrumentation/network/NetworkChangeInstrumentation.java index e2364b042..c5bee1951 100644 --- a/instrumentation/network/src/main/java/io/opentelemetry/android/instrumentation/network/NetworkChangeInstrumentation.java +++ b/instrumentation/network/src/main/java/io/opentelemetry/android/instrumentation/network/NetworkChangeInstrumentation.java @@ -7,6 +7,7 @@ import android.app.Application; import androidx.annotation.NonNull; +import com.google.auto.service.AutoService; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.instrumentation.AndroidInstrumentation; import io.opentelemetry.android.internal.services.ServiceManager; @@ -17,6 +18,7 @@ import java.util.List; /** Generates telemetry for when the network status changes. */ +@AutoService(AndroidInstrumentation.class) public final class NetworkChangeInstrumentation implements AndroidInstrumentation { final List> additionalExtractors = new ArrayList<>(); diff --git a/instrumentation/slowrendering/build.gradle.kts b/instrumentation/slowrendering/build.gradle.kts index 2c2cf518e..96eaaf9de 100644 --- a/instrumentation/slowrendering/build.gradle.kts +++ b/instrumentation/slowrendering/build.gradle.kts @@ -16,8 +16,7 @@ android { dependencies { api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) - api(project(":android-agent")) - api(project(":common")) + api(project(":core")) api(project(":instrumentation:common-api")) implementation(libs.androidx.core) implementation(libs.opentelemetry.semconv) diff --git a/instrumentation/slowrendering/src/main/java/io/opentelemetry/android/instrumentation/slowrendering/SlowRenderingInstrumentation.java b/instrumentation/slowrendering/src/main/java/io/opentelemetry/android/instrumentation/slowrendering/SlowRenderingInstrumentation.java index 55c9f2091..fd997bc85 100644 --- a/instrumentation/slowrendering/src/main/java/io/opentelemetry/android/instrumentation/slowrendering/SlowRenderingInstrumentation.java +++ b/instrumentation/slowrendering/src/main/java/io/opentelemetry/android/instrumentation/slowrendering/SlowRenderingInstrumentation.java @@ -10,12 +10,14 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; +import com.google.auto.service.AutoService; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.common.RumConstants; import io.opentelemetry.android.instrumentation.AndroidInstrumentation; import java.time.Duration; /** Entrypoint for installing the slow rendering detection instrumentation. */ +@AutoService(AndroidInstrumentation.class) public final class SlowRenderingInstrumentation implements AndroidInstrumentation { Duration slowRenderingDetectionPollInterval = Duration.ofSeconds(1); diff --git a/instrumentation/startup/build.gradle.kts b/instrumentation/startup/build.gradle.kts index f679f2ac9..fe5e828b8 100644 --- a/instrumentation/startup/build.gradle.kts +++ b/instrumentation/startup/build.gradle.kts @@ -16,8 +16,7 @@ android { dependencies { api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) - api(project(":android-agent")) - api(project(":common")) + api(project(":core")) implementation(libs.androidx.core) implementation(libs.opentelemetry.semconv) implementation(libs.opentelemetry.sdk) diff --git a/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentation.kt b/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentation.kt index fab5df2d6..d2ac31876 100644 --- a/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentation.kt +++ b/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentation.kt @@ -6,10 +6,12 @@ package io.opentelemetry.android.instrumentation.startup import android.app.Application +import com.google.auto.service.AutoService import io.opentelemetry.android.OpenTelemetryRum import io.opentelemetry.android.instrumentation.AndroidInstrumentation import io.opentelemetry.android.internal.initialization.InitializationEvents +@AutoService(AndroidInstrumentation::class) class StartupInstrumentation : AndroidInstrumentation { override fun install( application: Application, diff --git a/settings.gradle.kts b/settings.gradle.kts index 1837c7041..0ed23cc0d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ rootProject.name = "opentelemetry-android" -include(":common") +include(":core") include(":android-agent") include(":instrumentation:activity") include(":instrumentation:anr")