sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

SentryFragmentLifecycleCallbacks creates long running spans for ViewPager2

Open markushi opened this issue 1 year ago • 3 comments

Integration

sentry-android

Build System

Gradle

AGP Version

unknown

Proguard

Enabled

Version

unknown

Steps to Reproduce

  1. Use ViewPager2
  2. Enable performance and our FragmentLifecycleIntegration

Expected Result

No span is created for non-visible fragments.

Actual Result

A span is created, but due to this:

non-primary-item Fragments are capped at STARTED

the spans end up running into an timeout, causing extra long transaction durations.

We probably should be using getUserVisibleHint() or getMinimumMaxLifecycleState() to determine Fragments which won't be activated.

┆Issue is synchronized with this Jira Improvement by Unito

markushi avatar Mar 18 '24 18:03 markushi

@markushi any updates on this? I added a report from an enterprise customer in the linked Jira ticket. They believe the same issue is affecting their TTID.

maxkosty avatar Apr 25 '24 17:04 maxkosty

cc @stefanosiano

kahest avatar Apr 26 '24 09:04 kahest

we are going to take a look at this in the next week

stefanosiano avatar Apr 26 '24 13:04 stefanosiano

Hi @stefanosiano, were you guys able to make any progress on this one?

maxkosty avatar May 13 '24 15:05 maxkosty

Hi @realkosty I was having some problem, but now I'm finally able to reproduce it and working on it 👍

stefanosiano avatar May 13 '24 16:05 stefanosiano

Options considered:

  • getUserVisibleHint(): it's deprecated and returns true for all fragments
  • mMaxState: only accessible through reflection and returns the current max state achieved (in onFragmentStarted it will be STARTED, while in onFragmentResumed it will be RESUMED
  • isVisible: returns true for all fragments

It seems like the only real option for us is to stop the span in onFragmentStarted instead of onFragmentResumed. Breadcrumbs will still be created correctly and most operations are going to be in Fragment.onCreate and associated callbacks, so it should be fine for users.

stefanosiano avatar May 15 '24 14:05 stefanosiano