Skip to content

Commit

Permalink
Merge branch 'main' into ref/catch-throwable
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-garcia committed Nov 18, 2021
2 parents 7d0e05c + 2d41eca commit 8311e42
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## Unreleased

* Ref: catch Throwable instead of Exception to suppress internal SDK errors (#1812)

## 5.4.1

* Feat: Refactor OkHttp and Apollo to Kotlin functional interfaces (#1797)
* Feat: Add secondary constructor to SentryInstrumentation (#1804)
* Ref: catch Throwable instead of Exception to suppress internal SDK errors (#1812)
* Fix: Do not start fragment span if not added to the Activity (#1813)

## 5.4.0

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m -XX:MaxMetaspaceSize=1536m -XX:+H
android.useAndroidX=true

# Release information
versionName=5.4.1-SNAPSHOT
versionName=5.4.2-SNAPSHOT

# disable renderscript, it's enabled by default
android.defaults.buildfeatures.renderscript=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ class SentryFragmentLifecycleCallbacks(
) {
addBreadcrumb(fragment, "created")

startTracing(fragment)
// we only start the tracing for the fragment if the fragment has been added to its activity
// and not only to the backstack
if (fragment.isAdded) {
startTracing(fragment)
}
}

override fun onFragmentViewCreated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class SentryFragmentLifecycleCallbacksTest {
fun getSut(
enableFragmentLifecycleBreadcrumbs: Boolean = true,
enableAutoFragmentLifecycleTracing: Boolean = false,
tracesSampleRate: Double? = 1.0
tracesSampleRate: Double? = 1.0,
isAdded: Boolean = true
): SentryFragmentLifecycleCallbacks {
whenever(hub.options).thenReturn(
SentryOptions().apply {
Expand All @@ -48,6 +49,7 @@ class SentryFragmentLifecycleCallbacksTest {
whenever(hub.configureScope(any())).thenAnswer {
(it.arguments[0] as ScopeCallback).run(scope)
}
whenever(fragment.isAdded).thenReturn(isAdded)
return SentryFragmentLifecycleCallbacks(
hub = hub,
enableFragmentLifecycleBreadcrumbs = enableFragmentLifecycleBreadcrumbs,
Expand Down Expand Up @@ -196,6 +198,15 @@ class SentryFragmentLifecycleCallbacksTest {
)
}

@Test
fun `When fragment is created but not added to activity, it should not start tracing`() {
val sut = fixture.getSut(enableAutoFragmentLifecycleTracing = true, isAdded = false)

sut.onFragmentCreated(fixture.fragmentManager, fixture.fragment, savedInstanceState = null)

verify(fixture.transaction, never()).startChild(any(), any())
}

@Test
fun `When tracing is already running, do not start again`() {
val sut = fixture.getSut(enableAutoFragmentLifecycleTracing = true)
Expand Down

0 comments on commit 8311e42

Please sign in to comment.