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 index 4139ae9a..4f9e398b 100644 --- a/android-agent/src/main/kotlin/io/opentelemetry/android/agent/OtelRumConfigExtensions.kt +++ b/android-agent/src/main/kotlin/io/opentelemetry/android/agent/OtelRumConfigExtensions.kt @@ -32,49 +32,57 @@ import java.time.Duration */ fun OtelRumConfig.setActivityTracerCustomizer(customizer: (Tracer) -> Tracer): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(ActivityLifecycleInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(ActivityLifecycleInstrumentation::class.java) ?.setTracerCustomizer(customizer) return this } fun OtelRumConfig.setActivityNameExtractor(screenNameExtractor: ScreenNameExtractor): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(ActivityLifecycleInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(ActivityLifecycleInstrumentation::class.java) ?.setScreenNameExtractor(screenNameExtractor) return this } fun OtelRumConfig.setFragmentTracerCustomizer(customizer: (Tracer) -> Tracer): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(FragmentLifecycleInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(FragmentLifecycleInstrumentation::class.java) ?.setTracerCustomizer(customizer) return this } fun OtelRumConfig.setFragmentNameExtractor(screenNameExtractor: ScreenNameExtractor): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(FragmentLifecycleInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(FragmentLifecycleInstrumentation::class.java) ?.setScreenNameExtractor(screenNameExtractor) return this } fun OtelRumConfig.addAnrAttributesExtractor(extractor: AttributesExtractor, Void>): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(AnrInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(AnrInstrumentation::class.java) ?.addAttributesExtractor(extractor) return this } fun OtelRumConfig.addCrashAttributesExtractor(extractor: AttributesExtractor): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(CrashReporterInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(CrashReporterInstrumentation::class.java) ?.addAttributesExtractor(extractor) return this } fun OtelRumConfig.addNetworkChangeAttributesExtractor(extractor: AttributesExtractor): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(NetworkChangeInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(NetworkChangeInstrumentation::class.java) ?.addAttributesExtractor(extractor) return this } fun OtelRumConfig.setSlowRenderingDetectionPollInterval(interval: Duration): OtelRumConfig { - AndroidInstrumentationLoader.getInstrumentation(SlowRenderingInstrumentation::class.java) + AndroidInstrumentationLoader + .getInstrumentation(SlowRenderingInstrumentation::class.java) ?.setSlowRenderingDetectionPollInterval(interval) return this } diff --git a/buildSrc/src/main/kotlin/otel.spotless-conventions.gradle.kts b/buildSrc/src/main/kotlin/otel.spotless-conventions.gradle.kts index 88fb3bc6..4c974eb8 100644 --- a/buildSrc/src/main/kotlin/otel.spotless-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/otel.spotless-conventions.gradle.kts @@ -32,7 +32,7 @@ spotless { "*.sh", "src/**/*.properties" ) - indentWithSpaces() + leadingTabsToSpaces() trimTrailingWhitespace() endWithNewline() } diff --git a/common/src/main/java/io/opentelemetry/android/common/internal/tools/time/SystemTime.kt b/common/src/main/java/io/opentelemetry/android/common/internal/tools/time/SystemTime.kt index 64ff0778..050e5e61 100644 --- a/common/src/main/java/io/opentelemetry/android/common/internal/tools/time/SystemTime.kt +++ b/common/src/main/java/io/opentelemetry/android/common/internal/tools/time/SystemTime.kt @@ -15,9 +15,7 @@ interface SystemTime { companion object { private var instance: SystemTime = DefaultSystemTime() - fun get(): SystemTime { - return instance - } + fun get(): SystemTime = instance fun setForTest(instance: SystemTime) { this.instance = instance @@ -27,8 +25,6 @@ interface SystemTime { fun getCurrentTimeMillis(): Long class DefaultSystemTime : SystemTime { - override fun getCurrentTimeMillis(): Long { - return System.currentTimeMillis() - } + override fun getCurrentTimeMillis(): Long = System.currentTimeMillis() } } diff --git a/core/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt b/core/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt index 93ae85dd..69546da6 100644 --- a/core/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt +++ b/core/src/integrationTest/kotlin/io/opentelemetry/android/AgentInitTest.kt @@ -23,10 +23,11 @@ internal class AgentInitTest { fun startOpenTelemetryRumInAndroid() { val application = getApplicationContext() val otelRum = - OpenTelemetryRum.builder( - application, - OtelRumConfig(), - ).build() + OpenTelemetryRum + .builder( + application, + OtelRumConfig(), + ).build() assertNotNull(otelRum) } } diff --git a/core/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt index 8b2bb233..26c68998 100644 --- a/core/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt +++ b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt @@ -33,12 +33,11 @@ class SignalFromDiskExporter */ @WorkerThread @Throws(IOException::class) - fun exportBatchOfSpans(): Boolean { - return spanFromDiskExporter?.exportStoredBatch( + fun exportBatchOfSpans(): Boolean = + spanFromDiskExporter?.exportStoredBatch( exportTimeoutInMillis, TimeUnit.MILLISECONDS, ) ?: false - } /** * A batch contains all the signals that arrived in one call to [MetricFromDiskExporter.exportStoredBatch]. So if @@ -50,12 +49,11 @@ class SignalFromDiskExporter */ @WorkerThread @Throws(IOException::class) - fun exportBatchOfMetrics(): Boolean { - return metricFromDiskExporter?.exportStoredBatch( + fun exportBatchOfMetrics(): Boolean = + metricFromDiskExporter?.exportStoredBatch( exportTimeoutInMillis, TimeUnit.MILLISECONDS, ) ?: false - } /** * A batch contains all the signals that arrived in one call to [LogRecordFromDiskExporter.exportStoredBatch]. So if @@ -67,12 +65,11 @@ class SignalFromDiskExporter */ @WorkerThread @Throws(IOException::class) - fun exportBatchOfLogs(): Boolean { - return logRecordFromDiskExporter?.exportStoredBatch( + fun exportBatchOfLogs(): Boolean = + logRecordFromDiskExporter?.exportStoredBatch( exportTimeoutInMillis, TimeUnit.MILLISECONDS, ) ?: false - } /** * Convenience method that attempts to export all kinds of signals from disk. @@ -97,9 +94,7 @@ class SignalFromDiskExporter private var instance: SignalFromDiskExporter? = null @JvmStatic - fun get(): SignalFromDiskExporter? { - return instance - } + fun get(): SignalFromDiskExporter? = instance @JvmStatic fun set(signalFromDiskExporter: SignalFromDiskExporter) { diff --git a/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt index e2527778..babc4ac5 100644 --- a/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt +++ b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduleHandler.kt @@ -11,8 +11,7 @@ import java.util.concurrent.atomic.AtomicBoolean class DefaultExportScheduleHandler( private val exportScheduler: DefaultExportScheduler, private val periodicWorkServiceProvider: () -> PeriodicWorkService, -) : - ExportScheduleHandler { +) : ExportScheduleHandler { private val periodicWorkService by lazy { periodicWorkServiceProvider() } private val enabled = AtomicBoolean(false) diff --git a/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt index a508fdfe..b2d8378f 100644 --- a/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt +++ b/core/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt @@ -13,8 +13,9 @@ import io.opentelemetry.android.internal.services.periodicwork.PeriodicWorkServi import java.io.IOException import java.util.concurrent.TimeUnit -class DefaultExportScheduler(periodicWorkServiceProvider: () -> PeriodicWorkService) : - PeriodicRunnable(periodicWorkServiceProvider) { +class DefaultExportScheduler( + periodicWorkServiceProvider: () -> PeriodicWorkService, +) : PeriodicRunnable(periodicWorkServiceProvider) { companion object { private val DELAY_BEFORE_NEXT_EXPORT_IN_MILLIS = TimeUnit.SECONDS.toMillis(10) } @@ -31,11 +32,7 @@ class DefaultExportScheduler(periodicWorkServiceProvider: () -> PeriodicWorkServ } } - override fun shouldStopRunning(): Boolean { - return SignalFromDiskExporter.get() == null - } + override fun shouldStopRunning(): Boolean = SignalFromDiskExporter.get() == null - override fun minimumDelayUntilNextRunInMillis(): Long { - return DELAY_BEFORE_NEXT_EXPORT_IN_MILLIS - } + override fun minimumDelayUntilNextRunInMillis(): Long = DELAY_BEFORE_NEXT_EXPORT_IN_MILLIS } diff --git a/core/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt b/core/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt index e6ea8b5c..36f9606e 100644 --- a/core/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt +++ b/core/src/main/java/io/opentelemetry/android/internal/features/persistence/SimpleTemporaryFileProvider.kt @@ -9,9 +9,9 @@ import io.opentelemetry.contrib.disk.buffering.internal.files.TemporaryFileProvi import java.io.File import java.util.UUID -internal class SimpleTemporaryFileProvider(private val tempDir: File) : TemporaryFileProvider { +internal class SimpleTemporaryFileProvider( + private val tempDir: File, +) : TemporaryFileProvider { /** Creates a unique file instance using the provided prefix and the current time in millis. */ - override fun createTemporaryFile(prefix: String): File { - return File(tempDir, prefix + "_" + UUID.randomUUID() + ".tmp") - } + override fun createTemporaryFile(prefix: String): File = File(tempDir, prefix + "_" + UUID.randomUUID() + ".tmp") } diff --git a/core/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt b/core/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt index 3b33b90c..7cd5ac91 100644 --- a/core/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt +++ b/core/src/main/java/io/opentelemetry/android/internal/processors/GlobalAttributesLogRecordAppender.kt @@ -11,8 +11,9 @@ import io.opentelemetry.sdk.logs.LogRecordProcessor import io.opentelemetry.sdk.logs.ReadWriteLogRecord import java.util.function.Supplier -internal class GlobalAttributesLogRecordAppender(private val attributesSupplier: Supplier) : - LogRecordProcessor { +internal class GlobalAttributesLogRecordAppender( + private val attributesSupplier: Supplier, +) : LogRecordProcessor { override fun onEmit( context: Context, logRecord: ReadWriteLogRecord, diff --git a/core/src/main/java/io/opentelemetry/android/internal/processors/ScreenAttributesLogRecordProcessor.kt b/core/src/main/java/io/opentelemetry/android/internal/processors/ScreenAttributesLogRecordProcessor.kt index a4156d47..0fe6c6d3 100644 --- a/core/src/main/java/io/opentelemetry/android/internal/processors/ScreenAttributesLogRecordProcessor.kt +++ b/core/src/main/java/io/opentelemetry/android/internal/processors/ScreenAttributesLogRecordProcessor.kt @@ -11,7 +11,9 @@ import io.opentelemetry.context.Context import io.opentelemetry.sdk.logs.LogRecordProcessor import io.opentelemetry.sdk.logs.ReadWriteLogRecord -class ScreenAttributesLogRecordProcessor(val visibleScreenService: VisibleScreenService) : LogRecordProcessor { +class ScreenAttributesLogRecordProcessor( + val visibleScreenService: VisibleScreenService, +) : LogRecordProcessor { override fun onEmit( context: Context, logRecord: ReadWriteLogRecord, diff --git a/core/src/main/java/io/opentelemetry/android/internal/processors/SessionIdLogRecordAppender.kt b/core/src/main/java/io/opentelemetry/android/internal/processors/SessionIdLogRecordAppender.kt index 12e5548f..d4fcf947 100644 --- a/core/src/main/java/io/opentelemetry/android/internal/processors/SessionIdLogRecordAppender.kt +++ b/core/src/main/java/io/opentelemetry/android/internal/processors/SessionIdLogRecordAppender.kt @@ -11,8 +11,9 @@ import io.opentelemetry.sdk.logs.LogRecordProcessor import io.opentelemetry.sdk.logs.ReadWriteLogRecord import io.opentelemetry.semconv.incubating.SessionIncubatingAttributes.SESSION_ID -internal class SessionIdLogRecordAppender(private val sessionProvider: SessionProvider) : - LogRecordProcessor { +internal class SessionIdLogRecordAppender( + private val sessionProvider: SessionProvider, +) : LogRecordProcessor { override fun onEmit( context: Context, logRecord: ReadWriteLogRecord, diff --git a/core/src/main/java/io/opentelemetry/android/session/Session.kt b/core/src/main/java/io/opentelemetry/android/session/Session.kt index 144976f6..2971ad83 100644 --- a/core/src/main/java/io/opentelemetry/android/session/Session.kt +++ b/core/src/main/java/io/opentelemetry/android/session/Session.kt @@ -14,14 +14,13 @@ interface Session { val NONE = DefaultSession("", -1) } - data class DefaultSession(private val id: String, private val timestamp: Long) : Session { - override fun getId(): String { - return id - } + data class DefaultSession( + private val id: String, + private val timestamp: Long, + ) : Session { + override fun getId(): String = id - override fun getStartTimestamp(): Long { - return timestamp - } + override fun getStartTimestamp(): Long = timestamp override fun equals(other: Any?): Boolean { if (this === other) return true @@ -32,8 +31,6 @@ interface Session { return id == other.id } - override fun hashCode(): Int { - return id.hashCode() - } + override fun hashCode(): Int = id.hashCode() } } diff --git a/core/src/main/java/io/opentelemetry/android/session/SessionManager.kt b/core/src/main/java/io/opentelemetry/android/session/SessionManager.kt index 7608da1b..f86f260a 100644 --- a/core/src/main/java/io/opentelemetry/android/session/SessionManager.kt +++ b/core/src/main/java/io/opentelemetry/android/session/SessionManager.kt @@ -16,7 +16,8 @@ internal class SessionManager( private val timeoutHandler: SessionIdTimeoutHandler, private val idGenerator: SessionIdGenerator = SessionIdGenerator.DEFAULT, private val sessionLifetimeNanos: Long = TimeUnit.HOURS.toNanos(4), -) : SessionProvider, SessionPublisher { +) : SessionProvider, + SessionPublisher { // TODO: Make thread safe / wrap with AtomicReference? private var session: Session = Session.NONE private val observers = synchronizedList(ArrayList()) @@ -69,11 +70,10 @@ internal class SessionManager( fun create( timeoutHandler: SessionIdTimeoutHandler, sessionLifetimeNanos: Long, - ): SessionManager { - return SessionManager( + ): SessionManager = + SessionManager( timeoutHandler = timeoutHandler, sessionLifetimeNanos = sessionLifetimeNanos, ) - } } } diff --git a/core/src/main/java/io/opentelemetry/android/session/SessionStorage.kt b/core/src/main/java/io/opentelemetry/android/session/SessionStorage.kt index 3d6aa1de..b7bc0c25 100644 --- a/core/src/main/java/io/opentelemetry/android/session/SessionStorage.kt +++ b/core/src/main/java/io/opentelemetry/android/session/SessionStorage.kt @@ -13,9 +13,7 @@ interface SessionStorage { class InMemory( @Volatile var session: Session = Session.NONE, ) : SessionStorage { - override fun get(): Session { - return session - } + override fun get(): Session = session override fun save(newSession: Session) { this.session = newSession diff --git a/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt b/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt index 57e951bf..4c39ba1e 100644 --- a/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt +++ b/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportSchedulerTest.kt @@ -33,7 +33,9 @@ class DefaultExportSchedulerTest { @Test fun `Try to export all available signals when running`() { val signalFromDiskExporter = mockk() - every { signalFromDiskExporter.exportBatchOfEach() }.returns(true).andThen(true) + every { signalFromDiskExporter.exportBatchOfEach() } + .returns(true) + .andThen(true) .andThen(false) SignalFromDiskExporter.set(signalFromDiskExporter) diff --git a/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt b/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt index a867a793..76d4544c 100644 --- a/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt +++ b/core/src/test/java/io/opentelemetry/android/features/diskbuffering/scheduler/SignalFromDiskExporterTest.kt @@ -164,8 +164,8 @@ class SignalFromDiskExporterTest { metricFromDiskExporter: MetricFromDiskExporter?, logRecordFromDiskExporter: LogRecordFromDiskExporter?, exportTimeoutInMillis: Long? = null, - ): SignalFromDiskExporter { - return if (exportTimeoutInMillis == null) { + ): SignalFromDiskExporter = + if (exportTimeoutInMillis == null) { SignalFromDiskExporter( spanFromDiskExporter, metricFromDiskExporter, @@ -179,5 +179,4 @@ class SignalFromDiskExporterTest { exportTimeoutInMillis, ) } - } } diff --git a/demo-app/gradle/libs.versions.toml b/demo-app/gradle/libs.versions.toml index 9b81ac7b..5b25c3d5 100644 --- a/demo-app/gradle/libs.versions.toml +++ b/demo-app/gradle/libs.versions.toml @@ -2,7 +2,7 @@ opentelemetry = "1.45.0" opentelemetry-alpha = "1.45.0-alpha" junit = "5.11.4" -spotless = "6.25.0" +spotless = "7.0.0" kotlin = "2.1.0" navigation-compose = "2.7.7" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ce03982e..f0da9ed8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ mockito = "5.15.2" junit = "5.11.4" byteBuddy = "1.15.11" okhttp = "4.12.0" -spotless = "6.25.0" +spotless = "7.0.0" kotlin = "2.1.0" androidPlugin = "8.7.3" junitKtx = "1.2.1" diff --git a/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityCallbacks.kt b/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityCallbacks.kt index e34df313..077d6199 100644 --- a/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityCallbacks.kt +++ b/instrumentation/activity/src/main/java/io/opentelemetry/android/instrumentation/activity/ActivityCallbacks.kt @@ -9,7 +9,9 @@ import android.app.Activity import android.os.Bundle import io.opentelemetry.android.internal.services.visiblescreen.activities.DefaultingActivityLifecycleCallbacks -class ActivityCallbacks(private val tracers: ActivityTracerCache) : DefaultingActivityLifecycleCallbacks { +class ActivityCallbacks( + private val tracers: ActivityTracerCache, +) : DefaultingActivityLifecycleCallbacks { override fun onActivityPreCreated( activity: Activity, savedInstanceState: Bundle?, @@ -52,7 +54,8 @@ class ActivityCallbacks(private val tracers: ActivityTracerCache) : DefaultingAc } override fun onActivityPostResumed(activity: Activity) { - tracers.addEvent(activity, "activityPostResumed") + tracers + .addEvent(activity, "activityPostResumed") .addPreviousScreenAttribute() .endSpanForActivityResumed() } diff --git a/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationLoader.kt b/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationLoader.kt index ec921b65..c678515c 100644 --- a/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationLoader.kt +++ b/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/AndroidInstrumentationLoader.kt @@ -41,9 +41,7 @@ interface AndroidInstrumentationLoader { * Convenience method for [AndroidInstrumentationLoader.getByType]. */ @JvmStatic - fun getInstrumentation(type: Class): T? { - return get().getByType(type) - } + fun getInstrumentation(type: Class): T? = get().getByType(type) @JvmStatic fun resetForTest() { diff --git a/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/internal/AndroidInstrumentationLoaderImpl.kt b/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/internal/AndroidInstrumentationLoaderImpl.kt index 0228ae50..4cf527a9 100644 --- a/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/internal/AndroidInstrumentationLoaderImpl.kt +++ b/instrumentation/android-instrumentation/src/main/java/io/opentelemetry/android/instrumentation/internal/AndroidInstrumentationLoaderImpl.kt @@ -15,18 +15,16 @@ import java.util.ServiceLoader */ class AndroidInstrumentationLoaderImpl : AndroidInstrumentationLoader { private val instrumentations: MutableMap, AndroidInstrumentation> by lazy { - ServiceLoader.load(AndroidInstrumentation::class.java).associateBy { it.javaClass } + ServiceLoader + .load(AndroidInstrumentation::class.java) + .associateBy { it.javaClass } .toMutableMap() } @Suppress("UNCHECKED_CAST") - override fun getByType(type: Class): T? { - return instrumentations[type] as? T - } + override fun getByType(type: Class): T? = instrumentations[type] as? T - override fun getAll(): Collection { - return instrumentations.values.toList() - } + override fun getAll(): Collection = instrumentations.values.toList() @Throws(IllegalStateException::class) fun registerForTest(instrumentation: AndroidInstrumentation) { diff --git a/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.kt b/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.kt index 728b8bb9..08a859d1 100644 --- a/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.kt +++ b/instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.kt @@ -19,8 +19,9 @@ import java.time.Instant import java.util.function.Supplier @AutoService(InitializationEvents::class) -class SdkInitializationEvents(private val clock: Supplier = Supplier { Instant.now() }) : - InitializationEvents { +class SdkInitializationEvents( + private val clock: Supplier = Supplier { Instant.now() }, +) : InitializationEvents { private val events = mutableListOf() override fun sdkInitializationStarted() { @@ -63,7 +64,8 @@ class SdkInitializationEvents(private val clock: Supplier = Supplier { SdkEventLoggerProvider.create(loggerProvider).get("otel.initialization.events") events.forEach { event: Event -> val eventBuilder = - eventLogger.builder(event.name) + eventLogger + .builder(event.name) .setTimestamp(event.timestamp) .setAttributes(event.attributes) if (event.body != null) { diff --git a/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEventsTest.kt b/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEventsTest.kt index a3671abf..d7899cbe 100644 --- a/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEventsTest.kt +++ b/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEventsTest.kt @@ -39,11 +39,13 @@ class SdkInitializationEventsTest { val exporter = mockk() val processor = mockk() val loggerProvider = - SdkLoggerProvider.builder() + SdkLoggerProvider + .builder() .addLogRecordProcessor(processor) .build() val sdk = - OpenTelemetrySdk.builder() + OpenTelemetrySdk + .builder() .setLoggerProvider(loggerProvider) .build() every { processor.onEmit(any(), any()) }.answers { @@ -80,11 +82,11 @@ class SdkInitializationEventsTest { ) } - fun time(timeMs: Long): EventAssert { - return EventAssert(TimeUnit.MILLISECONDS.toNanos(timeMs)) - } + fun time(timeMs: Long): EventAssert = EventAssert(TimeUnit.MILLISECONDS.toNanos(timeMs)) - class EventAssert(val timeNs: Long) : Consumer { + class EventAssert( + val timeNs: Long, + ) : Consumer { lateinit var name: String var body: Value<*>? = null var attrs: Attributes? = null diff --git a/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentationTest.kt b/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentationTest.kt index 98f0eb6f..a03bda27 100644 --- a/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentationTest.kt +++ b/instrumentation/startup/src/test/java/io/opentelemetry/android/instrumentation/startup/StartupInstrumentationTest.kt @@ -60,11 +60,10 @@ class StartupInstrumentationTest { verify { initializationEvents wasNot Called } } - private fun makeContext(): InstallationContext { - return InstallationContext( + private fun makeContext(): InstallationContext = + InstallationContext( mockk(), otelTesting.openTelemetry, mockk(), ) - } } diff --git a/services/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt b/services/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt index 9b63727e..d05f33ef 100644 --- a/services/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt +++ b/services/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt @@ -12,7 +12,9 @@ import io.opentelemetry.android.internal.services.periodicwork.PeriodicWorkServi import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenService import java.util.Collections -internal class ServiceManagerImpl(services: List) : ServiceManager { +internal class ServiceManagerImpl( + services: List, +) : ServiceManager { private val services: Map, Any> init { @@ -25,8 +27,8 @@ internal class ServiceManagerImpl(services: List) : ServiceManager { companion object { @JvmStatic - fun create(application: Application): ServiceManager { - return ServiceManagerImpl( + fun create(application: Application): ServiceManager = + ServiceManagerImpl( listOf( Preferences.create(application), CacheStorage(application), @@ -36,32 +38,19 @@ internal class ServiceManagerImpl(services: List) : ServiceManager { VisibleScreenService.create(application), ), ) - } } - override fun getPreferences(): Preferences { - return getService(Preferences::class.java) - } + override fun getPreferences(): Preferences = getService(Preferences::class.java) - override fun getCacheStorage(): CacheStorage { - return getService(CacheStorage::class.java) - } + override fun getCacheStorage(): CacheStorage = getService(CacheStorage::class.java) - override fun getPeriodicWorkService(): PeriodicWorkService { - return getService(PeriodicWorkService::class.java) - } + override fun getPeriodicWorkService(): PeriodicWorkService = getService(PeriodicWorkService::class.java) - override fun getCurrentNetworkProvider(): CurrentNetworkProvider { - return getService(CurrentNetworkProvider::class.java) - } + override fun getCurrentNetworkProvider(): CurrentNetworkProvider = getService(CurrentNetworkProvider::class.java) - override fun getAppLifecycleService(): AppLifecycleService { - return getService(AppLifecycleService::class.java) - } + override fun getAppLifecycleService(): AppLifecycleService = getService(AppLifecycleService::class.java) - override fun getVisibleScreenService(): VisibleScreenService { - return getService(VisibleScreenService::class.java) - } + override fun getVisibleScreenService(): VisibleScreenService = getService(VisibleScreenService::class.java) override fun start() { for (service in services.values) { diff --git a/services/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt b/services/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt index a8d44fc0..28cb4cac 100644 --- a/services/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt +++ b/services/src/main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt @@ -18,12 +18,11 @@ class AppLifecycleService internal constructor( ) : Startable { companion object { @JvmStatic - fun create(): AppLifecycleService { - return AppLifecycleService( + fun create(): AppLifecycleService = + AppLifecycleService( ApplicationStateWatcher(), ProcessLifecycleOwner.get().lifecycle, ) - } } fun registerListener(listener: ApplicationStateListener) { diff --git a/services/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt b/services/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt index 5ddd3c68..62c60afe 100644 --- a/services/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt +++ b/services/src/main/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnable.kt @@ -13,8 +13,9 @@ import io.opentelemetry.android.common.internal.tools.time.SystemTime *

This class is internal and not for public use. Its APIs are unstable and can change at any * time. */ -abstract class PeriodicRunnable(periodicWorkServiceProvider: () -> PeriodicWorkService) : - Runnable { +abstract class PeriodicRunnable( + periodicWorkServiceProvider: () -> PeriodicWorkService, +) : Runnable { private val periodicWorkService by lazy { periodicWorkServiceProvider() } private var lastTimeItRan: Long? = null @@ -28,11 +29,10 @@ abstract class PeriodicRunnable(periodicWorkServiceProvider: () -> PeriodicWorkS } } - private fun isReadyToRun(): Boolean { - return lastTimeItRan?.let { + private fun isReadyToRun(): Boolean = + lastTimeItRan?.let { getCurrentTimeMillis() >= (it + minimumDelayUntilNextRunInMillis()) } ?: true - } private fun enqueueForNextLoop() { periodicWorkService.enqueue(this) diff --git a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt index 6449fd9d..11c52181 100644 --- a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt +++ b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/VisibleScreenService.kt @@ -30,7 +30,9 @@ import java.util.concurrent.atomic.AtomicReference * We have to treat DialogFragments slightly differently since they don't replace the launching * screen, and the launching screen never leaves visibility. */ -class VisibleScreenService internal constructor(private val application: Application) : Startable { +class VisibleScreenService internal constructor( + private val application: Application, +) : Startable { private val lastResumedActivity = AtomicReference() private val previouslyLastResumedActivity = AtomicReference() private val lastResumedFragment = AtomicReference() @@ -40,9 +42,7 @@ class VisibleScreenService internal constructor(private val application: Applica companion object { @JvmStatic - fun create(application: Application): VisibleScreenService { - return VisibleScreenService(application) - } + fun create(application: Application): VisibleScreenService = VisibleScreenService(application) } override fun start() { @@ -50,13 +50,12 @@ class VisibleScreenService internal constructor(private val application: Applica application.registerActivityLifecycleCallbacks(fragmentLifecycleTrackerRegisterer) } - private fun buildActivitiesTracker(): Application.ActivityLifecycleCallbacks { - return if (Build.VERSION.SDK_INT < 29) { + private fun buildActivitiesTracker(): Application.ActivityLifecycleCallbacks = + if (Build.VERSION.SDK_INT < 29) { Pre29VisibleScreenLifecycleBinding(this) } else { VisibleScreenLifecycleBinding(this) } - } private fun buildFragmentsTrackerRegisterer(): Application.ActivityLifecycleCallbacks { val fragmentLifecycle = VisibleFragmentTracker(this) diff --git a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.kt b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.kt index 15bb7939..9cfb374b 100644 --- a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.kt +++ b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/Pre29VisibleScreenLifecycleBinding.kt @@ -13,7 +13,9 @@ import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenSer * activity has been resumed and when an activity has been paused. It's just a glue class designed * for API level before 29. */ -class Pre29VisibleScreenLifecycleBinding(private val visibleScreenService: VisibleScreenService) : DefaultingActivityLifecycleCallbacks { +class Pre29VisibleScreenLifecycleBinding( + private val visibleScreenService: VisibleScreenService, +) : DefaultingActivityLifecycleCallbacks { override fun onActivityResumed(activity: Activity) { visibleScreenService.activityResumed(activity) } diff --git a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.kt b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.kt index 4081e36f..f1dfe6e3 100644 --- a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.kt +++ b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/activities/VisibleScreenLifecycleBinding.kt @@ -12,7 +12,9 @@ import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenSer * An ActivityLifecycleCallbacks that is responsible for telling the VisibleScreenTracker when an * activity has been resumed and when an activity has been paused. It's just a glue class. */ -class VisibleScreenLifecycleBinding(private val visibleScreenService: VisibleScreenService) : DefaultingActivityLifecycleCallbacks { +class VisibleScreenLifecycleBinding( + private val visibleScreenService: VisibleScreenService, +) : DefaultingActivityLifecycleCallbacks { override fun onActivityPostResumed(activity: Activity) { visibleScreenService.activityResumed(activity) } diff --git a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt index 21dc0140..a9a2fd4e 100644 --- a/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt +++ b/services/src/main/java/io/opentelemetry/android/internal/services/visiblescreen/fragments/VisibleFragmentTracker.kt @@ -9,8 +9,9 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenService -class VisibleFragmentTracker(private val visibleScreenService: VisibleScreenService) : - FragmentManager.FragmentLifecycleCallbacks() { +class VisibleFragmentTracker( + private val visibleScreenService: VisibleScreenService, +) : FragmentManager.FragmentLifecycleCallbacks() { override fun onFragmentResumed( fm: FragmentManager, f: Fragment, diff --git a/services/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt b/services/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt index 9be39c64..f1cfb5cc 100644 --- a/services/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt +++ b/services/src/test/java/io/opentelemetry/android/internal/services/periodicwork/PeriodicRunnableTest.kt @@ -108,21 +108,15 @@ class PeriodicRunnableTest { } } - override fun shouldStopRunning(): Boolean { - return stopRunning - } + override fun shouldStopRunning(): Boolean = stopRunning - override fun minimumDelayUntilNextRunInMillis(): Long { - return minimumDelayInMillis - } + override fun minimumDelayUntilNextRunInMillis(): Long = minimumDelayInMillis } private class TestSystemTime : SystemTime { var currentTime = 1000L - override fun getCurrentTimeMillis(): Long { - return currentTime - } + override fun getCurrentTimeMillis(): Long = currentTime fun advanceTimeByMillis(millis: Long) { currentTime += millis diff --git a/test-common/src/main/kotlin/io/opentelemetry/android/test/common/OpenTelemetryRumRule.kt b/test-common/src/main/kotlin/io/opentelemetry/android/test/common/OpenTelemetryRumRule.kt index ec648e6c..8e2bc504 100644 --- a/test-common/src/main/kotlin/io/opentelemetry/android/test/common/OpenTelemetryRumRule.kt +++ b/test-common/src/main/kotlin/io/opentelemetry/android/test/common/OpenTelemetryRumRule.kt @@ -28,29 +28,29 @@ class OpenTelemetryRumRule : TestRule { override fun apply( base: Statement, description: Description, - ): Statement { - return object : Statement() { + ): Statement = + object : Statement() { override fun evaluate() { setUpOpenTelemetry() base.evaluate() } } - } - fun getSpan(): Span { - return openTelemetryRum.openTelemetry.getTracer("TestTracer").spanBuilder("A Span") + fun getSpan(): Span = + openTelemetryRum.openTelemetry + .getTracer("TestTracer") + .spanBuilder("A Span") .startSpan() - } private fun setUpOpenTelemetry() { inMemorySpanExporter = InMemorySpanExporter.create() InstrumentationRegistry.getInstrumentation().runOnMainSync { openTelemetryRum = - OpenTelemetryRum.builder(ApplicationProvider.getApplicationContext()) + OpenTelemetryRum + .builder(ApplicationProvider.getApplicationContext()) .addTracerProviderCustomizer { tracer, _ -> tracer.addSpanProcessor(SimpleSpanProcessor.create(inMemorySpanExporter)) - } - .build() + }.build() } } }