-
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.
Add in extension functions useful when working with EmbraceAttributes
- Loading branch information
1 parent
2a1b4ba
commit 587bfd3
Showing
23 changed files
with
211 additions
and
125 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
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
9 changes: 9 additions & 0 deletions
9
embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/arch/schema/KeySpan.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,9 @@ | ||
package io.embrace.android.embracesdk.arch.schema | ||
|
||
/** | ||
* Denotes an important span to be aggregated and displayed as such in the platform. | ||
*/ | ||
internal object KeySpan : EmbraceAttribute { | ||
override val attributeName: String = "key" | ||
override val attributeValue: String = "true" | ||
} |
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
80 changes: 80 additions & 0 deletions
80
...ndroid-sdk/src/test/java/io/embrace/android/embracesdk/arch/EmbraceAttributeExtensions.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,80 @@ | ||
package io.embrace.android.embracesdk.arch | ||
|
||
import io.embrace.android.embracesdk.arch.destination.LogEventData | ||
import io.embrace.android.embracesdk.arch.destination.StartSpanData | ||
import io.embrace.android.embracesdk.arch.schema.EmbType | ||
import io.embrace.android.embracesdk.arch.schema.EmbraceAttribute | ||
import io.embrace.android.embracesdk.arch.schema.ErrorCodeAttribute | ||
import io.embrace.android.embracesdk.arch.schema.KeySpan | ||
import io.embrace.android.embracesdk.arch.schema.TelemetryType | ||
import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData | ||
import io.embrace.android.embracesdk.spans.ErrorCode | ||
import io.opentelemetry.api.trace.StatusCode | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNull | ||
import org.junit.Assert.assertFalse | ||
|
||
/** | ||
* Assert [EmbraceSpanData] is of type [EmbType.Performance.Default] | ||
*/ | ||
internal fun EmbraceSpanData.assertIsTypePerformance() = assertIsType(EmbType.Performance.Default) | ||
|
||
/** | ||
* Assert [EmbraceSpanData] is of type [telemetryType] | ||
*/ | ||
internal fun EmbraceSpanData.assertIsType(telemetryType: TelemetryType) = assertHasEmbraceAttribute(telemetryType) | ||
|
||
internal fun EmbraceSpanData.assertIsKeySpan() = assertHasEmbraceAttribute(KeySpan) | ||
|
||
internal fun EmbraceSpanData.assertNotKeySpan() = assertDoesNotHaveEmbraceAttribute(KeySpan) | ||
|
||
/** | ||
* Assert [EmbraceSpanData] has the [EmbraceAttribute] defined by [embraceAttribute] | ||
*/ | ||
internal fun EmbraceSpanData.assertHasEmbraceAttribute(embraceAttribute: EmbraceAttribute) { | ||
assertEquals(embraceAttribute.attributeValue, attributes[embraceAttribute.otelAttributeName()]) | ||
} | ||
|
||
internal fun EmbraceSpanData.assertDoesNotHaveEmbraceAttribute(embraceAttribute: EmbraceAttribute) { | ||
assertFalse(attributes[embraceAttribute.otelAttributeName()]?.equals(embraceAttribute.attributeValue) ?: false) | ||
} | ||
|
||
/** | ||
* Assert [EmbraceSpanData] has ended with the error defined by [errorCode] | ||
*/ | ||
internal fun EmbraceSpanData.assertError(errorCode: ErrorCode) { | ||
assertEquals(StatusCode.ERROR, status) | ||
assertHasEmbraceAttribute(errorCode.fromErrorCode()) | ||
} | ||
|
||
/** | ||
* Assert [EmbraceSpanData] has ended successfully | ||
*/ | ||
internal fun EmbraceSpanData.assertSuccessful() { | ||
assertEquals(StatusCode.OK, status) | ||
assertNull(attributes[ErrorCodeAttribute.Failure.otelAttributeName()]) | ||
} | ||
|
||
/** | ||
* Assert [StartSpanData] is of type [telemetryType] | ||
*/ | ||
internal fun StartSpanData.assertIsType(telemetryType: TelemetryType) = assertHasEmbraceAttribute(telemetryType) | ||
|
||
/** | ||
* Assert [StartSpanData] has the [EmbraceAttribute] defined by [embraceAttribute] | ||
*/ | ||
internal fun StartSpanData.assertHasEmbraceAttribute(embraceAttribute: EmbraceAttribute) { | ||
assertEquals(embraceAttribute.attributeValue, attributes[embraceAttribute.otelAttributeName()]) | ||
} | ||
|
||
/** | ||
* Assert [LogEventData] is of type [telemetryType] | ||
*/ | ||
internal fun LogEventData.assertIsType(telemetryType: TelemetryType) = assertHasEmbraceAttribute(telemetryType) | ||
|
||
/** | ||
* Assert [LogEventData] has the [EmbraceAttribute] defined by [embraceAttribute] | ||
*/ | ||
internal fun LogEventData.assertHasEmbraceAttribute(embraceAttribute: EmbraceAttribute) { | ||
assertEquals(embraceAttribute.attributeValue, attributes[embraceAttribute.otelAttributeName()]) | ||
} |
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.