Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move OpenTelemetry module #1142

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions embrace-android-api/api/embrace-android-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

11 changes: 11 additions & 0 deletions embrace-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogRecordData>): CompletableResultCode
public fun storeLogs(logs: List<LogRecordData>): CompletableResultCode

/**
* Returns the list of currently stored [Log] objects, waiting to be sent in the next batch
*/
fun completedLogs(): List<Log>
public fun completedLogs(): List<Log>

/**
* 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<Log>
public fun flushLogs(): List<Log>

/**
* 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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Loading