From 3ecf4cf8d78424882c453fd23e067fbdcdef51d6 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Fri, 29 Nov 2024 17:07:29 +0000 Subject: [PATCH] propagate auto termination enum to span service --- .../api/embrace-android-api.api | 1 + .../android/embracesdk/spans/EmbraceSpan.kt | 5 + .../config/detekt/baseline.xml | 1 + .../arch/datasource/SpanDataSource.kt | 10 +- .../internal/opentelemetry/TracerExt.kt | 3 + .../internal/spans/CurrentSessionSpanImpl.kt | 2 +- .../internal/spans/EmbraceSpanBuilder.kt | 2 + .../internal/spans/EmbraceSpanFactory.kt | 2 + .../internal/spans/EmbraceSpanFactoryImpl.kt | 3 + .../internal/spans/EmbraceSpanImpl.kt | 3 + .../internal/spans/EmbraceSpanService.kt | 15 +- .../internal/spans/EmbraceTracer.kt | 4 + .../embracesdk/internal/spans/SpanService.kt | 6 + .../internal/spans/SpanServiceImpl.kt | 19 +- .../spans/UninitializedSdkSpanService.kt | 10 +- .../opentelemetry/EmbSpanBuilderTest.kt | 3 + .../spans/CurrentSessionSpanImplTests.kt | 186 +++++++++++++++--- .../spans/EmbraceSpanFactoryImplTest.kt | 8 +- .../internal/spans/EmbraceSpanImplTest.kt | 4 +- .../internal/spans/EmbraceSpanServiceTest.kt | 15 +- .../internal/spans/EmbraceTracerTest.kt | 2 +- .../internal/spans/SpanServiceImplTest.kt | 61 +++--- .../capture/crumbs/RnActionDataSource.kt | 2 +- embrace-test-fakes/config/detekt/baseline.xml | 1 - .../fakes/FakePersistableEmbraceSpan.kt | 2 + .../embracesdk/fakes/FakeSpanService.kt | 12 +- 26 files changed, 303 insertions(+), 79 deletions(-) diff --git a/embrace-android-api/api/embrace-android-api.api b/embrace-android-api/api/embrace-android-api.api index e1cd945dd7..939f77ef84 100644 --- a/embrace-android-api/api/embrace-android-api.api +++ b/embrace-android-api/api/embrace-android-api.api @@ -231,6 +231,7 @@ public abstract interface class io/embrace/android/embracesdk/spans/EmbraceSpan public abstract fun addEvent (Ljava/lang/String;)Z public abstract fun addEvent (Ljava/lang/String;Ljava/lang/Long;)Z public abstract fun addEvent (Ljava/lang/String;Ljava/lang/Long;Ljava/util/Map;)Z + public abstract fun getAutoTerminationMode ()Lio/embrace/android/embracesdk/spans/AutoTerminationMode; public abstract fun getParent ()Lio/embrace/android/embracesdk/spans/EmbraceSpan; public abstract fun getSpanContext ()Lio/opentelemetry/api/trace/SpanContext; public abstract fun getSpanId ()Ljava/lang/String; diff --git a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/spans/EmbraceSpan.kt b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/spans/EmbraceSpan.kt index 0173c1b2ca..9de2a7e444 100644 --- a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/spans/EmbraceSpan.kt +++ b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/spans/EmbraceSpan.kt @@ -34,6 +34,11 @@ public interface EmbraceSpan { */ public val parent: EmbraceSpan? + /** + * The auto termination mode for this span + */ + public val autoTerminationMode: AutoTerminationMode + /** * Start recording of the Span. Returns true if this call triggered the start of the recording. Returns false if the Span has already * been started or has been stopped. diff --git a/embrace-android-core/config/detekt/baseline.xml b/embrace-android-core/config/detekt/baseline.xml index e0528e8e34..e0c4389ad6 100644 --- a/embrace-android-core/config/detekt/baseline.xml +++ b/embrace-android-core/config/detekt/baseline.xml @@ -4,5 +4,6 @@ LongParameterList:DeliveryModuleSupplier.kt$( configModule: ConfigModule, initModule: InitModule, otelModule: OpenTelemetryModule, workerThreadModule: WorkerThreadModule, coreModule: CoreModule, storageModule: StorageModule, essentialServiceModule: EssentialServiceModule, androidServicesModule: AndroidServicesModule, payloadStorageServiceProvider: Provider<PayloadStorageService>?, cacheStorageServiceProvider: Provider<PayloadStorageService>?, requestExecutionServiceProvider: Provider<RequestExecutionService>?, deliveryServiceProvider: Provider<DeliveryService>?, deliveryTracer: DeliveryTracer?, ) LongParameterList:NativeCoreModuleSupplier.kt$( initModule: InitModule, coreModule: CoreModule, payloadSourceModule: PayloadSourceModule, workerThreadModule: WorkerThreadModule, configModule: ConfigModule, storageModule: StorageModule, essentialServiceModule: EssentialServiceModule, otelModule: OpenTelemetryModule, delegateProvider: Provider<JniDelegate?>, sharedObjectLoaderProvider: Provider<SharedObjectLoader?>, symbolServiceProvider: Provider<SymbolService?>, ) + LongParameterList:SpanService.kt$SpanService$( name: String, startTimeMs: Long, endTimeMs: Long, autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parent: EmbraceSpan? = null, type: TelemetryType = EmbType.Performance.Default, internal: Boolean = true, private: Boolean = false, attributes: Map<String, String> = emptyMap(), events: List<EmbraceSpanEvent> = emptyList(), errorCode: ErrorCode? = null, ) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/datasource/SpanDataSource.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/datasource/SpanDataSource.kt index 41c550d57c..1bcd80298a 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/datasource/SpanDataSource.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/datasource/SpanDataSource.kt @@ -3,6 +3,7 @@ package io.embrace.android.embracesdk.internal.arch.datasource import io.embrace.android.embracesdk.internal.arch.schema.SchemaType import io.embrace.android.embracesdk.internal.spans.PersistableEmbraceSpan import io.embrace.android.embracesdk.internal.spans.SpanService +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan /** @@ -34,11 +35,16 @@ interface SpanDataSource : DataSource { ): Boolean } -fun SpanService.startSpanCapture(schemaType: SchemaType, startTimeMs: Long): PersistableEmbraceSpan? { +fun SpanService.startSpanCapture( + schemaType: SchemaType, + startTimeMs: Long, + autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, +): PersistableEmbraceSpan? { return startSpan( name = schemaType.fixedObjectName, startTimeMs = startTimeMs, - type = schemaType.telemetryType + type = schemaType.telemetryType, + autoTerminationMode = autoTerminationMode, )?.apply { schemaType.attributes().forEach { addAttribute(it.key, it.value) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/TracerExt.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/TracerExt.kt index 3544429e21..6b6d367e3f 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/TracerExt.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/TracerExt.kt @@ -2,6 +2,7 @@ package io.embrace.android.embracesdk.internal.opentelemetry import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType import io.embrace.android.embracesdk.internal.spans.EmbraceSpanBuilder +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.opentelemetry.api.trace.SpanBuilder import io.opentelemetry.api.trace.Tracer @@ -14,6 +15,7 @@ internal fun Tracer.embraceSpanBuilder( type: TelemetryType, internal: Boolean, private: Boolean, + autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parent: EmbraceSpan? = null, ): EmbraceSpanBuilder = EmbraceSpanBuilder( tracer = this, @@ -21,5 +23,6 @@ internal fun Tracer.embraceSpanBuilder( telemetryType = type, internal = internal, private = private, + autoTerminationMode = autoTerminationMode, parentSpan = parent, ) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImpl.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImpl.kt index b176ac9f6c..56bbb99515 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImpl.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImpl.kt @@ -172,7 +172,7 @@ internal class CurrentSessionSpanImpl( name = "session", type = EmbType.Ux.Session, internal = true, - private = false + private = false, ).apply { start(startTimeMs = startTimeMs) setSystemAttribute(SessionIncubatingAttributes.SESSION_ID, Uuid.getEmbUuid()) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanBuilder.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanBuilder.kt index 86e0a02494..16ae9aca2c 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanBuilder.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanBuilder.kt @@ -3,6 +3,7 @@ package io.embrace.android.embracesdk.internal.spans import io.embrace.android.embracesdk.internal.arch.schema.FixedAttribute import io.embrace.android.embracesdk.internal.arch.schema.PrivateSpan import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanBuilder @@ -20,6 +21,7 @@ class EmbraceSpanBuilder( telemetryType: TelemetryType, val internal: Boolean, private: Boolean, + val autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parentSpan: EmbraceSpan?, ) { lateinit var parentContext: Context diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactory.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactory.kt index 4b4801f708..4696b2c567 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactory.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactory.kt @@ -2,6 +2,7 @@ package io.embrace.android.embracesdk.internal.spans import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType import io.embrace.android.embracesdk.internal.config.behavior.SensitiveKeysBehavior +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan /** @@ -14,6 +15,7 @@ internal interface EmbraceSpanFactory { type: TelemetryType, internal: Boolean, private: Boolean, + autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parent: EmbraceSpan? = null, ): PersistableEmbraceSpan diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImpl.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImpl.kt index 85107ce1b4..08e1b0a0be 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImpl.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImpl.kt @@ -3,6 +3,7 @@ package io.embrace.android.embracesdk.internal.spans import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType import io.embrace.android.embracesdk.internal.config.behavior.SensitiveKeysBehavior import io.embrace.android.embracesdk.internal.opentelemetry.embraceSpanBuilder +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.opentelemetry.api.trace.Tracer import io.opentelemetry.sdk.common.Clock @@ -19,6 +20,7 @@ internal class EmbraceSpanFactoryImpl( type: TelemetryType, internal: Boolean, private: Boolean, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, ): PersistableEmbraceSpan = create( embraceSpanBuilder = tracer.embraceSpanBuilder( @@ -27,6 +29,7 @@ internal class EmbraceSpanFactoryImpl( internal = internal, private = private, parent = parent, + autoTerminationMode = autoTerminationMode ) ) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImpl.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImpl.kt index e0b844aa64..ae73116f47 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImpl.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImpl.kt @@ -19,6 +19,7 @@ import io.embrace.android.embracesdk.internal.spans.EmbraceSpanLimits.MAX_TOTAL_ import io.embrace.android.embracesdk.internal.spans.EmbraceSpanLimits.isAttributeValid import io.embrace.android.embracesdk.internal.spans.EmbraceSpanLimits.isNameValid import io.embrace.android.embracesdk.internal.utils.truncatedStacktraceText +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode @@ -77,6 +78,8 @@ internal class EmbraceSpanImpl( override val isRecording: Boolean get() = startedSpan.get()?.isRecording == true + override val autoTerminationMode: AutoTerminationMode = spanBuilder.autoTerminationMode + override fun start(startTimeMs: Long?): Boolean { if (spanStarted()) { return false diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanService.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanService.kt index 635d985dc5..75dbc4a464 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanService.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanService.kt @@ -2,6 +2,7 @@ package io.embrace.android.embracesdk.internal.spans import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType import io.embrace.android.embracesdk.internal.utils.Provider +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode @@ -44,12 +45,20 @@ internal class EmbraceSpanService( override fun createSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, private: Boolean, ): PersistableEmbraceSpan? = - currentDelegate.createSpan(name = name, parent = parent, type = type, internal = internal, private = private) + currentDelegate.createSpan( + name = name, + autoTerminationMode = autoTerminationMode, + parent = parent, + type = type, + internal = internal, + private = private + ) override fun createSpan(embraceSpanBuilder: EmbraceSpanBuilder): PersistableEmbraceSpan? = currentDelegate.createSpan( @@ -58,6 +67,7 @@ internal class EmbraceSpanService( override fun recordSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -67,6 +77,7 @@ internal class EmbraceSpanService( code: () -> T, ): T = currentDelegate.recordSpan( name = name, + autoTerminationMode = autoTerminationMode, parent = parent, type = type, internal = internal, @@ -80,6 +91,7 @@ internal class EmbraceSpanService( name: String, startTimeMs: Long, endTimeMs: Long, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -91,6 +103,7 @@ internal class EmbraceSpanService( name = name, startTimeMs = startTimeMs, endTimeMs = endTimeMs, + autoTerminationMode = autoTerminationMode, parent = parent, type = type, internal = internal, diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt index 75a324b234..ba9c2c44c0 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt @@ -23,6 +23,7 @@ class EmbraceTracer( parent = parent, internal = false, private = false, + autoTerminationMode = autoTerminationMode ) override fun startSpan( @@ -37,6 +38,7 @@ class EmbraceTracer( startTimeMs = startTimeMs?.normalizeTimestampAsMillis(), internal = false, private = false, + autoTerminationMode = autoTerminationMode ) override fun recordSpan( @@ -53,6 +55,7 @@ class EmbraceTracer( private = false, attributes = attributes ?: emptyMap(), events = events ?: emptyList(), + autoTerminationMode = autoTerminationMode, code = code ) @@ -74,6 +77,7 @@ class EmbraceTracer( private = false, attributes = attributes ?: emptyMap(), events = events ?: emptyList(), + autoTerminationMode = autoTerminationMode, errorCode = errorCode ) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanService.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanService.kt index af82680085..c61ade50e2 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanService.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanService.kt @@ -3,6 +3,7 @@ package io.embrace.android.embracesdk.internal.spans import io.embrace.android.embracesdk.internal.Initializable import io.embrace.android.embracesdk.internal.arch.schema.EmbType import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode @@ -18,6 +19,7 @@ interface SpanService : Initializable { */ fun createSpan( name: String, + autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parent: EmbraceSpan? = null, type: TelemetryType = EmbType.Performance.Default, internal: Boolean = true, @@ -35,6 +37,7 @@ interface SpanService : Initializable { */ fun startSpan( name: String, + autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parent: EmbraceSpan? = null, startTimeMs: Long? = null, type: TelemetryType = EmbType.Performance.Default, @@ -43,6 +46,7 @@ interface SpanService : Initializable { ): PersistableEmbraceSpan? { createSpan( name = name, + autoTerminationMode = autoTerminationMode, parent = parent, type = type, internal = internal, @@ -62,6 +66,7 @@ interface SpanService : Initializable { */ fun recordSpan( name: String, + autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parent: EmbraceSpan? = null, type: TelemetryType = EmbType.Performance.Default, internal: Boolean = true, @@ -79,6 +84,7 @@ interface SpanService : Initializable { name: String, startTimeMs: Long, endTimeMs: Long, + autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, parent: EmbraceSpan? = null, type: TelemetryType = EmbType.Performance.Default, internal: Boolean = true, diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanServiceImpl.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanServiceImpl.kt index c6d636b364..57f4540c05 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanServiceImpl.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanServiceImpl.kt @@ -3,6 +3,7 @@ package io.embrace.android.embracesdk.internal.spans import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType import io.embrace.android.embracesdk.internal.clock.nanosToMillis import io.embrace.android.embracesdk.internal.spans.EmbraceSpanLimits.isNameValid +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode @@ -29,6 +30,7 @@ internal class SpanServiceImpl( override fun createSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -40,7 +42,8 @@ internal class SpanServiceImpl( type = type, internal = internal, private = private, - parent = parent + parent = parent, + autoTerminationMode = autoTerminationMode, ) } else { null @@ -60,6 +63,7 @@ internal class SpanServiceImpl( override fun recordSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -69,7 +73,14 @@ internal class SpanServiceImpl( code: () -> T, ): T { val returnValue: T - val span = createSpan(name = name, parent = parent, type = type, internal = internal, private = private) + val span = createSpan( + name = name, + autoTerminationMode = autoTerminationMode, + parent = parent, + type = type, + internal = internal, + private = private + ) try { val started = span?.start() ?: false if (started) { @@ -98,6 +109,7 @@ internal class SpanServiceImpl( name: String, startTimeMs: Long, endTimeMs: Long, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -116,7 +128,8 @@ internal class SpanServiceImpl( type = type, internal = internal, private = private, - parent = parent + parent = parent, + autoTerminationMode = autoTerminationMode, ) if (newSpan.start(startTimeMs)) { attributes.forEach { diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/UninitializedSdkSpanService.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/UninitializedSdkSpanService.kt index 060edf9eb7..86dbc1573a 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/UninitializedSdkSpanService.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/UninitializedSdkSpanService.kt @@ -1,6 +1,7 @@ package io.embrace.android.embracesdk.internal.spans import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode @@ -22,6 +23,7 @@ internal class UninitializedSdkSpanService : SpanService { override fun createSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -32,6 +34,7 @@ internal class UninitializedSdkSpanService : SpanService { override fun recordSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -45,6 +48,7 @@ internal class UninitializedSdkSpanService : SpanService { name: String, startTimeMs: Long, endTimeMs: Long, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -57,6 +61,7 @@ internal class UninitializedSdkSpanService : SpanService { name = name, startTimeMs = startTimeMs, endTimeMs = endTimeMs, + autoTerminationMode = autoTerminationMode, parent = parent, type = type, internal = internal, @@ -73,13 +78,14 @@ internal class UninitializedSdkSpanService : SpanService { name = name, startTimeMs = startTimeMs, endTimeMs = endTimeMs, + autoTerminationMode = autoTerminationMode, parent = parent, type = type, internal = internal, private = private, attributes = attributes, events = events, - errorCode = errorCode + errorCode = errorCode, ) ) } @@ -103,6 +109,7 @@ internal class UninitializedSdkSpanService : SpanService { name = it.name, startTimeMs = it.startTimeMs, endTimeMs = it.endTimeMs, + autoTerminationMode = it.autoTerminationMode, parent = it.parent, type = it.type, internal = it.internal, @@ -127,6 +134,7 @@ internal class UninitializedSdkSpanService : SpanService { val name: String, val startTimeMs: Long, val endTimeMs: Long, + val autoTerminationMode: AutoTerminationMode, val parent: EmbraceSpan?, val type: TelemetryType, val internal: Boolean, diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/opentelemetry/EmbSpanBuilderTest.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/opentelemetry/EmbSpanBuilderTest.kt index 05767f6d94..1fdec546ae 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/opentelemetry/EmbSpanBuilderTest.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/opentelemetry/EmbSpanBuilderTest.kt @@ -10,6 +10,7 @@ import io.embrace.android.embracesdk.fixtures.fakeContextKey import io.embrace.android.embracesdk.internal.arch.schema.EmbType import io.embrace.android.embracesdk.internal.spans.EmbraceSpanBuilder import io.embrace.android.embracesdk.internal.spans.getEmbraceSpan +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.trace.Span @@ -60,6 +61,7 @@ internal class EmbSpanBuilderTest { internal = true, private = true, parentSpan = spanParent, + autoTerminationMode = AutoTerminationMode.ON_BACKGROUND, ) embSpanBuilder = EmbSpanBuilder( embraceSpanBuilder = newEmbraceSpanBuilder, @@ -73,6 +75,7 @@ internal class EmbSpanBuilderTest { assertEquals(spanParent, parent) assertEquals("emb-custom", name) assertEquals(EmbType.Performance.Default, type) + assertEquals(AutoTerminationMode.ON_BACKGROUND, autoTerminationMode) } } diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImplTests.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImplTests.kt index 05d1984c5d..35b765d00f 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImplTests.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpanImplTests.kt @@ -20,6 +20,7 @@ import io.embrace.android.embracesdk.internal.payload.toNewPayload import io.embrace.android.embracesdk.internal.spans.EmbraceSpanLimits.MAX_TOTAL_ATTRIBUTE_COUNT import io.embrace.android.embracesdk.internal.spans.EmbraceSpanLimits.MAX_TOTAL_EVENT_COUNT import io.embrace.android.embracesdk.internal.telemetry.TelemetryService +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.ErrorCode import io.opentelemetry.api.trace.SpanId @@ -80,17 +81,37 @@ internal class CurrentSessionSpanImplTests { @Test fun `check trace limits with maximum not started traces`() { repeat(SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION) { - assertNotNull(spanService.createSpan(name = "spanzzz$it", internal = false)) + assertNotNull( + spanService.createSpan( + name = "spanzzz$it", + internal = false + ) + ) } - assertNull(spanService.createSpan(name = "failed-span", internal = false)) + assertNull( + spanService.createSpan( + name = "failed-span", + internal = false + ) + ) } @Test fun `check trace limits with maximum internal not started traces`() { repeat(SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION) { - assertNotNull(spanService.createSpan(name = "spanzzz$it", internal = false)) + assertNotNull( + spanService.createSpan( + name = "spanzzz$it", + internal = false + ) + ) } - assertNull(spanService.createSpan(name = "failed-span", internal = false)) + assertNull( + spanService.createSpan( + name = "failed-span", + internal = false + ) + ) repeat(SpanServiceImpl.MAX_INTERNAL_SPANS_PER_SESSION) { assertNotNull(spanService.createSpan(name = "internal$it")) @@ -140,9 +161,20 @@ internal class CurrentSessionSpanImplTests { @Test fun `check trace limits with maximum traces recorded around a lambda`() { repeat(SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION) { - assertEquals("derp", spanService.recordSpan(name = "record$it", internal = false) { "derp" }) + assertEquals( + "derp", + spanService.recordSpan( + name = "record$it", + internal = false, + ) { "derp" } + ) } - assertNull(spanService.createSpan(name = "failed-span", internal = false)) + assertNull( + spanService.createSpan( + name = "failed-span", + internal = false, + ) + ) } @Test @@ -153,70 +185,160 @@ internal class CurrentSessionSpanImplTests { name = "complete$it", startTimeMs = 100L, endTimeMs = 200L, - internal = false + internal = false, ) ) } - assertNull(spanService.createSpan(name = "failed-span", internal = false)) + assertNull( + spanService.createSpan( + name = "failed-span", + internal = false, + ) + ) } @Test fun `check internal traces and child spans don't count towards limit`() { - val parent = checkNotNull(spanService.createSpan(name = "test-span", internal = false)) + val parent = checkNotNull( + spanService.createSpan( + name = "test-span", + internal = false, + ) + ) assertTrue(parent.start()) repeat(SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION - 1) { - assertNotNull("Adding span $it failed", spanService.createSpan(name = "spanzzz$it", internal = false)) + assertNotNull( + "Adding span $it failed", + spanService.createSpan( + name = "spanzzz$it", + internal = false, + ) + ) } - assertNull(spanService.createSpan(name = "failed-span", internal = false)) - assertNull(spanService.createSpan(name = "child-span", parent = parent, internal = false)) - assertNotNull(spanService.createSpan(name = "internal-again", internal = true)) - assertNotNull(spanService.createSpan(name = "internal-child-span", parent = parent, internal = true)) + assertNull( + spanService.createSpan( + name = "failed-span", + internal = false, + ) + ) + assertNull( + spanService.createSpan( + name = "child-span", + parent = parent, + internal = false, + ) + ) + assertNotNull( + spanService.createSpan( + name = "internal-again", + internal = true, + ) + ) + assertNotNull( + spanService.createSpan( + name = "internal-child-span", + parent = parent, + internal = true, + ) + ) } @Test fun `check total limit can be reached with descendant spans`() { var parentSpan: EmbraceSpan? = null repeat(SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION) { - val span = spanService.createSpan(name = "spanzzz$it", parent = parentSpan, internal = false) + val span = spanService.createSpan( + name = "spanzzz$it", + parent = parentSpan, + internal = false, + ) assertTrue(checkNotNull(span).start()) parentSpan = span } - assertNull(spanService.createSpan(name = "failed-span", parent = parentSpan, internal = false)) + assertNull( + spanService.createSpan( + name = "failed-span", + parent = parentSpan, + internal = false, + ) + ) assertFalse( spanService.recordCompletedSpan( name = "failed-span", startTimeMs = 100L, endTimeMs = 200L, parent = parentSpan, - internal = false + internal = false, ) ) spanSink.flushSpans() - assertEquals(2, spanService.recordSpan(name = "failed-span", parent = parentSpan, internal = false) { 2 }) + assertEquals( + 2, + spanService.recordSpan( + name = "failed-span", + parent = parentSpan, + internal = false, + ) { 2 } + ) assertEquals(0, spanSink.completedSpans().size) } @Test fun `check internal child spans don't count towards limit`() { - val parentSpan = checkNotNull(spanService.createSpan(name = "parent-span", internal = true)) + val parentSpan = checkNotNull( + spanService.createSpan( + name = "parent-span", + internal = true, + ) + ) assertTrue(parentSpan.start()) - assertNotNull(spanService.createSpan(name = "failed-span", parent = parentSpan, internal = true)) - assertNotNull(spanService.recordSpan(name = "failed-span", parent = parentSpan, internal = true) { }) + assertNotNull( + spanService.createSpan( + name = "failed-span", + parent = parentSpan, + internal = true, + ) + ) + assertNotNull( + spanService.recordSpan( + name = "failed-span", + parent = parentSpan, + internal = true, + ) { } + ) assertTrue( spanService.recordCompletedSpan( name = "failed-span", startTimeMs = 100L, endTimeMs = 200L, parent = parentSpan, - internal = true + internal = true, ) ) repeat(SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION) { - assertNotNull(spanService.createSpan(name = "spanzzz$it", parent = parentSpan, internal = false)) + assertNotNull( + spanService.createSpan( + name = "spanzzz$it", + parent = parentSpan, + internal = false, + ) + ) } - assertNull(spanService.createSpan(name = "failed-span", parent = parentSpan, internal = false)) - assertNotNull(spanService.createSpan(name = "internal-span", parent = parentSpan, internal = true)) + assertNull( + spanService.createSpan( + name = "failed-span", + parent = parentSpan, + internal = false, + ) + ) + assertNotNull( + spanService.createSpan( + name = "internal-span", + parent = parentSpan, + internal = true, + ) + ) } @Test @@ -326,10 +448,12 @@ internal class CurrentSessionSpanImplTests { @Test fun `validate tracked spans update when session is ended`() { - val embraceSpan = checkNotNull(spanService.createSpan(name = "test-span")) + val embraceSpan = + checkNotNull(spanService.createSpan(name = "test-span")) assertTrue(embraceSpan.start()) val embraceSpanId = checkNotNull(embraceSpan.spanId) - val parentSpan = checkNotNull(spanService.createSpan(name = "parent-span")) + val parentSpan = + checkNotNull(spanService.createSpan(name = "parent-span")) assertTrue(parentSpan.start()) val parentSpanId = checkNotNull(parentSpan.spanId) val parentSpanFromService = checkNotNull(spanRepository.getSpan(parentSpanId)) @@ -340,7 +464,12 @@ internal class CurrentSessionSpanImplTests { assertNull(spanRepository.getSpan(parentSpanId)) // existing reference to completed span can still be used - checkNotNull(spanService.createSpan(name = "child-span", parent = parentSpan)) + checkNotNull( + spanService.createSpan( + name = "child-span", + parent = parentSpan, + ) + ) // active span from before flush is still available and working val activeSpanFromBeforeFlush = checkNotNull(spanRepository.getSpan(embraceSpanId)) @@ -432,6 +561,7 @@ internal class CurrentSessionSpanImplTests { type: TelemetryType, internal: Boolean, private: Boolean, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, ): PersistableEmbraceSpan = stoppedSpan diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImplTest.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImplTest.kt index fab712cbb0..d722290ca3 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImplTest.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanFactoryImplTest.kt @@ -53,7 +53,7 @@ internal class EmbraceSpanFactoryImplTest { name = "test", type = EmbType.Performance.Default, internal = false, - private = false + private = false, ) assertTrue(span.start(clock.now())) with(span) { @@ -72,7 +72,7 @@ internal class EmbraceSpanFactoryImplTest { name = "test", type = EmbType.Performance.Default, internal = true, - private = true + private = true, ) assertTrue(span.start(clock.now())) with(span) { @@ -89,7 +89,7 @@ internal class EmbraceSpanFactoryImplTest { name = "test", type = EmbType.Performance.Default, internal = true, - private = false + private = false, ) assertTrue(span.start(clock.now())) with(span) { @@ -108,7 +108,7 @@ internal class EmbraceSpanFactoryImplTest { type = EmbType.System.LowPower, internal = false, private = false, - parent = spanParent + parent = spanParent, ) with(embraceSpanFactory.create(embraceSpanBuilder = spanBuilder)) { diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImplTest.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImplTest.kt index 0b0b233cd0..2fafa85a3f 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImplTest.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanImplTest.kt @@ -71,7 +71,7 @@ internal class EmbraceSpanImplTest { name = EXPECTED_SPAN_NAME, type = EmbType.Performance.Default, internal = false, - private = false + private = false, ) ) fakeClock.tick(100) @@ -489,7 +489,7 @@ internal class EmbraceSpanImplTest { name = EXPECTED_SPAN_NAME, type = EmbType.System.LowPower, internal = true, - private = true + private = true, ) private fun createEmbraceSpanImpl( diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanServiceTest.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanServiceTest.kt index bc5967630e..0da6a13006 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanServiceTest.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanServiceTest.kt @@ -76,7 +76,7 @@ internal class EmbraceSpanServiceTest { endTimeMs = expectedEndTimeMs, type = expectedType, attributes = expectedAttributes, - events = expectedEvents + events = expectedEvents, ) val name = "emb-$expectedName" @@ -101,14 +101,15 @@ internal class EmbraceSpanServiceTest { spanSink.flushSpans() val parent = checkNotNull(spanService.createSpan("test-span")) assertTrue(parent.start()) - val child = checkNotNull(spanService.createSpan(name = "child-span", parent = parent)) + val child = + checkNotNull(spanService.createSpan(name = "child-span", parent = parent)) assertTrue(child.start(startTimeMs = clock.now() - 10)) val grandchild = checkNotNull( spanService.startSpan( name = "grand-child-span", parent = child, - startTimeMs = clock.now() + 1L + startTimeMs = clock.now() + 1L, ) ) assertTrue(grandchild.stop()) @@ -128,7 +129,7 @@ internal class EmbraceSpanServiceTest { spanService.recordCompletedSpan( name = expectedName, startTimeMs = expectedStartTimeMs, - endTimeMs = expectedEndTimeMs + endTimeMs = expectedEndTimeMs, ) ) @@ -141,14 +142,14 @@ internal class EmbraceSpanServiceTest { val expectedName = "child-span" val expectedStartTimeMs = clock.now() val expectedEndTimeMs = expectedStartTimeMs + 100L - val parentSpan = checkNotNull(spanService.createSpan(name = "test-span")) + val parentSpan = checkNotNull(spanService.createSpan("test-span")) assertTrue(parentSpan.start()) assertTrue( spanService.recordCompletedSpan( name = expectedName, startTimeMs = expectedStartTimeMs, endTimeMs = expectedEndTimeMs, - parent = parentSpan + parent = parentSpan, ) ) assertTrue(parentSpan.stop()) @@ -162,7 +163,7 @@ internal class EmbraceSpanServiceTest { @Test fun `can record span after init`() { spanSink.flushSpans() - spanService.recordSpan(name = "test-span") { + spanService.recordSpan("test-span") { spanService.hashCode() } diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceTracerTest.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceTracerTest.kt index b67398ac5a..47d72d8743 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceTracerTest.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/EmbraceTracerTest.kt @@ -270,7 +270,7 @@ internal class EmbraceTracerTest { @Test fun `get same EmbraceSpan using spanId`() { - val embraceSpan = checkNotNull(spanService.createSpan(name = "test-span")) + val embraceSpan = checkNotNull(spanService.createSpan("test-span")) assertTrue(embraceSpan.start()) val spanId = checkNotNull(embraceSpan.spanId) val spanFromTracer = checkNotNull(embraceTracer.getSpan(spanId)) diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/SpanServiceImplTest.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/SpanServiceImplTest.kt index d99aa53cae..dcc1c1bf7e 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/SpanServiceImplTest.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/spans/SpanServiceImplTest.kt @@ -60,7 +60,7 @@ internal class SpanServiceImplTest { @Test fun `create trace with default parameters`() { - val embraceSpan = checkNotNull(spansService.createSpan(name = "test-span")) + val embraceSpan = checkNotNull(spansService.createSpan("test-span")) assertNull(embraceSpan.parent) assertTrue(embraceSpan.start()) assertTrue(embraceSpan.stop()) @@ -73,7 +73,9 @@ internal class SpanServiceImplTest { @Test fun `create trace that is internally logged but public`() { - val embraceSpan = checkNotNull(spansService.createSpan(name = "test-span", internal = true, private = false)) + val embraceSpan = checkNotNull( + spansService.createSpan(name = "test-span", internal = true, private = false) + ) assertNull(embraceSpan.parent) assertTrue(embraceSpan.start()) assertTrue(embraceSpan.stop()) @@ -84,7 +86,9 @@ internal class SpanServiceImplTest { @Test fun `create trace that is private but not considered internally logged`() { - val embraceSpan = checkNotNull(spansService.createSpan(name = "test-span", internal = false, private = true)) + val embraceSpan = checkNotNull( + spansService.createSpan(name = "test-span", internal = false, private = true) + ) assertNull(embraceSpan.parent) assertTrue(embraceSpan.start()) assertTrue(embraceSpan.stop()) @@ -107,7 +111,7 @@ internal class SpanServiceImplTest { val embraceSpan = checkNotNull( spansService.createSpan( name = "test-span", - type = EmbType.Performance.Default + type = EmbType.Performance.Default, ) ) assertTrue(embraceSpan.start()) @@ -187,7 +191,8 @@ internal class SpanServiceImplTest { fun `start a span directly`() { spanSink.flushSpans() val parentStartTime = clock.now() - val parent = checkNotNull(spansService.startSpan(name = "test-span", private = false)) + val parent = + checkNotNull(spansService.startSpan(name = "test-span", private = false)) val childStartTimeMs = clock.now() + 10L val child = checkNotNull( spansService.startSpan( @@ -240,7 +245,7 @@ internal class SpanServiceImplTest { type = expectedType, private = false, attributes = expectedAttributes, - events = expectedEvents + events = expectedEvents, ) with(verifyAndReturnSoleCompletedSpan("emb-$expectedName")) { @@ -268,7 +273,7 @@ internal class SpanServiceImplTest { name = expectedName, startTimeMs = expectedStartTimeMs, endTimeMs = expectedEndTimeMs, - parent = parentSpan + parent = parentSpan, ) ) @@ -299,7 +304,7 @@ internal class SpanServiceImplTest { name = expectedName, startTimeMs = expectedStartTimeMs, endTimeMs = expectedEndTimeMs, - parent = parentSpan + parent = parentSpan, ) ) } @@ -313,7 +318,7 @@ internal class SpanServiceImplTest { name = expectedName, startTimeMs = 10L, endTimeMs = 100L, - parent = parentSpan + parent = parentSpan, ) ) } @@ -326,7 +331,7 @@ internal class SpanServiceImplTest { name = "test${errorCode.name}", startTimeMs = 0, endTimeMs = 1, - errorCode = errorCode + errorCode = errorCode, ) ) with(verifyAndReturnSoleCompletedSpan("emb-test${errorCode.name}")) { @@ -342,7 +347,7 @@ internal class SpanServiceImplTest { spansService.recordCompletedSpan( name = "test-pan", startTimeMs = 500, - endTimeMs = 499 + endTimeMs = 499, ) ) } @@ -357,7 +362,7 @@ internal class SpanServiceImplTest { spansService.recordCompletedSpan( name = "test-span", startTimeMs = 500, - endTimeMs = 600 + endTimeMs = 600, ) ) } @@ -470,7 +475,7 @@ internal class SpanServiceImplTest { name = TOO_LONG_SPAN_NAME, startTimeMs = 100L, endTimeMs = 200L, - internal = false + internal = false, ) ) assertNotNull(spansService.recordSpan(name = TOO_LONG_SPAN_NAME, internal = false) { 1 }) @@ -482,7 +487,7 @@ internal class SpanServiceImplTest { name = MAX_LENGTH_SPAN_NAME, startTimeMs = 100L, endTimeMs = 200L, - internal = false + internal = false, ) ) assertEquals(2, spanSink.completedSpans().size) @@ -496,19 +501,27 @@ internal class SpanServiceImplTest { name = TOO_LONG_INTERNAL_SPAN_NAME, startTimeMs = 100L, endTimeMs = 200L, - internal = true + internal = true, ) ) - assertNotNull(spansService.recordSpan(name = TOO_LONG_INTERNAL_SPAN_NAME, internal = true) { 1 }) + assertNotNull( + spansService.recordSpan(name = TOO_LONG_INTERNAL_SPAN_NAME, internal = true) { + 1 + } + ) assertEquals(0, spanSink.completedSpans().size) assertNotNull(spansService.createSpan(name = MAX_LENGTH_INTERNAL_SPAN_NAME, internal = true)) - assertNotNull(spansService.recordSpan(name = MAX_LENGTH_INTERNAL_SPAN_NAME, internal = true) { 2 }) + assertNotNull( + spansService.recordSpan(name = MAX_LENGTH_INTERNAL_SPAN_NAME, internal = true) { + 2 + } + ) assertTrue( spansService.recordCompletedSpan( name = MAX_LENGTH_INTERNAL_SPAN_NAME, startTimeMs = 100L, endTimeMs = 200L, - internal = true + internal = true, ) ) assertEquals(2, spanSink.completedSpans().size) @@ -521,7 +534,7 @@ internal class SpanServiceImplTest { name = "too many events", startTimeMs = 100L, endTimeMs = 200L, - events = tooBigEvents + events = tooBigEvents, ) ) assertTrue( @@ -529,7 +542,7 @@ internal class SpanServiceImplTest { name = MAX_LENGTH_SPAN_NAME, startTimeMs = 100L, endTimeMs = 200L, - events = maxSizeEvents + events = maxSizeEvents, ) ) @@ -553,7 +566,7 @@ internal class SpanServiceImplTest { startTimeMs = 100L, endTimeMs = 200L, events = events, - internal = false + internal = false, ) ) @@ -570,7 +583,7 @@ internal class SpanServiceImplTest { name = "too many attributes", startTimeMs = 100L, endTimeMs = 200L, - attributes = tooBigAttributes + attributes = tooBigAttributes, ) ) assertTrue( @@ -578,7 +591,7 @@ internal class SpanServiceImplTest { name = MAX_LENGTH_SPAN_NAME, startTimeMs = 100L, endTimeMs = 200L, - attributes = maxSizeAttributes + attributes = maxSizeAttributes, ) ) @@ -598,7 +611,7 @@ internal class SpanServiceImplTest { startTimeMs = 100L, endTimeMs = 200L, attributes = attributesMap, - internal = false + internal = false, ) ) diff --git a/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/crumbs/RnActionDataSource.kt b/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/crumbs/RnActionDataSource.kt index f56bc13d34..c6ae3a003a 100644 --- a/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/crumbs/RnActionDataSource.kt +++ b/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/crumbs/RnActionDataSource.kt @@ -38,7 +38,7 @@ class RnActionDataSource( startTimeMs = startTime, endTimeMs = endTime, type = schemaType.telemetryType, - attributes = schemaType.attributes() + attributes = schemaType.attributes(), ) } ) diff --git a/embrace-test-fakes/config/detekt/baseline.xml b/embrace-test-fakes/config/detekt/baseline.xml index 5c6e047f6c..4ef8e43723 100644 --- a/embrace-test-fakes/config/detekt/baseline.xml +++ b/embrace-test-fakes/config/detekt/baseline.xml @@ -2,7 +2,6 @@ - LongParameterList:EmbraceSpanDataAssertions.kt$( span: Span?, expectedStartTimeMs: Long, expectedEndTimeMs: Long?, expectedParentId: String, expectedTraceId: String? = null, expectedStatus: Span.Status = Span.Status.UNSET, expectedErrorCode: ErrorCode? = null, expectedCustomAttributes: Map<String, String> = emptyMap(), expectedEvents: List<SpanEvent> = emptyList(), private: Boolean = false, key: Boolean = false, ) TooGenericExceptionThrown:FakeSharedPreferences.kt$FakeSharedPreferences$throw Exception("test exception") diff --git a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakePersistableEmbraceSpan.kt b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakePersistableEmbraceSpan.kt index 3c829203b7..441d511fe3 100644 --- a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakePersistableEmbraceSpan.kt +++ b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakePersistableEmbraceSpan.kt @@ -16,6 +16,7 @@ import io.embrace.android.embracesdk.internal.spans.PersistableEmbraceSpan import io.embrace.android.embracesdk.internal.spans.getEmbraceSpan import io.embrace.android.embracesdk.internal.spans.hasFixedAttribute import io.embrace.android.embracesdk.internal.spans.toStatus +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode @@ -33,6 +34,7 @@ class FakePersistableEmbraceSpan( val type: TelemetryType = EmbType.Performance.Default, val internal: Boolean = false, val private: Boolean = internal, + override val autoTerminationMode: AutoTerminationMode = AutoTerminationMode.NONE, private val fakeClock: FakeClock = FakeClock(), ) : PersistableEmbraceSpan { diff --git a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeSpanService.kt b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeSpanService.kt index 68bc4ed9c1..837af30f8f 100644 --- a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeSpanService.kt +++ b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeSpanService.kt @@ -5,6 +5,7 @@ import io.embrace.android.embracesdk.internal.arch.schema.TelemetryType import io.embrace.android.embracesdk.internal.spans.EmbraceSpanBuilder import io.embrace.android.embracesdk.internal.spans.PersistableEmbraceSpan import io.embrace.android.embracesdk.internal.spans.SpanService +import io.embrace.android.embracesdk.spans.AutoTerminationMode import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode @@ -12,7 +13,7 @@ import io.opentelemetry.context.Context class FakeSpanService : SpanService { - val createdSpans: MutableList = mutableListOf() + val createdSpans: MutableList = mutableListOf() override fun initializeService(sdkInitStartTimeMs: Long) { } @@ -21,6 +22,7 @@ class FakeSpanService : SpanService { override fun createSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -30,7 +32,8 @@ class FakeSpanService : SpanService { parentContext = parent?.run { Context.root().with(parent as PersistableEmbraceSpan) } ?: Context.root(), type = type, internal = internal, - private = private + private = private, + autoTerminationMode = autoTerminationMode ).apply { createdSpans.add(this) } @@ -42,13 +45,15 @@ class FakeSpanService : SpanService { parentContext = embraceSpanBuilder.parentContext, type = embraceSpanBuilder.getFixedAttributes().filterIsInstance().single(), internal = embraceSpanBuilder.internal, - private = embraceSpanBuilder.getFixedAttributes().contains(PrivateSpan) + private = embraceSpanBuilder.getFixedAttributes().contains(PrivateSpan), + autoTerminationMode = embraceSpanBuilder.autoTerminationMode, ).apply { createdSpans.add(this) } override fun recordSpan( name: String, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean, @@ -64,6 +69,7 @@ class FakeSpanService : SpanService { name: String, startTimeMs: Long, endTimeMs: Long, + autoTerminationMode: AutoTerminationMode, parent: EmbraceSpan?, type: TelemetryType, internal: Boolean,