Skip to content

Commit

Permalink
fix(deps): update spotless to v7 (major) (#733)
Browse files Browse the repository at this point in the history
* fix(deps): update spotless to v7

* run spotlessApply with the new version

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jason Plumb <[email protected]>
  • Loading branch information
renovate[bot] and breedx-splk authored Jan 7, 2025
1 parent f666603 commit eef2984
Show file tree
Hide file tree
Showing 33 changed files with 140 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<StackTraceElement>, Void>): OtelRumConfig {
AndroidInstrumentationLoader.getInstrumentation(AnrInstrumentation::class.java)
AndroidInstrumentationLoader
.getInstrumentation(AnrInstrumentation::class.java)
?.addAttributesExtractor(extractor)
return this
}

fun OtelRumConfig.addCrashAttributesExtractor(extractor: AttributesExtractor<CrashDetails, Void>): OtelRumConfig {
AndroidInstrumentationLoader.getInstrumentation(CrashReporterInstrumentation::class.java)
AndroidInstrumentationLoader
.getInstrumentation(CrashReporterInstrumentation::class.java)
?.addAttributesExtractor(extractor)
return this
}

fun OtelRumConfig.addNetworkChangeAttributesExtractor(extractor: AttributesExtractor<CurrentNetwork, Void>): 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spotless {
"*.sh",
"src/**/*.properties"
)
indentWithSpaces()
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ internal class AgentInitTest {
fun startOpenTelemetryRumInAndroid() {
val application = getApplicationContext<Application>()
val otelRum =
OpenTelemetryRum.builder(
application,
OtelRumConfig(),
).build()
OpenTelemetryRum
.builder(
application,
OtelRumConfig(),
).build()
assertNotNull(otelRum)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attributes>) :
LogRecordProcessor {
internal class GlobalAttributesLogRecordAppender(
private val attributesSupplier: Supplier<Attributes>,
) : LogRecordProcessor {
override fun onEmit(
context: Context,
logRecord: ReadWriteLogRecord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 7 additions & 10 deletions core/src/main/java/io/opentelemetry/android/session/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,8 +31,6 @@ interface Session {
return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
override fun hashCode(): Int = id.hashCode()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionObserver>())
Expand Down Expand Up @@ -69,11 +70,10 @@ internal class SessionManager(
fun create(
timeoutHandler: SessionIdTimeoutHandler,
sessionLifetimeNanos: Long,
): SessionManager {
return SessionManager(
): SessionManager =
SessionManager(
timeoutHandler = timeoutHandler,
sessionLifetimeNanos = sessionLifetimeNanos,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class DefaultExportSchedulerTest {
@Test
fun `Try to export all available signals when running`() {
val signalFromDiskExporter = mockk<SignalFromDiskExporter>()
every { signalFromDiskExporter.exportBatchOfEach() }.returns(true).andThen(true)
every { signalFromDiskExporter.exportBatchOfEach() }
.returns(true)
.andThen(true)
.andThen(false)
SignalFromDiskExporter.set(signalFromDiskExporter)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -179,5 +179,4 @@ class SignalFromDiskExporterTest {
exportTimeoutInMillis,
)
}
}
}
2 changes: 1 addition & 1 deletion demo-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ interface AndroidInstrumentationLoader {
* Convenience method for [AndroidInstrumentationLoader.getByType].
*/
@JvmStatic
fun <T : AndroidInstrumentation> getInstrumentation(type: Class<out T>): T? {
return get().getByType(type)
}
fun <T : AndroidInstrumentation> getInstrumentation(type: Class<out T>): T? = get().getByType(type)

@JvmStatic
fun resetForTest() {
Expand Down
Loading

0 comments on commit eef2984

Please sign in to comment.