-
-
Notifications
You must be signed in to change notification settings - Fork 475
feat: Add sentry-android-navigation module #2116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
romtsn
merged 13 commits into
feat/compose-navigation-support
from
feat/androidx-navigation
Jun 24, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e3bd4b1
Add compose module
romtsn 15085f3
Add sentry-android-navigation module for jetpack.navigation support
romtsn 4076929
Compose sample + tweaks
romtsn 2d64f04
Merge branch 'main' into feat/navigation-breadcrumbs
romtsn 962466a
feat: androidx-navigation support
romtsn 40372df
api dump
romtsn db06058
Address PR reviews
romtsn 29c8107
Add JvmOverloads for java-interop
romtsn bf7bce2
Add tests
romtsn 1c87f90
Switch to compileOnly navigation-runtime dep
romtsn 3ec43e0
Add runtime dep in tests
romtsn 8133b05
Add kotlin language verison for compatibility
romtsn c94942e
feat: Add compose module (navigation) (#2121)
romtsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| /build |
15 changes: 15 additions & 0 deletions
15
sentry-android-navigation/api/sentry-android-navigation.api
This file contains hidden or 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,15 @@ | ||
| public final class io/sentry/android/navigation/BuildConfig { | ||
| public static final field BUILD_TYPE Ljava/lang/String; | ||
| public static final field DEBUG Z | ||
| public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; | ||
| public static final field VERSION_NAME Ljava/lang/String; | ||
| public fun <init> ()V | ||
| } | ||
|
|
||
| public final class io/sentry/android/navigation/SentryNavigationListener : androidx/navigation/NavController$OnDestinationChangedListener { | ||
| public fun <init> ()V | ||
| public fun <init> (Lio/sentry/IHub;)V | ||
| public synthetic fun <init> (Lio/sentry/IHub;ILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
| public fun onDestinationChanged (Landroidx/navigation/NavController;Landroidx/navigation/NavDestination;Landroid/os/Bundle;)V | ||
| } | ||
|
|
This file contains hidden or 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,95 @@ | ||
| import io.gitlab.arturbosch.detekt.Detekt | ||
| import io.gitlab.arturbosch.detekt.extensions.DetektExtension | ||
|
|
||
| plugins { | ||
| id("com.android.library") | ||
| kotlin("android") | ||
| jacoco | ||
| id(Config.QualityPlugins.gradleVersions) | ||
| id(Config.QualityPlugins.detektPlugin) | ||
| } | ||
|
|
||
| android { | ||
| compileSdk = Config.Android.compileSdkVersion | ||
|
|
||
| defaultConfig { | ||
| targetSdk = Config.Android.targetSdkVersion | ||
| minSdk = Config.Android.minSdkVersion | ||
|
|
||
| // for AGP 4.1 | ||
| buildConfigField("String", "VERSION_NAME", "\"${project.version}\"") | ||
| } | ||
|
|
||
| buildTypes { | ||
| getByName("debug") | ||
| getByName("release") { | ||
| consumerProguardFiles("proguard-rules.pro") | ||
| } | ||
| } | ||
|
|
||
| kotlinOptions { | ||
| jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
| kotlinOptions.languageVersion = Config.kotlinCompatibleLanguageVersion | ||
| } | ||
|
|
||
| testOptions { | ||
| animationsDisabled = true | ||
| unitTests.apply { | ||
| isReturnDefaultValues = true | ||
| isIncludeAndroidResources = true | ||
| } | ||
| } | ||
|
|
||
| lint { | ||
| warningsAsErrors = true | ||
| checkDependencies = true | ||
|
|
||
| // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks. | ||
| checkReleaseBuilds = false | ||
| } | ||
|
|
||
| variantFilter { | ||
| if (Config.Android.shouldSkipDebugVariant(buildType.name)) { | ||
| ignore = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<Test> { | ||
| configure<JacocoTaskExtension> { | ||
| isIncludeNoLocationClasses = false | ||
| } | ||
| } | ||
|
|
||
| kotlin { | ||
| explicitApi() | ||
| } | ||
|
|
||
| dependencies { | ||
| api(projects.sentry) | ||
|
|
||
| compileOnly(Config.Libs.navigationRuntime) | ||
|
|
||
| // tests | ||
| testImplementation(Config.Libs.navigationRuntime) | ||
|
|
||
| testImplementation(Config.TestLibs.kotlinTestJunit) | ||
| testImplementation(Config.TestLibs.mockitoKotlin) | ||
| testImplementation(Config.TestLibs.mockitoInline) | ||
|
|
||
| testImplementation(Config.TestLibs.robolectric) | ||
| testImplementation(Config.TestLibs.androidxCore) | ||
| testImplementation(Config.TestLibs.androidxRunner) | ||
| testImplementation(Config.TestLibs.androidxJunit) | ||
| testImplementation(Config.TestLibs.androidxCoreKtx) | ||
| } | ||
|
|
||
| tasks.withType<Detekt> { | ||
| // Target version of the generated JVM bytecode. It is used for type resolution. | ||
| jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
| } | ||
|
|
||
| configure<DetektExtension> { | ||
| buildUponDefaultConfig = true | ||
| allRules = true | ||
| } |
This file contains hidden or 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,7 @@ | ||
| ##---------------Begin: proguard configuration for Compose ---------- | ||
|
|
||
| # To ensure that stack traces is unambiguous | ||
| # https://developer.android.com/studio/build/shrink-code#decode-stack-trace | ||
| -keepattributes LineNumberTable,SourceFile | ||
|
|
||
| ##---------------End: proguard configuration for Compose ---------- |
This file contains hidden or 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,2 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest package="io.sentry.android.navigation"/> |
64 changes: 64 additions & 0 deletions
64
...android-navigation/src/main/java/io/sentry/android/navigation/SentryNavigationListener.kt
This file contains hidden or 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,64 @@ | ||
| package io.sentry.android.navigation | ||
|
|
||
| import android.os.Bundle | ||
| import androidx.navigation.NavController | ||
| import androidx.navigation.NavDestination | ||
| import io.sentry.Breadcrumb | ||
| import io.sentry.Hint | ||
| import io.sentry.HubAdapter | ||
| import io.sentry.IHub | ||
| import io.sentry.SentryLevel.INFO | ||
| import io.sentry.TypeCheckHint | ||
| import java.lang.ref.WeakReference | ||
|
|
||
| class SentryNavigationListener @JvmOverloads constructor( | ||
| private val hub: IHub = HubAdapter.getInstance() | ||
| ) : NavController.OnDestinationChangedListener { | ||
|
|
||
| private var previousDestinationRef: WeakReference<NavDestination>? = null | ||
| private var previousArgs: Bundle? = null | ||
|
romtsn marked this conversation as resolved.
|
||
|
|
||
| override fun onDestinationChanged( | ||
| controller: NavController, | ||
| destination: NavDestination, | ||
| arguments: Bundle? | ||
| ) { | ||
| addBreadcrumb(destination, arguments) | ||
| previousDestinationRef = WeakReference(destination) | ||
| previousArgs = arguments | ||
| } | ||
|
|
||
| private fun addBreadcrumb(destination: NavDestination, arguments: Bundle?) { | ||
| val breadcrumb = Breadcrumb().apply { | ||
| type = "navigation" | ||
| category = "navigation" | ||
|
philipphofmann marked this conversation as resolved.
|
||
|
|
||
| val from = previousDestinationRef?.get()?.route | ||
| from?.let { data["from"] = it } | ||
| previousArgs?.let { args -> | ||
| val fromArguments = args.keySet().filter { | ||
| it != NavController.KEY_DEEP_LINK_INTENT // there's a lot of unrelated stuff | ||
| }.associateWith { args[it] } | ||
| if (fromArguments.isNotEmpty()) { | ||
| data["from_arguments"] = fromArguments | ||
| } | ||
| } | ||
|
|
||
| val to = destination.route | ||
| to?.let { data["to"] = it } | ||
|
romtsn marked this conversation as resolved.
|
||
| arguments?.let { args -> | ||
| val toArguments = args.keySet().filter { | ||
| it != NavController.KEY_DEEP_LINK_INTENT // there's a lot of unrelated stuff | ||
| }.associateWith { args[it] } | ||
| if (toArguments.isNotEmpty()) { | ||
| data["to_arguments"] = toArguments | ||
| } | ||
| } | ||
|
|
||
| level = INFO | ||
| } | ||
| val hint = Hint() | ||
| hint.set(TypeCheckHint.ANDROID_NAV_DESTINATION, destination) | ||
| hub.addBreadcrumb(breadcrumb) | ||
| } | ||
| } | ||
119 changes: 119 additions & 0 deletions
119
...oid-navigation/src/test/java/io/sentry/android/navigation/SentryNavigationListenerTest.kt
This file contains hidden or 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,119 @@ | ||
| package io.sentry.android.navigation | ||
|
|
||
| import androidx.core.os.bundleOf | ||
| import androidx.navigation.NavController | ||
| import androidx.navigation.NavDestination | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.nhaarman.mockitokotlin2.check | ||
| import com.nhaarman.mockitokotlin2.mock | ||
| import com.nhaarman.mockitokotlin2.reset | ||
| import com.nhaarman.mockitokotlin2.verify | ||
| import com.nhaarman.mockitokotlin2.whenever | ||
| import io.sentry.Breadcrumb | ||
| import io.sentry.IHub | ||
| import io.sentry.SentryLevel | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.annotation.Config | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| @Config(sdk = [31]) | ||
| class SentryNavigationListenerTest { | ||
|
romtsn marked this conversation as resolved.
|
||
|
|
||
| class Fixture { | ||
| val hub = mock<IHub>() | ||
| val destination = mock<NavDestination>() | ||
| val navController = mock<NavController>() | ||
|
|
||
| fun getSut(toRoute: String = "route"): SentryNavigationListener { | ||
| whenever(destination.route).thenReturn(toRoute) | ||
| return SentryNavigationListener(hub) | ||
| } | ||
| } | ||
|
|
||
| private val fixture = Fixture() | ||
|
|
||
| @Test | ||
| fun `onDestinationChanged captures a breadcrumb`() { | ||
| val sut = fixture.getSut() | ||
|
|
||
| sut.onDestinationChanged(fixture.navController, fixture.destination, null) | ||
|
|
||
| verify(fixture.hub).addBreadcrumb( | ||
| check<Breadcrumb> { | ||
| assertEquals("navigation", it.type) | ||
| assertEquals("navigation", it.category) | ||
| assertEquals("route", it.data["to"]) | ||
| assertEquals(SentryLevel.INFO, it.level) | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `onDestinationChanged captures a breadcrumb with arguments`() { | ||
| val sut = fixture.getSut() | ||
|
|
||
| sut.onDestinationChanged( | ||
| fixture.navController, | ||
| fixture.destination, | ||
| bundleOf("arg1" to "foo", "arg2" to "bar") | ||
| ) | ||
|
|
||
| verify(fixture.hub).addBreadcrumb( | ||
| check<Breadcrumb> { | ||
| assertEquals("route", it.data["to"]) | ||
| assertEquals(mapOf("arg1" to "foo", "arg2" to "bar"), it.data["to_arguments"]) | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `onDestinationChanged does not send empty args map`() { | ||
| val sut = fixture.getSut() | ||
|
|
||
| sut.onDestinationChanged( | ||
| fixture.navController, | ||
| fixture.destination, | ||
| bundleOf() | ||
| ) | ||
|
|
||
| verify(fixture.hub).addBreadcrumb( | ||
| check<Breadcrumb> { | ||
| assertEquals("route", it.data["to"]) | ||
| assertNull(it.data["to_arguments"]) | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `onDestinationChanged captures a breadcrumb with from and to destinations`() { | ||
| val sut = fixture.getSut(toRoute = "route_from") | ||
|
|
||
| sut.onDestinationChanged( | ||
| fixture.navController, | ||
| fixture.destination, | ||
| bundleOf("from_arg1" to "from_foo") | ||
| ) | ||
| reset(fixture.hub) | ||
|
|
||
| val toDestination = mock<NavDestination> { | ||
| whenever(mock.route).thenReturn("route_to") | ||
| } | ||
| sut.onDestinationChanged( | ||
| fixture.navController, | ||
| toDestination, | ||
| bundleOf("to_arg1" to "to_foo") | ||
| ) | ||
| verify(fixture.hub).addBreadcrumb( | ||
| check<Breadcrumb> { | ||
| assertEquals("route_from", it.data["from"]) | ||
| assertEquals(mapOf("from_arg1" to "from_foo"), it.data["from_arguments"]) | ||
|
|
||
| assertEquals("route_to", it.data["to"]) | ||
| assertEquals(mapOf("to_arg1" to "to_foo"), it.data["to_arguments"]) | ||
| } | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or 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 @@ | ||
| /build |
This file contains hidden or 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,12 @@ | ||
| public final class io/sentry/compose/BuildConfig { | ||
| public static final field BUILD_TYPE Ljava/lang/String; | ||
| public static final field DEBUG Z | ||
| public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; | ||
| public static final field VERSION_NAME Ljava/lang/String; | ||
| public fun <init> ()V | ||
| } | ||
|
|
||
| public final class io/sentry/compose/SentryNavigationIntegrationKt { | ||
| public static final fun withSentryObservableEffect (Landroidx/navigation/NavHostController;Landroidx/compose/runtime/Composer;I)Landroidx/navigation/NavHostController; | ||
| } | ||
|
|
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.