Skip to content

Commit aaeb610

Browse files
romtsnclaude
andcommitted
fix: Decouple screen tracking from performance tracing in fragments
Screen name updates on scope should work independently of whether performance tracing is enabled. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5d6efb4 commit aaeb610

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public class SentryFragmentLifecycleCallbacks(
163163
fragmentsWithOngoingTransactions.containsKey(fragment)
164164

165165
private fun startTracing(fragment: Fragment) {
166-
if (!fragment.isAdded || !isPerformanceEnabled || isRunningSpan(fragment)) {
166+
if (!fragment.isAdded) {
167167
return
168168
}
169169

@@ -173,6 +173,10 @@ public class SentryFragmentLifecycleCallbacks(
173173
scopes.configureScope { it.screen = fragmentName }
174174
}
175175

176+
if (!isPerformanceEnabled || isRunningSpan(fragment)) {
177+
return
178+
}
179+
176180
var transaction: ISpan? = null
177181
scopes.configureScope { transaction = it.transaction }
178182

sentry-android-fragment/src/test/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacksTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,22 @@ class SentryFragmentLifecycleCallbacksTest {
291291
verify(fixture.scope).screen = "androidx.fragment.app.Fragment"
292292
}
293293

294+
@Test
295+
fun `When performance is disabled, it should still update screen name`() {
296+
val sut =
297+
fixture.getSut(enableAutoFragmentLifecycleTracing = false, enableScreenTracking = true)
298+
299+
sut.onFragmentViewCreated(
300+
fixture.fragmentManager,
301+
fixture.fragment,
302+
view = mock(),
303+
savedInstanceState = null,
304+
)
305+
306+
verify(fixture.scope).screen = "androidx.fragment.app.Fragment"
307+
verify(fixture.transaction, never()).startChild(any<String>(), any<String>())
308+
}
309+
294310
@Test
295311
fun `When fragment view is created after onFragmentCreated, it should not start a second span`() {
296312
// Normal path: onFragmentCreated already started the span; onFragmentViewCreated is a no-op

0 commit comments

Comments
 (0)