From 2a04dcd55cdc484e2dcd8f0f04634e082f1cf373 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Fri, 26 Jul 2024 12:01:10 +0100 Subject: [PATCH] refactor: move otel module --- .../api/embrace-android-api.api | 51 +++++++++++++++++++ .../embracesdk/internal/InternalTracingApi.kt | 0 .../android/embracesdk/spans/TracingApi.kt | 0 embrace-android-core/build.gradle.kts | 11 ++++ .../arch/schema/AppTerminationCause.kt | 16 ++++++ .../internal/injection/OpenTelemetryModule.kt | 28 +++++----- .../internal/logs/EmbraceLogRecordExporter.kt | 2 +- .../logs/EmbraceLogRecordProcessor.kt | 2 +- .../embracesdk/internal/logs/LogSink.kt | 12 ++--- .../opentelemetry/EmbraceAttributeKeys.kt | 38 +++++++------- .../OpenTelemetryConfiguration.kt | 20 ++++---- .../internal/spans/CurrentSessionSpan.kt | 11 ++-- .../embracesdk/internal/spans/EmbraceExt.kt | 29 +++++++++++ .../internal/spans/EmbraceSpanData.kt | 20 ++------ .../internal/spans/EmbraceSpanExporter.kt | 0 .../internal/spans/EmbraceSpanProcessor.kt | 0 .../internal/spans/EmbraceTracer.kt | 4 +- .../internal/spans/InternalTracer.kt | 2 +- .../internal/spans/SpanRepository.kt | 18 ++++--- .../embracesdk/internal/spans/SpanSink.kt | 8 +-- .../internal/utils/CollectionExtensions.kt | 6 +-- .../embracesdk/internal/payload/Log.kt | 2 +- .../api/embrace-android-sdk.api | 51 ------------------- .../assertions/InternalErrorAssertions.kt | 5 +- .../testcases/ExternalTracerTest.kt | 3 +- .../arch/schema/AppTerminationCause.kt | 16 ------ .../internal/spans/EmbraceExtensions.kt | 26 ---------- .../embracesdk/internal/spans/SpanDataExt.kt | 16 ++++++ .../embracesdk/internal/spans/SpanSinkImpl.kt | 2 +- .../delivery/EmbraceDeliveryServiceTest.kt | 3 +- .../fakes/FakeCurrentSessionSpan.kt | 3 +- .../internal/payload/SpanMapperTest.kt | 8 +-- 32 files changed, 220 insertions(+), 193 deletions(-) rename {embrace-android-sdk/src/main/java => embrace-android-api/src/main/kotlin}/io/embrace/android/embracesdk/internal/InternalTracingApi.kt (100%) rename {embrace-android-sdk/src/main/java => embrace-android-api/src/main/kotlin}/io/embrace/android/embracesdk/spans/TracingApi.kt (100%) create mode 100644 embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/injection/OpenTelemetryModule.kt (77%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordExporter.kt (96%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordProcessor.kt (93%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/logs/LogSink.kt (78%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/opentelemetry/EmbraceAttributeKeys.kt (51%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/opentelemetry/OpenTelemetryConfiguration.kt (81%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpan.kt (65%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/EmbraceSpanData.kt (63%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/EmbraceSpanExporter.kt (100%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/EmbraceSpanProcessor.kt (100%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt (96%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/InternalTracer.kt (99%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/SpanRepository.kt (83%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/spans/SpanSink.kt (78%) rename {embrace-android-sdk/src/main/java => embrace-android-core/src/main/kotlin}/io/embrace/android/embracesdk/internal/utils/CollectionExtensions.kt (91%) rename {embrace-android-sdk/src/main/java => embrace-android-payload/src/main/kotlin}/io/embrace/android/embracesdk/internal/payload/Log.kt (98%) delete mode 100644 embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt create mode 100644 embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanDataExt.kt diff --git a/embrace-android-api/api/embrace-android-api.api b/embrace-android-api/api/embrace-android-api.api index 50c8555caa..26048cc462 100644 --- a/embrace-android-api/api/embrace-android-api.api +++ b/embrace-android-api/api/embrace-android-api.api @@ -15,6 +15,23 @@ public abstract interface annotation class io/embrace/android/embracesdk/annotat public abstract interface annotation class io/embrace/android/embracesdk/annotation/StartupActivity : java/lang/annotation/Annotation { } +public abstract interface class io/embrace/android/embracesdk/internal/InternalTracingApi { + public abstract fun addSpanAttribute (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z + public abstract fun addSpanEvent (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/util/Map;)Z + public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;)Z + public abstract fun recordSpan (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public abstract fun startSpan (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;)Ljava/lang/String; + public abstract fun stopSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/Long;)Z +} + +public final class io/embrace/android/embracesdk/internal/InternalTracingApi$DefaultImpls { + public static synthetic fun addSpanEvent$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/util/Map;ILjava/lang/Object;)Z + public static synthetic fun recordCompletedSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;ILjava/lang/Object;)Z + public static synthetic fun recordSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun startSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;ILjava/lang/Object;)Ljava/lang/String; + public static synthetic fun stopSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Lio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/Long;ILjava/lang/Object;)Z +} + public abstract interface class io/embrace/android/embracesdk/spans/EmbraceSpan { public abstract fun addAttribute (Ljava/lang/String;Ljava/lang/String;)Z public abstract fun addEvent (Ljava/lang/String;)Z @@ -73,3 +90,37 @@ public final class io/embrace/android/embracesdk/spans/ErrorCode : java/lang/Enu public static fun values ()[Lio/embrace/android/embracesdk/spans/ErrorCode; } +public abstract interface class io/embrace/android/embracesdk/spans/TracingApi { + public abstract fun createSpan (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; + public abstract fun createSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; + public abstract fun getSpan (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; + public abstract fun isTracingAvailable ()Z + public abstract fun recordCompletedSpan (Ljava/lang/String;JJ)Z + public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/EmbraceSpan;)Z + public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;)Z + public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z + public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/util/Map;Ljava/util/List;)Z + public abstract fun recordCompletedSpan (Ljava/lang/String;JJLjava/util/Map;Ljava/util/List;)Z + public abstract fun recordSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public abstract fun recordSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public abstract fun recordSpan (Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public abstract fun recordSpan (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public abstract fun startSpan (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; + public abstract fun startSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; + public abstract fun startSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/Long;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; +} + +public final class io/embrace/android/embracesdk/spans/TracingApi$DefaultImpls { + public static fun createSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; + public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJ)Z + public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/EmbraceSpan;)Z + public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;)Z + public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z + public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLjava/util/Map;Ljava/util/List;)Z + public static fun recordSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public static fun recordSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public static fun recordSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public static fun startSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; + public static fun startSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; +} + diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/InternalTracingApi.kt b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/internal/InternalTracingApi.kt similarity index 100% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/InternalTracingApi.kt rename to embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/internal/InternalTracingApi.kt diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/spans/TracingApi.kt b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/spans/TracingApi.kt similarity index 100% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/spans/TracingApi.kt rename to embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/spans/TracingApi.kt diff --git a/embrace-android-core/build.gradle.kts b/embrace-android-core/build.gradle.kts index 4973a25ccd..6afede3d48 100644 --- a/embrace-android-core/build.gradle.kts +++ b/embrace-android-core/build.gradle.kts @@ -6,6 +6,16 @@ description = "Embrace Android SDK: Core" android { namespace = "io.embrace.android.embracesdk.core" + defaultConfig { + // For library projects only, the BuildConfig.VERSION_NAME and BuildConfig.VERSION_CODE properties have been removed from the generated BuildConfig class + // + // https://developer.android.com/studio/releases/gradle-plugin#version_properties_removed_from_buildconfig_class_in_library_projects + buildConfigField("String", "VERSION_NAME", "\"${version}\"") + buildConfigField("String", "VERSION_CODE", "\"${53}\"") + } + buildFeatures { + buildConfig = true + } } apiValidation.validationDisabled = true @@ -15,6 +25,7 @@ dependencies { compileOnly(project(":embrace-android-api")) compileOnly(platform(libs.opentelemetry.bom)) compileOnly(libs.opentelemetry.api) + compileOnly(libs.opentelemetry.sdk) compileOnly(libs.opentelemetry.semconv) compileOnly(libs.opentelemetry.semconv.incubating) compileOnly(libs.lifecycle.common.java8) diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt new file mode 100644 index 0000000000..d351a7503b --- /dev/null +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt @@ -0,0 +1,16 @@ +package io.embrace.android.embracesdk.internal.arch.schema + +/** + * Attribute that stores the reason an app instance terminated + */ +public sealed class AppTerminationCause( + override val value: String +) : FixedAttribute { + override val key: EmbraceAttributeKey = EmbraceAttributeKey(id = "termination_cause") + + public object Crash : AppTerminationCause("crash") + + public object UserTermination : AppTerminationCause("user_termination") + + public object Unknown : AppTerminationCause("unknown") +} diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/injection/OpenTelemetryModule.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/injection/OpenTelemetryModule.kt similarity index 77% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/injection/OpenTelemetryModule.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/injection/OpenTelemetryModule.kt index 62032970de..4c32292fb3 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/injection/OpenTelemetryModule.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/injection/OpenTelemetryModule.kt @@ -16,72 +16,72 @@ import io.opentelemetry.api.trace.TracerProvider /** * Module that instantiates various OpenTelemetry related components */ -internal interface OpenTelemetryModule { +public interface OpenTelemetryModule { /** * Configuration for the OpenTelemetry SDK */ - val openTelemetryConfiguration: OpenTelemetryConfiguration + public val openTelemetryConfiguration: OpenTelemetryConfiguration /** * Caches span instances that are in progress or completed in the current session */ - val spanRepository: SpanRepository + public val spanRepository: SpanRepository /** * Provides storage for completed spans that have not been sent off-device */ - val spanSink: SpanSink + public val spanSink: SpanSink /** * An instance of the OpenTelemetry component obtained from the wrapped SDK to create spans */ - val sdkTracer: Tracer + public val sdkTracer: Tracer /** * Component that manages and provides access to the current session span */ - val currentSessionSpan: CurrentSessionSpan + public val currentSessionSpan: CurrentSessionSpan /** * Service to record spans */ - val spanService: SpanService + public val spanService: SpanService /** * Implementation of public tracing API */ - val embraceTracer: EmbraceTracer + public val embraceTracer: EmbraceTracer /** * Implementation of internal tracing API */ - val internalTracer: InternalTracer + public val internalTracer: InternalTracer /** * An instance of the OpenTelemetry component obtained from the wrapped SDK to create log records */ - val logger: Logger + public val logger: Logger /** * Provides storage for completed logs that have not been forwarded yet to the delivery service */ - val logSink: LogSink + public val logSink: LogSink /** * Provides an [OpenTelemetry] instance that can be used by instrumentation libraries to record telemetry as if it were using the * Embrace APIs. Currently, only the APIs related [Tracer] have operational implementations. Every other method will return no-op * implementations that records no data. */ - val externalOpenTelemetry: OpenTelemetry + public val externalOpenTelemetry: OpenTelemetry /** * Provides [Tracer] instances for instrumentation external to the Embrace SDK to create spans */ - val externalTracerProvider: TracerProvider + public val externalTracerProvider: TracerProvider /** * OpenTelemetry SDK compatible clock based on [clock] */ - val openTelemetryClock: io.opentelemetry.sdk.common.Clock + public val openTelemetryClock: io.opentelemetry.sdk.common.Clock } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordExporter.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordExporter.kt similarity index 96% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordExporter.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordExporter.kt index 4057654d44..6cb103ebfd 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordExporter.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordExporter.kt @@ -9,7 +9,7 @@ import io.opentelemetry.sdk.logs.export.LogRecordExporter /** * Exports the given [LogRecordData] to a [LogSink] */ -internal class EmbraceLogRecordExporter( +public class EmbraceLogRecordExporter( private val logSink: LogSink, private val externalLogRecordExporter: LogRecordExporter ) : LogRecordExporter { diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordProcessor.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordProcessor.kt similarity index 93% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordProcessor.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordProcessor.kt index 5c80800bbd..fbc39b58a1 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordProcessor.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/EmbraceLogRecordProcessor.kt @@ -8,7 +8,7 @@ import io.opentelemetry.sdk.logs.export.LogRecordExporter /** * [LogRecordProcessor] that exports log records it to the given [LogRecordExporter] */ -internal class EmbraceLogRecordProcessor( +public class EmbraceLogRecordProcessor( private val logRecordExporter: LogRecordExporter ) : LogRecordProcessor { diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/LogSink.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/LogSink.kt similarity index 78% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/LogSink.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/LogSink.kt index c18f73c8e4..f8c913d658 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/logs/LogSink.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/logs/LogSink.kt @@ -8,31 +8,31 @@ import io.opentelemetry.sdk.logs.data.LogRecordData * A service that stores exported logs and provides access to them so they * can be sent off-device at the appropriate cadence. */ -internal interface LogSink { +public interface LogSink { /** * Store [Log] objects to be sent in the nexdt batch. Implementations must support concurrent invocations. */ - fun storeLogs(logs: List): CompletableResultCode + public fun storeLogs(logs: List): CompletableResultCode /** * Returns the list of currently stored [Log] objects, waiting to be sent in the next batch */ - fun completedLogs(): List + public fun completedLogs(): List /** * Returns and clears the currently stored [Log] objects, to be used when the next batch is to be sent. * Implementations of this method must make sure the clearing and returning is atomic, i.e. logs cannot be added during this operation. */ - fun flushLogs(): List + public fun flushLogs(): List /** * Return a [Log] that is to be sent immediately rather than batched */ - fun pollNonbatchedLog(): Log? + public fun pollNonbatchedLog(): Log? /** * Registers a callback to be called after new logs are stored. */ - fun registerLogStoredCallback(onLogsStored: () -> Unit) + public fun registerLogStoredCallback(onLogsStored: () -> Unit) } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/opentelemetry/EmbraceAttributeKeys.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/EmbraceAttributeKeys.kt similarity index 51% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/opentelemetry/EmbraceAttributeKeys.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/EmbraceAttributeKeys.kt index 78759ab918..0bed840de3 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/opentelemetry/EmbraceAttributeKeys.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/EmbraceAttributeKeys.kt @@ -6,94 +6,94 @@ import io.embrace.android.embracesdk.internal.payload.ThreadInfo /** * A snapshot of the current call stack of the threads running in the app process per [ThreadInfo] */ -internal val embAndroidThreads = EmbraceAttributeKey("android.threads") +public val embAndroidThreads: EmbraceAttributeKey = EmbraceAttributeKey("android.threads") /** * Sequence number for the number of crashes captured by Embrace on the device, reported on every crash */ -internal val embCrashNumber = EmbraceAttributeKey("android.crash_number") +public val embCrashNumber: EmbraceAttributeKey = EmbraceAttributeKey("android.crash_number") /** * Attribute name for the exception handling type - whether it's handled or unhandled */ -internal val embExceptionHandling = EmbraceAttributeKey("exception_handling") +public val embExceptionHandling: EmbraceAttributeKey = EmbraceAttributeKey("exception_handling") /** * Monotonically increasing sequence ID given to completed span that is expected to be sent to the server */ -internal val embProcessIdentifier: EmbraceAttributeKey = EmbraceAttributeKey("process_identifier") +public val embProcessIdentifier: EmbraceAttributeKey = EmbraceAttributeKey("process_identifier") /** * Attribute name for the unique ID assigned to each app instance */ -internal val embSequenceId: EmbraceAttributeKey = EmbraceAttributeKey(id = "sequence_id", isPrivate = true) +public val embSequenceId: EmbraceAttributeKey = EmbraceAttributeKey(id = "sequence_id", isPrivate = true) /** * Attribute name for the application state (foreground/background) at the time the log was recorded */ -internal val embState = EmbraceAttributeKey("state") +public val embState: EmbraceAttributeKey = EmbraceAttributeKey("state") /** * Attribute name for whether the session is a cold start */ -internal val embColdStart = EmbraceAttributeKey("cold_start") +public val embColdStart: EmbraceAttributeKey = EmbraceAttributeKey("cold_start") /** * Attribute name for session number (integer sequence ID) */ -internal val embSessionNumber = EmbraceAttributeKey("session_number") +public val embSessionNumber: EmbraceAttributeKey = EmbraceAttributeKey("session_number") /** * Attribute name that indicates whether the session was ended by the SDK or an unexpected termination */ -internal val embCleanExit = EmbraceAttributeKey("clean_exit") +public val embCleanExit: EmbraceAttributeKey = EmbraceAttributeKey("clean_exit") /** * Attribute name that indicates whether the session was terminated */ -internal val embTerminated = EmbraceAttributeKey("terminated") +public val embTerminated: EmbraceAttributeKey = EmbraceAttributeKey("terminated") /** * Attribute name that represents last known time that the session existed (nanoseconds since epoch) */ -internal val embHeartbeatTimeUnixNano = EmbraceAttributeKey("heartbeat_time_unix_nano") +public val embHeartbeatTimeUnixNano: EmbraceAttributeKey = EmbraceAttributeKey("heartbeat_time_unix_nano") /** * Attribute name that identifies the crash report tied to the session */ -internal val embCrashId = EmbraceAttributeKey("crash_id") +public val embCrashId: EmbraceAttributeKey = EmbraceAttributeKey("crash_id") /** * Attribute name that identifies the session start type */ -internal val embSessionStartType = EmbraceAttributeKey("session_start_type") +public val embSessionStartType: EmbraceAttributeKey = EmbraceAttributeKey("session_start_type") /** * Attribute name that identifies the session end type */ -internal val embSessionEndType = EmbraceAttributeKey("session_end_type") +public val embSessionEndType: EmbraceAttributeKey = EmbraceAttributeKey("session_end_type") /** * Attribute name that identifies the startup duration */ -internal val embSessionStartupDuration = EmbraceAttributeKey("startup_duration") +public val embSessionStartupDuration: EmbraceAttributeKey = EmbraceAttributeKey("startup_duration") /** * Attribute name that identifies the startup threshold */ -internal val embSessionStartupThreshold = EmbraceAttributeKey("threshold") +public val embSessionStartupThreshold: EmbraceAttributeKey = EmbraceAttributeKey("threshold") /** * Attribute name that identifies the SDK duration */ -internal val embSdkStartupDuration = EmbraceAttributeKey("sdk_startup_duration") +public val embSdkStartupDuration: EmbraceAttributeKey = EmbraceAttributeKey("sdk_startup_duration") /** * Attribute name that identifies the error log count in a session */ -internal val embErrorLogCount = EmbraceAttributeKey("error_log_count") +public val embErrorLogCount: EmbraceAttributeKey = EmbraceAttributeKey("error_log_count") /** * Attribute name that identifies the number of free bytes on disk */ -internal val embFreeDiskBytes = EmbraceAttributeKey("disk_free_bytes") +public val embFreeDiskBytes: EmbraceAttributeKey = EmbraceAttributeKey("disk_free_bytes") diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/opentelemetry/OpenTelemetryConfiguration.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/OpenTelemetryConfiguration.kt similarity index 81% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/opentelemetry/OpenTelemetryConfiguration.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/OpenTelemetryConfiguration.kt index 7b88abc967..460a6511e0 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/opentelemetry/OpenTelemetryConfiguration.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/opentelemetry/OpenTelemetryConfiguration.kt @@ -1,6 +1,6 @@ package io.embrace.android.embracesdk.internal.opentelemetry -import io.embrace.android.embracesdk.BuildConfig +import io.embrace.android.embracesdk.core.BuildConfig import io.embrace.android.embracesdk.internal.SystemInfo import io.embrace.android.embracesdk.internal.logs.EmbraceLogRecordExporter import io.embrace.android.embracesdk.internal.logs.EmbraceLogRecordProcessor @@ -19,15 +19,15 @@ import io.opentelemetry.semconv.incubating.DeviceIncubatingAttributes import io.opentelemetry.semconv.incubating.OsIncubatingAttributes import io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes -internal class OpenTelemetryConfiguration( +public class OpenTelemetryConfiguration( spanSink: SpanSink, logSink: LogSink, systemInfo: SystemInfo, processIdentifier: String ) { - val embraceSdkName = BuildConfig.LIBRARY_PACKAGE_NAME - val embraceSdkVersion = BuildConfig.VERSION_NAME - val resource: Resource = Resource.getDefault().toBuilder() + public val embraceSdkName: String = BuildConfig.LIBRARY_PACKAGE_NAME + public val embraceSdkVersion: String = BuildConfig.VERSION_NAME + public val resource: Resource = Resource.getDefault().toBuilder() .put(ServiceAttributes.SERVICE_NAME, embraceSdkName) .put(ServiceAttributes.SERVICE_VERSION, embraceSdkVersion) .put(OsIncubatingAttributes.OS_NAME, systemInfo.osName) @@ -45,7 +45,7 @@ internal class OpenTelemetryConfiguration( private val externalSpanExporters = mutableListOf() private val externalLogExporters = mutableListOf() - val spanProcessor: SpanProcessor by lazy { + public val spanProcessor: SpanProcessor by lazy { EmbraceSpanProcessor( EmbraceSpanExporter( spanSink = spanSink, @@ -55,7 +55,7 @@ internal class OpenTelemetryConfiguration( ) } - val logProcessor: LogRecordProcessor by lazy { + public val logProcessor: LogRecordProcessor by lazy { EmbraceLogRecordProcessor( EmbraceLogRecordExporter( logSink = logSink, @@ -64,13 +64,13 @@ internal class OpenTelemetryConfiguration( ) } - fun addSpanExporter(spanExporter: SpanExporter) { + public fun addSpanExporter(spanExporter: SpanExporter) { externalSpanExporters.add(spanExporter) } - fun addLogExporter(logExporter: LogRecordExporter) { + public fun addLogExporter(logExporter: LogRecordExporter) { externalLogExporters.add(logExporter) } - fun hasConfiguredOtelExporters() = externalLogExporters.isNotEmpty() || externalSpanExporters.isNotEmpty() + public fun hasConfiguredOtelExporters(): Boolean = externalLogExporters.isNotEmpty() || externalSpanExporters.isNotEmpty() } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpan.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpan.kt similarity index 65% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpan.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpan.kt index cf257866a8..a902a04b41 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpan.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/CurrentSessionSpan.kt @@ -8,19 +8,22 @@ import io.embrace.android.embracesdk.spans.EmbraceSpan /** * Abstraction of the current session span */ -internal interface CurrentSessionSpan : Initializable, SessionSpanWriter { +public interface CurrentSessionSpan : Initializable, SessionSpanWriter { /** * End the current session span and start a new one if the app is not terminating */ - fun endSession(startNewSession: Boolean, appTerminationCause: AppTerminationCause? = null): List + public fun endSession( + startNewSession: Boolean, + appTerminationCause: AppTerminationCause? = null + ): List /** * Returns true if a span with the given parameters can be started in the current session */ - fun canStartNewSpan(parent: EmbraceSpan?, internal: Boolean): Boolean + public fun canStartNewSpan(parent: EmbraceSpan?, internal: Boolean): Boolean /** * Returns the current session ID */ - fun getSessionId(): String + public fun getSessionId(): String } diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceExt.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceExt.kt index aafc02aeeb..577949df90 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceExt.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceExt.kt @@ -1,6 +1,12 @@ package io.embrace.android.embracesdk.internal.spans +import io.embrace.android.embracesdk.internal.arch.schema.EmbraceAttributeKey +import io.embrace.android.embracesdk.internal.arch.schema.FixedAttribute +import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.logs.Severity +import io.opentelemetry.api.trace.Span +import io.opentelemetry.sdk.logs.data.LogRecordData +import io.opentelemetry.sdk.trace.data.SpanData /** * Prefix added to OTel signal object names recorded by the SDK @@ -27,3 +33,26 @@ public fun io.embrace.android.embracesdk.Severity.toOtelSeverity(): Severity = w * Return the appropriate internal Embrace attribute usage name given the current string */ internal fun String.toEmbraceUsageAttributeName(): String = EMBRACE_USAGE_ATTRIBUTE_NAME_PREFIX + this + +/** + * Returns the attributes as a new Map + */ +public fun Attributes.toStringMap(): Map = asMap().entries.associate { + it.key.key.toString() to it.value.toString() +} + +public fun EmbraceSpanData.hasFixedAttribute(fixedAttribute: FixedAttribute): Boolean = + fixedAttribute.value == attributes[fixedAttribute.key.name] + +internal fun Span.setEmbraceAttribute(key: EmbraceAttributeKey, value: String): Span { + setAttribute(key.name, value) + return this +} + +public fun Span.setFixedAttribute(fixedAttribute: FixedAttribute): Span = setEmbraceAttribute(fixedAttribute.key, fixedAttribute.value) + +internal fun SpanData.hasFixedAttribute(fixedAttribute: FixedAttribute): Boolean = + attributes.asMap()[fixedAttribute.key.attributeKey] == fixedAttribute.value + +public fun LogRecordData.hasFixedAttribute(fixedAttribute: FixedAttribute): Boolean = + attributes[fixedAttribute.key.attributeKey] == fixedAttribute.value diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanData.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanData.kt similarity index 63% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanData.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanData.kt index 830448b338..4e8df47e8d 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanData.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanData.kt @@ -4,12 +4,11 @@ import io.embrace.android.embracesdk.internal.clock.nanosToMillis import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.sdk.trace.data.EventData -import io.opentelemetry.sdk.trace.data.SpanData /** * Serializable representation of [EmbraceSpanData] */ -internal data class EmbraceSpanData( +public data class EmbraceSpanData( val traceId: String, val spanId: String, @@ -28,20 +27,9 @@ internal data class EmbraceSpanData( val attributes: Map = emptyMap() ) { - internal constructor(spanData: SpanData) : this( - traceId = spanData.spanContext.traceId, - spanId = spanData.spanContext.spanId, - parentSpanId = spanData.parentSpanId, - name = spanData.name, - startTimeNanos = spanData.startEpochNanos, - endTimeNanos = spanData.endEpochNanos, - status = spanData.status.statusCode, - events = fromEventData(eventDataList = spanData.events), - attributes = spanData.attributes.toStringMap(), - ) - - companion object { - fun fromEventData(eventDataList: List?): List { + + public companion object { + public fun fromEventData(eventDataList: List?): List { val events = mutableListOf() eventDataList?.forEach { eventData -> val event = EmbraceSpanEvent.create( diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanExporter.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanExporter.kt similarity index 100% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanExporter.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanExporter.kt diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanProcessor.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanProcessor.kt similarity index 100% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceSpanProcessor.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceSpanProcessor.kt diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt similarity index 96% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt index cf78901a5d..e3a98cb655 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/EmbraceTracer.kt @@ -7,7 +7,7 @@ import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode import io.embrace.android.embracesdk.spans.TracingApi -internal class EmbraceTracer( +public class EmbraceTracer( private val clock: Clock, private val spanService: SpanService, ) : TracingApi { @@ -70,7 +70,7 @@ internal class EmbraceTracer( * Return the current time in millis for the clock instance used by the Embrace SDK. This should be used to obtain the time * in used for [recordCompletedSpan] so the timestamps will be in sync with those used by the SDK when a time is implicitly recorded. */ - fun getSdkCurrentTimeMs(): Long = clock.now() + public fun getSdkCurrentTimeMs(): Long = clock.now() @Deprecated("Not required. Use Embrace.isStarted() to know when the full tracing API is available") override fun isTracingAvailable(): Boolean = spanService.initialized() diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/InternalTracer.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/InternalTracer.kt similarity index 99% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/InternalTracer.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/InternalTracer.kt index bfc09a2e6a..7da281b0b5 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/InternalTracer.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/InternalTracer.kt @@ -7,7 +7,7 @@ import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.embrace.android.embracesdk.spans.ErrorCode -internal class InternalTracer( +public class InternalTracer( private val spanRepository: SpanRepository, private val embraceTracer: EmbraceTracer, ) : InternalTracingApi { diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanRepository.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanRepository.kt similarity index 83% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanRepository.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanRepository.kt index 3ce31ad010..fea43db75e 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanRepository.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanRepository.kt @@ -10,7 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger /** * Allows the tracking of [EmbraceSpan] instances so that their references can be retrieved with its associated spanId */ -internal class SpanRepository { +public class SpanRepository { private val activeSpans: MutableMap = ConcurrentHashMap() private val completedSpans: MutableMap = mutableMapOf() private val spanIdsInProcess: MutableMap = ConcurrentHashMap() @@ -18,7 +18,7 @@ internal class SpanRepository { /** * Track the [EmbraceSpan] if it has been started and it's not already tracked. */ - fun trackStartedSpan(embraceSpan: PersistableEmbraceSpan) { + public fun trackStartedSpan(embraceSpan: PersistableEmbraceSpan) { val spanId = embraceSpan.spanId ?: return if (notTracked(spanId)) { @@ -37,7 +37,7 @@ internal class SpanRepository { /** * Transition active span to completed span if the span is tracked and the span is actually stopped. */ - fun trackedSpanStopped(spanId: String) { + public fun trackedSpanStopped(spanId: String) { spanIdsInProcess.lockAndRun(spanId) { activeSpans[spanId]?.takeIf { !it.isRecording }?.let { activeSpans.remove(spanId) }?.let { embraceSpan -> completedSpans[spanId] = embraceSpan @@ -48,7 +48,7 @@ internal class SpanRepository { /** * Return the [EmbraceSpan] with the corresponding [spanId] if it's tracked. Return null otherwise. */ - fun getSpan(spanId: String): EmbraceSpan? = + public fun getSpan(spanId: String): EmbraceSpan? = spanIdsInProcess.lockAndRun(spanId) { activeSpans[spanId] ?: completedSpans[spanId] } @@ -56,19 +56,21 @@ internal class SpanRepository { /** * Get a list of active spans that are being tracked */ - fun getActiveSpans(): List = synchronized(spanIdsInProcess) { activeSpans.values.toList() } + public fun getActiveSpans(): List = synchronized(spanIdsInProcess) { + activeSpans.values.toList() + } /** * Get a list of completed spans that are being tracked. */ - fun getCompletedSpans(): List = synchronized(spanIdsInProcess) { + public fun getCompletedSpans(): List = synchronized(spanIdsInProcess) { completedSpans.values.toList() } /** * Stop the existing active spans and mark them as failed */ - fun failActiveSpans(failureTimeMs: Long) { + public fun failActiveSpans(failureTimeMs: Long) { getActiveSpans().filterNot { it.hasFixedAttribute(EmbType.Ux.Session) }.forEach { span -> span.stop(ErrorCode.FAILURE, failureTimeMs) } @@ -77,7 +79,7 @@ internal class SpanRepository { /** * Clear the spans this repository is tracking */ - fun clearCompletedSpans() { + public fun clearCompletedSpans() { synchronized(spanIdsInProcess) { completedSpans.clear() } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanSink.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanSink.kt similarity index 78% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanSink.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanSink.kt index aeb66dbe97..e2a247edb2 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanSink.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/spans/SpanSink.kt @@ -7,20 +7,20 @@ import io.opentelemetry.sdk.trace.data.SpanData * A service that stores all the spans that are completed and exported via [EmbraceSpanExporter], and provides access to them so they * can be sent off-device at the appropriate cadence. */ -internal interface SpanSink { +public interface SpanSink { /** * Stores spans that have been completed. Implementations must support concurrent invocations. */ - fun storeCompletedSpans(spans: List): CompletableResultCode + public fun storeCompletedSpans(spans: List): CompletableResultCode /** * Returns the list of the currently stored completed spans. */ - fun completedSpans(): List + public fun completedSpans(): List /** * Returns and clears the currently stored completed Spans. Implementations of this method must make sure the clearing and returning is * atomic, i.e. spans cannot be added during this operation. */ - fun flushSpans(): List + public fun flushSpans(): List } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/utils/CollectionExtensions.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/utils/CollectionExtensions.kt similarity index 91% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/utils/CollectionExtensions.kt rename to embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/utils/CollectionExtensions.kt index 34c081c75c..a2eecf0c41 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/utils/CollectionExtensions.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/utils/CollectionExtensions.kt @@ -7,7 +7,7 @@ import java.util.concurrent.atomic.AtomicInteger * Returns the element at the specified index. * Returns null if the index is out of bounds, instead of the out-of-bounds exception. */ -internal fun List.at(index: Int): T? { +public fun List.at(index: Int): T? { return if (index >= 0 && index < count()) { this[index] } else { @@ -18,7 +18,7 @@ internal fun List.at(index: Int): T? { /** * Dynamically allocate a set of locks in this map to support mutual exclusion for executing blocks of code when using the same key */ -internal fun MutableMap.lockAndRun(key: String, code: () -> T): T { +public fun MutableMap.lockAndRun(key: String, code: () -> T): T { var lock: AtomicInteger // Find the lock for the given key if it exists - create a new one if it doesn't @@ -52,7 +52,7 @@ internal fun MutableMap.lockAndRun(key: String, code: * or equal to the size of the number of elements requested, but since the underlying data can change after the size check, you can * get more elements than requested if they were added during the [toList] call. */ -internal fun Collection.threadSafeTake(n: Int): List { +public fun Collection.threadSafeTake(n: Int): List { return if (n == 0) { emptyList() } else { diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Log.kt b/embrace-android-payload/src/main/kotlin/io/embrace/android/embracesdk/internal/payload/Log.kt similarity index 98% rename from embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Log.kt rename to embrace-android-payload/src/main/kotlin/io/embrace/android/embracesdk/internal/payload/Log.kt index bfdf3e6293..ec830f1a5c 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Log.kt +++ b/embrace-android-payload/src/main/kotlin/io/embrace/android/embracesdk/internal/payload/Log.kt @@ -21,7 +21,7 @@ import com.squareup.moshi.JsonClass * processing span. If span_id is present, trace_id SHOULD be also present. */ @JsonClass(generateAdapter = true) -internal data class Log( +public data class Log( /* The time the log was captured, in nanoseconds since the Unix epoch */ @Json(name = "time_unix_nano") diff --git a/embrace-android-sdk/api/embrace-android-sdk.api b/embrace-android-sdk/api/embrace-android-sdk.api index 33d23dc332..1345451e4c 100644 --- a/embrace-android-sdk/api/embrace-android-sdk.api +++ b/embrace-android-sdk/api/embrace-android-sdk.api @@ -205,23 +205,6 @@ public abstract interface class io/embrace/android/embracesdk/internal/EmbraceIn public abstract fun stopSdk ()V } -public abstract interface class io/embrace/android/embracesdk/internal/InternalTracingApi { - public abstract fun addSpanAttribute (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z - public abstract fun addSpanEvent (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/util/Map;)Z - public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;)Z - public abstract fun recordSpan (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public abstract fun startSpan (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;)Ljava/lang/String; - public abstract fun stopSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/Long;)Z -} - -public final class io/embrace/android/embracesdk/internal/InternalTracingApi$DefaultImpls { - public static synthetic fun addSpanEvent$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/util/Map;ILjava/lang/Object;)Z - public static synthetic fun recordCompletedSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;ILjava/lang/Object;)Z - public static synthetic fun recordSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Ljava/lang/Object; - public static synthetic fun startSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;ILjava/lang/Object;)Ljava/lang/String; - public static synthetic fun stopSpan$default (Lio/embrace/android/embracesdk/internal/InternalTracingApi;Ljava/lang/String;Lio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/Long;ILjava/lang/Object;)Z -} - public abstract interface class io/embrace/android/embracesdk/internal/api/BreadcrumbApi { public abstract fun addBreadcrumb (Ljava/lang/String;)V } @@ -424,37 +407,3 @@ public final class io/embrace/android/embracesdk/network/http/HttpMethod : java/ public static fun values ()[Lio/embrace/android/embracesdk/network/http/HttpMethod; } -public abstract interface class io/embrace/android/embracesdk/spans/TracingApi { - public abstract fun createSpan (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; - public abstract fun createSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; - public abstract fun getSpan (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; - public abstract fun isTracingAvailable ()Z - public abstract fun recordCompletedSpan (Ljava/lang/String;JJ)Z - public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/EmbraceSpan;)Z - public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;)Z - public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z - public abstract fun recordCompletedSpan (Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/util/Map;Ljava/util/List;)Z - public abstract fun recordCompletedSpan (Ljava/lang/String;JJLjava/util/Map;Ljava/util/List;)Z - public abstract fun recordSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public abstract fun recordSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public abstract fun recordSpan (Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public abstract fun recordSpan (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public abstract fun startSpan (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; - public abstract fun startSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; - public abstract fun startSpan (Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/Long;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; -} - -public final class io/embrace/android/embracesdk/spans/TracingApi$DefaultImpls { - public static fun createSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; - public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJ)Z - public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/EmbraceSpan;)Z - public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;)Z - public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLio/embrace/android/embracesdk/spans/ErrorCode;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z - public static fun recordCompletedSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;JJLjava/util/Map;Ljava/util/List;)Z - public static fun recordSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static fun recordSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Ljava/util/Map;Ljava/util/List;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static fun recordSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static fun startSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; - public static fun startSpan (Lio/embrace/android/embracesdk/spans/TracingApi;Ljava/lang/String;Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Lio/embrace/android/embracesdk/spans/EmbraceSpan; -} - diff --git a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/assertions/InternalErrorAssertions.kt b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/assertions/InternalErrorAssertions.kt index 1f623e8ce4..a0816f34d6 100644 --- a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/assertions/InternalErrorAssertions.kt +++ b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/assertions/InternalErrorAssertions.kt @@ -27,8 +27,9 @@ internal fun assertInternalErrorLogged( } val matchingLogs = logs.filter { log -> - log.attributes?.findAttributeValue(ExceptionAttributes.EXCEPTION_TYPE.key) == exceptionClassName && - log.attributes.findAttributeValue(ExceptionAttributes.EXCEPTION_MESSAGE.key) == errorMessage + val attrs = log.attributes + attrs?.findAttributeValue(ExceptionAttributes.EXCEPTION_TYPE.key) == exceptionClassName && + attrs.findAttributeValue(ExceptionAttributes.EXCEPTION_MESSAGE.key) == errorMessage } if (matchingLogs.isEmpty()) { fail("No internal errors found matching the expected exception") diff --git a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/ExternalTracerTest.kt b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/ExternalTracerTest.kt index 88971a591e..3471137aa8 100644 --- a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/ExternalTracerTest.kt +++ b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/ExternalTracerTest.kt @@ -15,6 +15,7 @@ import io.embrace.android.embracesdk.internal.utils.truncatedStacktraceText import io.embrace.android.embracesdk.internal.opentelemetry.EmbSpan import io.embrace.android.embracesdk.internal.opentelemetry.EmbSpanBuilder import io.embrace.android.embracesdk.internal.opentelemetry.EmbTracer +import io.embrace.android.embracesdk.internal.spans.toEmbraceSpanData import io.embrace.android.embracesdk.recordSession import io.embrace.android.embracesdk.spans.ErrorCode import io.opentelemetry.api.OpenTelemetry @@ -159,7 +160,7 @@ internal class ExternalTracerTest { assertTrue("Timed out waiting for the span to be exported", spanExporter.awaitSpanExport(3)) val exportedSpan: SpanData = spanExporter.exportedSpans.single { it.name == "external-span" } - assertEquals(parent.toOldPayload(), EmbraceSpanData(exportedSpan)) + assertEquals(parent.toOldPayload(), exportedSpan.toEmbraceSpanData()) with(exportedSpan.instrumentationScopeInfo) { assertEquals("external-tracer", name) assertEquals("1.0.0", version) diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt deleted file mode 100644 index 32d3b74191..0000000000 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/arch/schema/AppTerminationCause.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.embrace.android.embracesdk.internal.arch.schema - -/** - * Attribute that stores the reason an app instance terminated - */ -internal sealed class AppTerminationCause( - override val value: String -) : FixedAttribute { - override val key = EmbraceAttributeKey(id = "termination_cause") - - internal object Crash : AppTerminationCause("crash") - - internal object UserTermination : AppTerminationCause("user_termination") - - internal object Unknown : AppTerminationCause("unknown") -} diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceExtensions.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceExtensions.kt index 01b63de0bb..bb1604ccec 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceExtensions.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/EmbraceExtensions.kt @@ -9,15 +9,12 @@ import io.embrace.android.embracesdk.internal.payload.SpanEvent import io.embrace.android.embracesdk.spans.EmbraceSpan import io.embrace.android.embracesdk.spans.EmbraceSpanEvent import io.opentelemetry.api.common.AttributeKey -import io.opentelemetry.api.common.Attributes import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.api.logs.LogRecordBuilder import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanBuilder import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.api.trace.Tracer -import io.opentelemetry.sdk.logs.data.LogRecordData -import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.ExceptionAttributes /** @@ -44,25 +41,11 @@ internal fun Tracer.embraceSpanBuilder( parentSpan = parent, ) -internal fun Span.setEmbraceAttribute(key: EmbraceAttributeKey, value: String): Span { - setAttribute(key.name, value) - return this -} - -internal fun Span.setFixedAttribute(fixedAttribute: FixedAttribute): Span = setEmbraceAttribute(fixedAttribute.key, fixedAttribute.value) - internal fun LogRecordBuilder.setFixedAttribute(fixedAttribute: FixedAttribute): LogRecordBuilder { setAttribute(fixedAttribute.key.attributeKey, fixedAttribute.value) return this } -/** - * Returns the attributes as a new Map - */ -internal fun Attributes.toStringMap(): Map = asMap().entries.associate { - it.key.key.toString() to it.value.toString() -} - /** * Populate an [AttributesBuilder] with String key-value pairs from a [Map] */ @@ -73,15 +56,6 @@ internal fun AttributesBuilder.fromMap(attributes: Map): Attribu return this } -internal fun SpanData.hasFixedAttribute(fixedAttribute: FixedAttribute): Boolean = - attributes.asMap()[fixedAttribute.key.attributeKey] == fixedAttribute.value - -internal fun LogRecordData.hasFixedAttribute(fixedAttribute: FixedAttribute): Boolean = - attributes[fixedAttribute.key.attributeKey] == fixedAttribute.value - -internal fun EmbraceSpanData.hasFixedAttribute(fixedAttribute: FixedAttribute): Boolean = - fixedAttribute.value == attributes[fixedAttribute.key.name] - internal fun io.embrace.android.embracesdk.internal.payload.Span.hasFixedAttribute(fixedAttribute: FixedAttribute): Boolean { return fixedAttribute.value == attributes?.singleOrNull { it.key == fixedAttribute.key.name }?.data } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanDataExt.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanDataExt.kt new file mode 100644 index 0000000000..f2300ef2ba --- /dev/null +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanDataExt.kt @@ -0,0 +1,16 @@ +package io.embrace.android.embracesdk.internal.spans + +import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData.Companion.fromEventData +import io.opentelemetry.sdk.trace.data.SpanData + +internal fun SpanData.toEmbraceSpanData() = EmbraceSpanData( + traceId = spanContext.traceId, + spanId = spanContext.spanId, + parentSpanId = parentSpanId, + name = name, + startTimeNanos = startEpochNanos, + endTimeNanos = endEpochNanos, + status = status.statusCode, + events = fromEventData(eventDataList = events), + attributes = attributes.toStringMap(), +) diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanSinkImpl.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanSinkImpl.kt index 42525fb941..fa96a7db64 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanSinkImpl.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/spans/SpanSinkImpl.kt @@ -13,7 +13,7 @@ internal class SpanSinkImpl : SpanSink { override fun storeCompletedSpans(spans: List): CompletableResultCode { try { - completedSpans += spans.map { EmbraceSpanData(spanData = it) } + completedSpans += spans.map { it.toEmbraceSpanData() } } catch (t: Throwable) { return CompletableResultCode.ofFailure() } diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/comms/delivery/EmbraceDeliveryServiceTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/comms/delivery/EmbraceDeliveryServiceTest.kt index 3064396ea6..23e2aa2c77 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/comms/delivery/EmbraceDeliveryServiceTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/comms/delivery/EmbraceDeliveryServiceTest.kt @@ -41,6 +41,7 @@ import io.embrace.android.embracesdk.internal.session.orchestrator.SessionSnapsh import io.embrace.android.embracesdk.internal.session.orchestrator.SessionSnapshotType.NORMAL_END import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData import io.embrace.android.embracesdk.internal.spans.findAttributeValue +import io.embrace.android.embracesdk.internal.spans.toEmbraceSpanData import io.embrace.android.embracesdk.internal.worker.BackgroundWorker import io.embrace.android.embracesdk.spans.ErrorCode import io.opentelemetry.api.trace.SpanId @@ -194,7 +195,7 @@ internal class EmbraceDeliveryServiceTest { @Test fun `do not add failed span from a snapshot if a span with the same id is already in the payload`() { - val startedSnapshot = EmbraceSpanData(perfSpanSnapshot) + val startedSnapshot = perfSpanSnapshot.toEmbraceSpanData() val completedSpan = startedSnapshot.copy(endTimeNanos = startedSnapshot.startTimeNanos + 10000000L) val snapshots = listOfNotNull(startedSnapshot) val base = fakeSessionEnvelope() diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeCurrentSessionSpan.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeCurrentSessionSpan.kt index 7bfa551221..206af0a5d3 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeCurrentSessionSpan.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeCurrentSessionSpan.kt @@ -7,6 +7,7 @@ import io.embrace.android.embracesdk.internal.arch.schema.SchemaType import io.embrace.android.embracesdk.internal.clock.millisToNanos import io.embrace.android.embracesdk.internal.spans.CurrentSessionSpan import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData +import io.embrace.android.embracesdk.internal.spans.toEmbraceSpanData import io.embrace.android.embracesdk.spans.EmbraceSpan import io.opentelemetry.sdk.trace.data.StatusData import java.util.concurrent.atomic.AtomicInteger @@ -52,7 +53,7 @@ internal class FakeCurrentSessionSpan( endingSessionSpan.spanStatus = if (appTerminationCause == null) StatusData.ok() else StatusData.error() sessionIteration.incrementAndGet() sessionSpan = if (appTerminationCause == null) newSessionSpan(clock.now()) else null - return listOf(EmbraceSpanData((endingSessionSpan))) + return listOf((endingSessionSpan).toEmbraceSpanData()) } override fun canStartNewSpan(parent: EmbraceSpan?, internal: Boolean): Boolean { diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/internal/payload/SpanMapperTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/internal/payload/SpanMapperTest.kt index bd36840687..42702954f2 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/internal/payload/SpanMapperTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/internal/payload/SpanMapperTest.kt @@ -7,7 +7,7 @@ import io.embrace.android.embracesdk.arch.assertNotPrivateSpan import io.embrace.android.embracesdk.arch.assertSuccessful import io.embrace.android.embracesdk.fakes.FakeSpanData import io.embrace.android.embracesdk.internal.clock.nanosToMillis -import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData +import io.embrace.android.embracesdk.internal.spans.toEmbraceSpanData import io.embrace.android.embracesdk.spans.ErrorCode import io.opentelemetry.api.trace.StatusCode import org.junit.Assert.assertEquals @@ -17,7 +17,7 @@ internal class SpanMapperTest { @Test fun toSpan() { - val input = EmbraceSpanData(FakeSpanData.perfSpanCompleted) + val input = FakeSpanData.perfSpanCompleted.toEmbraceSpanData() val output = input.toNewPayload() assertEquals(input.traceId, output.traceId) @@ -45,7 +45,7 @@ internal class SpanMapperTest { @Test fun `terminating span snapshot works as expected`() { - val snapshot = EmbraceSpanData(FakeSpanData.perfSpanSnapshot).toNewPayload() + val snapshot = FakeSpanData.perfSpanSnapshot.toEmbraceSpanData().toNewPayload() val terminationTimeMs = snapshot.startTimeNanos!!.nanosToMillis() + 60000L val failedSpan = snapshot.toFailedSpan(terminationTimeMs) @@ -69,7 +69,7 @@ internal class SpanMapperTest { @Test fun `terminating span snapshot as old payload works as expected`() { - val snapshot = EmbraceSpanData(FakeSpanData.perfSpanSnapshot) + val snapshot = FakeSpanData.perfSpanSnapshot.toEmbraceSpanData() val terminationTimeMs = snapshot.startTimeNanos.nanosToMillis() + 60000L val failedSpan = snapshot.toFailedSpan(terminationTimeMs)