Skip to content

Odd activity auto tracing duration #1787

Closed

Description

@louis-fri

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

Activity

  1. marandaneto commented on Oct 29, 2021

    @marandaneto
    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

  2. louis-fri commented on Oct 29, 2021

    @louis-fri
    Author

    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.

  3. marandaneto commented on Oct 29, 2021

    @marandaneto
    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.

  4. LouisYubo commented on Oct 29, 2021

    @LouisYubo

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

  5. marandaneto commented on Nov 5, 2021

    @marandaneto
    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.

  6. marandaneto commented on Nov 16, 2021

    @marandaneto
    Contributor

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

  7. louis-fri commented on Nov 16, 2021

    @louis-fri
    Author

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

  8. marandaneto commented on Nov 16, 2021

    @marandaneto
    Contributor

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

  9. louis-fri commented on Nov 16, 2021

    @louis-fri
    Author

    @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"

  10. marandaneto commented on Nov 16, 2021

    @marandaneto
    Contributor

    will have a look, thanks

  11. 2 remaining items

  12. marandaneto commented on Nov 17, 2021

    @marandaneto
    Contributor

    I can confirm that HomeFragment isn't calling onFragmentResumed

  13. marandaneto commented on Nov 17, 2021

    @marandaneto
    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.

  14. marandaneto commented on Nov 17, 2021

    @marandaneto
    Contributor

    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.

  15. LouisYubo commented on Nov 18, 2021

    @LouisYubo

    @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.

  16. marandaneto commented on Nov 18, 2021

    @marandaneto
    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?

  17. marandaneto commented on Nov 18, 2021

    @marandaneto
    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?

  18. LouisYubo commented on Nov 18, 2021

    @LouisYubo

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

  19. marandaneto commented on Nov 18, 2021

    @marandaneto
    Contributor

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

  20. LouisYubo commented on Nov 18, 2021

    @LouisYubo

    @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

  21. marandaneto commented on Nov 18, 2021

    @marandaneto
    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.

  22. ghost added
    Bug
    on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugLogbackperformance

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions