Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ android {
isMinifyEnabled = true
signingConfig = signingConfigs.getByName("debug")
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
testProguardFiles("proguard-rules.pro")
}
getByName("release") {
isMinifyEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import androidx.test.core.app.launchActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.sentry.ProfilingTraceData
import io.sentry.Sentry
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.android.core.AndroidLogger
import io.sentry.android.core.CurrentActivityHolder
import io.sentry.android.core.NdkIntegration
import io.sentry.android.core.SentryAndroidOptions
import io.sentry.assertEnvelopeTransaction
import io.sentry.protocol.SentryTransaction
Expand All @@ -15,6 +18,7 @@ import org.junit.runner.RunWith
import shark.AndroidReferenceMatchers
import shark.IgnoredReferenceMatcher
import shark.ReferencePattern
import java.util.concurrent.CountDownLatch
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down Expand Up @@ -215,4 +219,74 @@ class SdkInitTests : BaseUiTest() {

LeakAssertions.assertNoLeaks()
}

@Test
fun foregroundInitInstallsDefaultIntegrations() {
val activityScenario = launchActivity<ComposeActivity>()
activityScenario.moveToState(Lifecycle.State.RESUMED)
activityScenario.onActivity { activity ->
// Our SentryInitProvider does not run in this test
// so we need to set the current activity manually
CurrentActivityHolder.getInstance().setActivity(activity)
initSentry(false) { options: SentryAndroidOptions ->
options.tracesSampleRate = 1.0
options.profilesSampleRate = 1.0
}
}
activityScenario.moveToState(Lifecycle.State.DESTROYED)
assertDefaultIntegrations()
}

@Test
fun backgroundInitInstallsDefaultIntegrations() {
val initLatch = CountDownLatch(1)

val activityScenario = launchActivity<ComposeActivity>()
activityScenario.moveToState(Lifecycle.State.RESUMED)
activityScenario.onActivity { activity ->
// Our SentryInitProvider does not run in this test
// so we need to set the current activity manually
CurrentActivityHolder.getInstance().setActivity(activity)
Thread {
initSentry(false) { options: SentryAndroidOptions ->
options.tracesSampleRate = 1.0
options.profilesSampleRate = 1.0
}
initLatch.countDown()
}.start()
}
initLatch.await()

activityScenario.moveToState(Lifecycle.State.DESTROYED)

assertDefaultIntegrations()
}

private fun assertDefaultIntegrations() {
val integrations = mutableListOf(
"UncaughtExceptionHandler",
"ShutdownHook",
"SendCachedEnvelope",
"AppLifecycle",
"EnvelopeFileObserver",
"AnrV2",
"ActivityLifecycle",
"ActivityBreadcrumbs",
"UserInteraction",
"AppComponentsBreadcrumbs",
"NetworkBreadcrumbs"
)

// NdkIntegration is not always available, so we check for its presence
try {
Class.forName(NdkIntegration.SENTRY_NDK_CLASS_NAME)
integrations.add("Ndk")
} catch (_: ClassNotFoundException) {
// ignored, in case the app is build without NDK support
}

for (integration in integrations) {
assertTrue(SentryIntegrationPackageStorage.getInstance().integrations.contains(integration), "Integration $integration was expected, but was not registered")
}
}
}
Loading