-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how Embrace attributes are defined (#526)
## Goal Create an abstraction for an Embrace Attribute and define a sealed class for each attribute and an implementation of that class for each valid value. I converted two attributes just to get some feedback as to whether this is a good idea/implementation. If it looks good, I can convert EmbType/TelemetryType to this format as well. The goal is to be able to use these class when validating values in tests, and also when we write out the property to OTel objects, instead of having to hardcode rules like putting `emb.` in front of attribute names, etc. If this looks good, I'll add convenience methods to internal objects and tests to simply the code that words with Embrace attributes, so you can do something like span.setEmbraceAttribute(ErrorCode.Failure) ## Testing Existing tests cover the usage, but unit tests should be added to test the abstract classes if this is deemed a good way to go.
- Loading branch information
Showing
16 changed files
with
122 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ndroid-sdk/src/main/java/io/embrace/android/embracesdk/arch/schema/AppTerminationCause.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.embrace.android.embracesdk.arch.schema | ||
|
||
/** | ||
* Attribute that stores the reason an app instance terminated | ||
*/ | ||
internal sealed class AppTerminationCause( | ||
override val attributeValue: String | ||
) : EmbraceAttribute { | ||
override val attributeName: String = "termination_cause" | ||
|
||
internal object Crash : AppTerminationCause("crash") | ||
|
||
internal object UserTermination : AppTerminationCause("user_termination") | ||
|
||
internal object Unknown : AppTerminationCause("unknown") | ||
} |
20 changes: 20 additions & 0 deletions
20
...e-android-sdk/src/main/java/io/embrace/android/embracesdk/arch/schema/EmbraceAttribute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.embrace.android.embracesdk.arch.schema | ||
|
||
import io.embrace.android.embracesdk.internal.spans.toEmbraceAttributeName | ||
|
||
/** | ||
* Instance of a valid value for an attribute that has special meaning in the Embrace platform. | ||
*/ | ||
internal interface EmbraceAttribute { | ||
/** | ||
* The unique name given to the attribute | ||
*/ | ||
val attributeName: String | ||
|
||
/** | ||
* The value of the particular instance of the attribute | ||
*/ | ||
val attributeValue: String | ||
|
||
fun otelAttributeName(): String = attributeName.toEmbraceAttributeName() | ||
} |
20 changes: 20 additions & 0 deletions
20
...android-sdk/src/main/java/io/embrace/android/embracesdk/arch/schema/ErrorCodeAttribute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.embrace.android.embracesdk.arch.schema | ||
|
||
import io.embrace.android.embracesdk.spans.ErrorCode | ||
import java.util.Locale | ||
|
||
/** | ||
* Attribute that stores the [ErrorCode] in an OpenTelemetry span | ||
*/ | ||
internal sealed class ErrorCodeAttribute( | ||
errorCode: ErrorCode | ||
) : EmbraceAttribute { | ||
override val attributeName: String = "error_code" | ||
override val attributeValue: String = errorCode.name.toLowerCase(Locale.ENGLISH) | ||
|
||
internal object Failure : ErrorCodeAttribute(ErrorCode.FAILURE) | ||
|
||
internal object UserAbandon : ErrorCodeAttribute(ErrorCode.USER_ABANDON) | ||
|
||
internal object Unknown : ErrorCodeAttribute(ErrorCode.UNKNOWN) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.