firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 573 forks source link

Customizable screen name in Firebase Performance metrics #3737

Open angelolloqui opened 2 years ago

angelolloqui commented 2 years ago

What feature would you like to see?

When using Firebase Performance in my app, I see we have all screens tracked under the same screen name, making it unusuable since it aggregates all screens together. This is happening since I have a parent activity that dynamically starts new fragments with the appropriate content. Note that this is not identical to a classic single activity project, since in my case we do open multiple activities, but the activity class name is always the same. Checking the code I think the info from the screen name comes from here:

   // AppStateMonitor
    public static String getScreenTraceName(Activity activity) {
        return "_st_" + activity.getClass().getSimpleName();
    }

Could you provide an API to instead of always getting the name from the class, to allow for custom namings? this way I would just add my own logic to show a custom screen name, and so I can distinguish the different screens with their appropriate frame metrics.

How would you use it?

I would like to be able to setup something during my app startup like:

AppStateMonitor.getInstance().setScreenNameProvider { activity -> activity.myFragmentLogic.name }

This provider by default could be instantiated with the current logic to be backward compatible:

val screenNameProvider = { activity -> activity.getClass().getSimpleName() }

An alternative approach to the lambda could be providing some interface that the activity can implement to provide the name

google-oss-bot commented 2 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

angelolloqui commented 2 years ago

BTW, maybe a better approach to also support single activity apps would be to provide APIs in AppStateMonitor to start a metric and end a metric by screen, so instead of having a map of Activities->traces, you could have a map of Strings->traces. This way, a developer could do something like:

// On fragment resume
AppStateMonitor.getInstance().startMonitoringScreen("MyFragmentName")

// On fragment stop
AppStateMonitor.getInstance().stopMonitoringScreen("MyFragmentName")
leotianlizhan commented 2 years ago

Hey @angelolloqui , we are releasing a new feature (automatically instrument Fragment screen traces) soon that would solve the use-case of the "classic single Activity project" where each fragment is a "screen" or "navigation destination". But it may or may not satisfy your use-case, so I want to ask some clarification questions for your case.

Is my understanding correct that each instance of your Activity (say ExampleActivity) dynamically populate its content?

Then, is each instance of your Activity using a unique Fragment class? For example, ExampleActivity (instance 1) only contains AlphaFragment ExampleActivity (instance 2) only contains BetaFragment ExampleActivity (instance 3) only contains GammaFragment ...

Is the Fragment inside your Activity most of the content? Meaning, your Activity doesn't do anything before Fragment is loaded and after the Fragment is removed, so there's nothing worth capturing for that Activity if you already have a Fragment trace captured?

If yes to all of these questions, then our next release should cover your use case.

angelolloqui commented 2 years ago

Hi @leotianlizhan ! thanks for the quick answer!

Yes, that is indeed my use case, so I am willing to update to your next version

Regards!

thatfiredev commented 2 years ago

@angelolloqui That feature has just been released on version 20.1.0 (BoM 30.1.0) of Firebase Performance! Give it a try and let us know if it fixes your issue :)

shamilovtim commented 2 years ago

I think we still need the custom screen name for react native and would need to be able to disable the Fragment workflow. See #3756

angelolloqui commented 2 years ago

Thanks @thatfiredev ! I am giving it a try and seems to work like a charm. I will put in on pro next week. I will let you know if any issue arises. Regards!