Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd activity auto tracing duration #1787

Closed
4 tasks done
LouisFn opened this issue Oct 29, 2021 · 20 comments · Fixed by #1813
Closed
4 tasks done

Odd activity auto tracing duration #1787

LouisFn opened this issue Oct 29, 2021 · 20 comments · Fixed by #1813
Labels
Logback performance Performance API issues Platform: Android Type: Bug Something isn't working
Projects

Comments

@LouisFn
Copy link

LouisFn commented Oct 29, 2021

Platform:

  • Android -> minSdk: 24, compileSdk: 30, targetSdk: 30, buildTools: 31.0.0
  • Kotlin -> 1.5.31, jvmTarget: VERSION_11
  • Timber -> 5.0.1

Build system:

  • Gradle -> 7.2

_Android Gradle Plugin: 7.0.2

The version of the SDK:
5.2.0


I have the following issue:

We get odd result with activity auto tracing. We receive many transactions with a very long duration on prod.

Screenshot 2021-10-29 at 10 59 40

@marandaneto
Copy link
Contributor

@LouisFn thanks for reporting.

can you reproduce that?

https://docs.sentry.io/platforms/android/performance/instrumentation/automatic-instrumentation/#androids-activity-instrumentation

did you disable the io.sentry.traces.activity.auto-finish.enable config or is it enabled as it is by default?

can you give some more context? thanks

@LouisFn
Copy link
Author

LouisFn commented Oct 29, 2021

Sadly we can't reproduce that but in prod, there are 10% of the traces of our MainActivity which have invalid duration (more than 10min up to 30h) ...
No, we didn't disable io.sentry.traces.activity.auto-finish.enable.

@marandaneto
Copy link
Contributor

@LouisFn did you find any pattern from this 10% of traces? like OS version, Device brand, or something.
I can't reproduce it either.

@LouisYubo
Copy link

LouisYubo commented Oct 29, 2021

No, we didn't find any pattern, it occurs on different android version and devices.

@marandaneto
Copy link
Contributor

@LouisYubo I can't really reproduce it, not sure how to proceed, any ideas on how to reproduce otherwise I'd have to close it.

@marandaneto
Copy link
Contributor

@LouisFn does your app have notifications? is it possible that users open your app via notification?

@LouisFn
Copy link
Author

LouisFn commented Nov 16, 2021

@marandaneto Completely, I can reproduce it by opening the app from notification

@marandaneto
Copy link
Contributor

@LouisFn ok thats a good start, can you tell me the exact steps to reproduce it? or provide a minimal reproducible example? thanks

@LouisFn
Copy link
Author

LouisFn commented Nov 16, 2021

@marandaneto It seems to be because the lib wait for the child traces to finish before stoping the transaction (waitForChildren) and the child trace from FragmentLifecycleIntegration never ends.

It's due to NavDeepLinkBuilder, when the deep link is triggered, the destination and all of its parents will be on the back stack. But for its parents, only onCreate is called but not onResume. So the HomeFragment transaction never finished.

You can find a reproducible example here:
https://github.com/LouisFn/SentryFrozenFrame

BTW, I think it would be usefull to add an option to disable "waitForChildren"

@marandaneto
Copy link
Contributor

will have a look, thanks

@marandaneto marandaneto added Type: Bug Something isn't working Logback and removed waiting for feedback labels Nov 17, 2021
@marandaneto
Copy link
Contributor

I can confirm that HomeFragment isn't calling onFragmentResumed

@marandaneto
Copy link
Contributor

@LouisFn in your use case, maybe there's a bug in your example as well, you set:

app:startDestination="@id/navigation_fragment_home"

but in LaunchActivity, you set .setDestination(R.id.navigation_fragment_home), so HomeFragment isn't even visible or anything, looks like a wrong setup of the navigation-ui rather than the bug in Sentry SDK.

@marandaneto
Copy link
Contributor

marandaneto commented Nov 17, 2021

do setDestination and app:startDestination must match or not? didn't find docs for that, if they don't have to, maybe fixing on the SDK would make more sense.

@LouisYubo
Copy link

@LouisFn in your use case, maybe there's a bug in your example as well, you set:

app:startDestination="@id/navigation_fragment_home"

but in LaunchActivity, you set .setDestination(R.id.navigation_fragment_home), so HomeFragment isn't even visible or anything, looks like a wrong setup of the navigation-ui rather than the bug in Sentry SDK.

I don't understand what you mean, I set .setDestination(R.id.navigation_fragment_chat) no .setDestination(R.id.navigation_fragment_home) so it's normal if HomeFragment isn't visible

do setDestination and app:startDestination must match or not? didn't find docs for that, if they don't have to, maybe fixing on the SDK would make more sense.

No, the purpose is to navigate to a specific destination (not the start destination) while adding the start destination to the backstack.

From the docs: https://developer.android.com/reference/androidx/navigation/NavDeepLinkBuilder

When this deep link is triggered:
The task is cleared.
The destination and all of its parents will be on the back stack.
[...]
The parent of the destination is the start destination of the containing navigation graph.

@marandaneto marandaneto added this to To do in kanban via automation Nov 18, 2021
@marandaneto marandaneto moved this from To do to In progress in kanban Nov 18, 2021
@marandaneto
Copy link
Contributor

sorry it was a typo, .setDestination(R.id.navigation_fragment_chat) indeed.

No, the purpose is to navigate to a specific destination (not the start destination) while adding the start destination to the backstack.

got it, that makes sense, since the fragment does not trigger any other lifecycle, I don't really know how to finish the span automatically for that case, ideas?

@marandaneto
Copy link
Contributor

even if I provide a custom waitForChildren, how would you know if HomeFragment was just added to the back stack but never visible, programmatically?

@LouisYubo
Copy link

LouisYubo commented Nov 18, 2021

I think, you might check if fragment isAdded in onCreate before starting the trace ?

@marandaneto
Copy link
Contributor

indeed @LouisYubo that's totally possible and it works, thanks for the tip, See PR #1813

kanban automation moved this from In progress to Done Nov 18, 2021
@LouisYubo
Copy link

LouisYubo commented Nov 18, 2021

@marandaneto Thanks a lot for the fix :)

But I think there are others issues with the auto tracing activity that doesn't seem to be related to waitForChildren. For now I didn't managed to reproduce this case

Screenshot 2021-11-18 at 13 50 56

or

Screenshot 2021-11-18 at 13 52 56

App Startup - MainActivity#onCreate is a custom child span added to measure our onCreate implementation

@marandaneto
Copy link
Contributor

@LouisYubo it could be related to opening the App thru notifications, mind testing that out? at least the sample that you have given is fixed, please raise a new issue with more detailed use case for the other one, also a minimal reproducible example would help as it did with this one, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Logback performance Performance API issues Platform: Android Type: Bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

3 participants