Skip to content

Commit

Permalink
Merge pull request #1117 from embrace-io/move-span-arch
Browse files Browse the repository at this point in the history
Move span arch classes over
  • Loading branch information
fractalwrench authored Jul 19, 2024
2 parents a7084ee + a2ae1a0 commit b694b5a
Show file tree
Hide file tree
Showing 28 changed files with 182 additions and 256 deletions.
67 changes: 67 additions & 0 deletions embrace-android-api/api/embrace-android-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,70 @@ public final class io/embrace/android/embracesdk/Severity : java/lang/Enum {
public static fun values ()[Lio/embrace/android/embracesdk/Severity;
}

public abstract interface annotation class io/embrace/android/embracesdk/annotation/BetaApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class io/embrace/android/embracesdk/annotation/InternalApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class io/embrace/android/embracesdk/annotation/StartupActivity : java/lang/annotation/Annotation {
}

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
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 getParent ()Lio/embrace/android/embracesdk/spans/EmbraceSpan;
public abstract fun getSpanContext ()Lio/opentelemetry/api/trace/SpanContext;
public abstract fun getSpanId ()Ljava/lang/String;
public abstract fun getTraceId ()Ljava/lang/String;
public abstract fun isRecording ()Z
public abstract fun recordException (Ljava/lang/Throwable;)Z
public abstract fun recordException (Ljava/lang/Throwable;Ljava/util/Map;)Z
public abstract fun start ()Z
public abstract fun start (Ljava/lang/Long;)Z
public abstract fun stop ()Z
public abstract fun stop (Lio/embrace/android/embracesdk/spans/ErrorCode;)Z
public abstract fun stop (Lio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/Long;)Z
public abstract fun stop (Ljava/lang/Long;)Z
public abstract fun updateName (Ljava/lang/String;)Z
}

public final class io/embrace/android/embracesdk/spans/EmbraceSpan$DefaultImpls {
public static fun addEvent (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/String;)Z
public static fun addEvent (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/String;Ljava/lang/Long;)Z
public static fun recordException (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/Throwable;)Z
public static fun start (Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z
public static fun stop (Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z
public static fun stop (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Lio/embrace/android/embracesdk/spans/ErrorCode;)Z
public static fun stop (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/Long;)Z
}

public final class io/embrace/android/embracesdk/spans/EmbraceSpanEvent {
public static final field Companion Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent$Companion;
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()J
public final fun component3 ()Ljava/util/Map;
public final fun copy (Ljava/lang/String;JLjava/util/Map;)Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;
public static synthetic fun copy$default (Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;Ljava/lang/String;JLjava/util/Map;ILjava/lang/Object;)Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;
public fun equals (Ljava/lang/Object;)Z
public final fun getAttributes ()Ljava/util/Map;
public final fun getName ()Ljava/lang/String;
public final fun getTimestampNanos ()J
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class io/embrace/android/embracesdk/spans/EmbraceSpanEvent$Companion {
public final fun create (Ljava/lang/String;JLjava/util/Map;)Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;
}

public final class io/embrace/android/embracesdk/spans/ErrorCode : java/lang/Enum {
public static final field FAILURE Lio/embrace/android/embracesdk/spans/ErrorCode;
public static final field UNKNOWN Lio/embrace/android/embracesdk/spans/ErrorCode;
public static final field USER_ABANDON Lio/embrace/android/embracesdk/spans/ErrorCode;
public static fun valueOf (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/ErrorCode;
public static fun values ()[Lio/embrace/android/embracesdk/spans/ErrorCode;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.embrace.android.embracesdk.annotation

import java.lang.annotation.Inherited

/**
* `@Documented` means that the annotation indicates that elements using this annotation should be documented by JavaDoc.
*
*
* `@Target` specifies where we can use the annotation.
* If you do not define any Target type that means annotation can be applied to any element.
*
*
* `@Inherited` signals that a custom annotation used in a class should be inherited by all of its sub classes.
*
*
* `@Retention` indicates how long annotations with the annotated type are to be retained.
* RetentionPolicy.RUNTIME means the annotation should be available at runtime, for inspection via java reflection.
*/
@MustBeDocumented
@Target(AnnotationTarget.CLASS)
@Inherited
@Retention(AnnotationRetention.RUNTIME)
public annotation class StartupActivity
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
package io.embrace.android.embracesdk.spans

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import io.embrace.android.embracesdk.annotation.BetaApi
import io.embrace.android.embracesdk.internal.clock.millisToNanos
import java.util.concurrent.TimeUnit

/**
* Represents an Event in an [EmbraceSpan]
*/
@BetaApi
@JsonClass(generateAdapter = true)
public data class EmbraceSpanEvent internal constructor(
/**
* The name of the event
*/
@Json(name = "name")
val name: String,

/**
* The timestamp of the event in nanoseconds
*/
@Json(name = "time_unix_nano")
val timestampNanos: Long,

/**
* The attributes of this event
*/
@Json(name = "attributes")
val attributes: Map<String, String>
) {

Expand All @@ -42,7 +36,11 @@ public data class EmbraceSpanEvent internal constructor(
*/
public fun create(name: String, timestampMs: Long, attributes: Map<String, String>?): EmbraceSpanEvent? {
if (inputsValid(name, attributes)) {
return EmbraceSpanEvent(name = name, timestampNanos = timestampMs.millisToNanos(), attributes = attributes ?: emptyMap())
return EmbraceSpanEvent(
name = name,
timestampNanos = TimeUnit.MILLISECONDS.toNanos(timestampMs),
attributes = attributes ?: emptyMap()
)
}

return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.embrace.android.embracesdk.spans

import io.embrace.android.embracesdk.annotation.BetaApi
import io.embrace.android.embracesdk.internal.arch.schema.ErrorCodeAttribute

/**
* Categorize the broad reason a Span completed unsuccessfully.
Expand All @@ -21,11 +20,5 @@ public enum class ErrorCode {
/**
* The reason for the unsuccessful termination is unknown
*/
UNKNOWN;

internal fun fromErrorCode(): ErrorCodeAttribute = when (this) {
FAILURE -> ErrorCodeAttribute.Failure
USER_ABANDON -> ErrorCodeAttribute.UserAbandon
UNKNOWN -> ErrorCodeAttribute.Unknown
}
UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ package io.embrace.android.embracesdk.internal
* to defer expensive initialization logic to a later time when it's desirable to create the instance earlier but we don't want to take
* the upfront performance hit of the init.
*/
internal interface Initializable {
public interface Initializable {

/**
* Explicitly initialize the service post instance creation
*/
fun initializeService(sdkInitStartTimeMs: Long)
public fun initializeService(sdkInitStartTimeMs: Long)

/**
* Returns true if this service is initialized
*/
fun initialized(): Boolean
public fun initialized(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.embrace.android.embracesdk.internal.arch.schema
/**
* Denotes an important span to be aggregated and displayed as such in the platform.
*/
internal object KeySpan : FixedAttribute {
override val key = EmbraceAttributeKey(id = "key")
public object KeySpan : FixedAttribute {
override val key: EmbraceAttributeKey = EmbraceAttributeKey(id = "key")
override val value: String = "true"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package io.embrace.android.embracesdk.internal.arch.schema
* Denotes a private span recorded by Embrace for diagnostic or internal usage purposes that is not meant to be consumed directly by
* users of the SDK, nor is considered part of the public API.
*/
internal object PrivateSpan : FixedAttribute {
override val key = EmbraceAttributeKey(id = "private")
public object PrivateSpan : FixedAttribute {
override val key: EmbraceAttributeKey = EmbraceAttributeKey(id = "private")
override val value: String = "true"
}
76 changes: 0 additions & 76 deletions embrace-android-sdk/api/embrace-android-sdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@ public final class io/embrace/android/embracesdk/WebViewClientSwazzledHooks {
public static fun _preOnPageStarted (Landroid/webkit/WebView;Ljava/lang/String;Landroid/graphics/Bitmap;)V
}

public abstract interface annotation class io/embrace/android/embracesdk/annotation/BetaApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class io/embrace/android/embracesdk/annotation/InternalApi : java/lang/annotation/Annotation {
}

public abstract interface annotation class io/embrace/android/embracesdk/annotation/StartupActivity : java/lang/annotation/Annotation {
}

public abstract interface class io/embrace/android/embracesdk/internal/EmbraceInternalInterface : io/embrace/android/embracesdk/internal/InternalTracingApi {
public abstract fun getSdkCurrentTime ()J
public abstract fun isAnrCaptureEnabled ()Z
Expand Down Expand Up @@ -433,73 +424,6 @@ 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/EmbraceSpan {
public abstract fun addAttribute (Ljava/lang/String;Ljava/lang/String;)Z
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 getParent ()Lio/embrace/android/embracesdk/spans/EmbraceSpan;
public abstract fun getSpanContext ()Lio/opentelemetry/api/trace/SpanContext;
public abstract fun getSpanId ()Ljava/lang/String;
public abstract fun getTraceId ()Ljava/lang/String;
public abstract fun isRecording ()Z
public abstract fun recordException (Ljava/lang/Throwable;)Z
public abstract fun recordException (Ljava/lang/Throwable;Ljava/util/Map;)Z
public abstract fun start ()Z
public abstract fun start (Ljava/lang/Long;)Z
public abstract fun stop ()Z
public abstract fun stop (Lio/embrace/android/embracesdk/spans/ErrorCode;)Z
public abstract fun stop (Lio/embrace/android/embracesdk/spans/ErrorCode;Ljava/lang/Long;)Z
public abstract fun stop (Ljava/lang/Long;)Z
public abstract fun updateName (Ljava/lang/String;)Z
}

public final class io/embrace/android/embracesdk/spans/EmbraceSpan$DefaultImpls {
public static fun addEvent (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/String;)Z
public static fun addEvent (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/String;Ljava/lang/Long;)Z
public static fun recordException (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/Throwable;)Z
public static fun start (Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z
public static fun stop (Lio/embrace/android/embracesdk/spans/EmbraceSpan;)Z
public static fun stop (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Lio/embrace/android/embracesdk/spans/ErrorCode;)Z
public static fun stop (Lio/embrace/android/embracesdk/spans/EmbraceSpan;Ljava/lang/Long;)Z
}

public final class io/embrace/android/embracesdk/spans/EmbraceSpanEvent {
public static final field Companion Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent$Companion;
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()J
public final fun component3 ()Ljava/util/Map;
public final fun copy (Ljava/lang/String;JLjava/util/Map;)Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;
public static synthetic fun copy$default (Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;Ljava/lang/String;JLjava/util/Map;ILjava/lang/Object;)Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;
public fun equals (Ljava/lang/Object;)Z
public final fun getAttributes ()Ljava/util/Map;
public final fun getName ()Ljava/lang/String;
public final fun getTimestampNanos ()J
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class io/embrace/android/embracesdk/spans/EmbraceSpanEvent$Companion {
public final fun create (Ljava/lang/String;JLjava/util/Map;)Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;
}

public final class io/embrace/android/embracesdk/spans/EmbraceSpanEventJsonAdapter : com/squareup/moshi/JsonAdapter {
public fun <init> (Lcom/squareup/moshi/Moshi;)V
public fun fromJson (Lcom/squareup/moshi/JsonReader;)Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;
public synthetic fun fromJson (Lcom/squareup/moshi/JsonReader;)Ljava/lang/Object;
public fun toJson (Lcom/squareup/moshi/JsonWriter;Lio/embrace/android/embracesdk/spans/EmbraceSpanEvent;)V
public synthetic fun toJson (Lcom/squareup/moshi/JsonWriter;Ljava/lang/Object;)V
public fun toString ()Ljava/lang/String;
}

public final class io/embrace/android/embracesdk/spans/ErrorCode : java/lang/Enum {
public static final field FAILURE Lio/embrace/android/embracesdk/spans/ErrorCode;
public static final field UNKNOWN Lio/embrace/android/embracesdk/spans/ErrorCode;
public static final field USER_ABANDON Lio/embrace/android/embracesdk/spans/ErrorCode;
public static fun valueOf (Ljava/lang/String;)Lio/embrace/android/embracesdk/spans/ErrorCode;
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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.embrace.android.embracesdk.internal.arch.schema

import io.embrace.android.embracesdk.spans.ErrorCode
import io.embrace.android.embracesdk.spans.ErrorCode.FAILURE
import io.embrace.android.embracesdk.spans.ErrorCode.UNKNOWN
import io.embrace.android.embracesdk.spans.ErrorCode.USER_ABANDON
import java.util.Locale

/**
Expand All @@ -17,4 +20,10 @@ internal sealed class ErrorCodeAttribute(
internal object UserAbandon : ErrorCodeAttribute(ErrorCode.USER_ABANDON)

internal object Unknown : ErrorCodeAttribute(ErrorCode.UNKNOWN)

internal fun ErrorCode.fromErrorCode(): ErrorCodeAttribute = when (this) {
FAILURE -> ErrorCodeAttribute.Failure
USER_ABANDON -> ErrorCodeAttribute.UserAbandon
UNKNOWN -> ErrorCodeAttribute.Unknown
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.embrace.android.embracesdk.internal.arch.schema.AppTerminationCause
import io.embrace.android.embracesdk.internal.arch.schema.EmbType
import io.embrace.android.embracesdk.internal.arch.schema.ErrorCodeAttribute
import io.embrace.android.embracesdk.internal.clock.millisToNanos
import io.embrace.android.embracesdk.internal.clock.nanosToMillis
import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData
import io.embrace.android.embracesdk.internal.spans.hasFixedAttribute
import io.embrace.android.embracesdk.internal.spans.setFixedAttribute
Expand All @@ -30,9 +31,9 @@ internal fun EmbraceSpanEvent.toNewPayload() = SpanEvent(
attributes = attributes.toNewPayload()
)

internal fun SpanEvent.toOldPayload() = EmbraceSpanEvent(
internal fun SpanEvent.toOldPayload() = EmbraceSpanEvent.create(
name = name ?: "",
timestampNanos = timestampNanos ?: 0,
timestampMs = (timestampNanos ?: 0).nanosToMillis(),
attributes = attributes?.toOldPayload() ?: emptyMap()
)

Expand All @@ -56,7 +57,7 @@ internal fun Span.toOldPayload(): EmbraceSpanData {
Span.Status.ERROR -> StatusCode.ERROR
else -> StatusCode.UNSET
},
events = events?.map { it.toOldPayload() } ?: emptyList(),
events = events?.mapNotNull { it.toOldPayload() } ?: emptyList(),
attributes = attributes?.toOldPayload() ?: emptyMap()
)
}
Expand Down
Loading

0 comments on commit b694b5a

Please sign in to comment.