-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support creating custom spans and attributes in the startup trace (#1824
) ## Goal Add the ability to add custom child spans and attributes to UI load traces. Also exposed a public method to get the SDK timestamp so the custom spans can use the same clock as the rest of the spans i the traces ## Testing Added unit and integration tests
- Loading branch information
Showing
10 changed files
with
208 additions
and
2 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
58 changes: 58 additions & 0 deletions
58
...src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/AppStartupTraceTest.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,58 @@ | ||
package io.embrace.android.embracesdk.testcases | ||
|
||
import android.os.Build | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.embrace.android.embracesdk.assertions.findSpansOfType | ||
import io.embrace.android.embracesdk.fakes.config.FakeEnabledFeatureConfig | ||
import io.embrace.android.embracesdk.fakes.config.FakeInstrumentedConfig | ||
import io.embrace.android.embracesdk.internal.arch.schema.EmbType | ||
import io.embrace.android.embracesdk.internal.spans.findAttributeValue | ||
import io.embrace.android.embracesdk.testframework.IntegrationTestRule | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
|
||
@Config(sdk = [Build.VERSION_CODES.LOLLIPOP]) | ||
@RunWith(AndroidJUnit4::class) | ||
internal class AppStartupTraceTest { | ||
@Rule | ||
@JvmField | ||
val testRule: IntegrationTestRule = IntegrationTestRule() | ||
|
||
@Test | ||
fun `startup spans recorded in foreground session when background activity is enabled`() { | ||
testRule.runTest( | ||
instrumentedConfig = FakeInstrumentedConfig( | ||
enabledFeatures = FakeEnabledFeatureConfig( | ||
bgActivityCapture = true | ||
) | ||
), | ||
testCaseAction = { | ||
val customStartTimeMs = clock.now() | ||
val customEndTimeMs = clock.tick(100L) | ||
embrace.addStartupChildSpan("custom-span", customStartTimeMs, customEndTimeMs) | ||
embrace.addStartupTraceAttribute("custom-attribute", "yes") | ||
simulateOpeningActivities( | ||
addStartupActivity = false, | ||
startInBackground = true | ||
) | ||
}, | ||
assertAction = { | ||
with(getSingleSessionEnvelope()) { | ||
val spans = findSpansOfType(EmbType.Performance.Default).associateBy { it.name } | ||
assertTrue(spans.isNotEmpty()) | ||
with(checkNotNull(spans["emb-cold-time-to-initial-display"])) { | ||
assertEquals("yes", attributes?.findAttributeValue("custom-attribute")) | ||
} | ||
assertTrue(spans.containsKey("emb-embrace-init")) | ||
assertTrue(spans.containsKey("custom-span")) | ||
assertTrue(spans.containsKey("emb-activity-create")) | ||
assertTrue(spans.containsKey("emb-activity-resume")) | ||
} | ||
} | ||
) | ||
} | ||
} |
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.