sentry-java
sentry-java copied to clipboard
Custom Transactions for Screens in Insights.ScreenLoads
Problem Statement
Hi, customer made custom tranasctions for their Screens (majority of their screens are not Activities, so Auto Instrumentation doesn't help them much)
How can they get these custom transactions to appear in Screen Loads? Need the TTID TTFD too.
Solution Brainstorm
A way to let Custom Transactions to appear in Screen Loads and with their TTID TTFD.
Quoting some internal discussion around this:
Yes, you can. You “just” need to adhere to using the right txn/span op names and measurements.
- Every screens needs to be a transaction created with op="ui.load"
- TTID needs to be a span tracked with
op="ui.load.initial_display" - TTFD needs to be a span created with
op="ui.load.full_display" - On top of that the TTID/TTFD need to be set as a measurement as well
Here's a more complete pseudo-code example:
// start a new transaction on every screen load / navigation event
val screenTransaction = Sentry.startTransaction(op="ui.load", description="My Compose Screen")
val ttidSpan = screenTransaction.startSpan(op="ui.load.initial_display", description="My Compose Screen TTID")
val ttfdSpan = screenTransaction.startSpan(op="ui.load.full_display", description="My Compose Screen TTFD")
// after the first frame is drawn, finish TTID
ttidSpan.finish()
screenTransaction.setMeasurement("time_to_initial_display", <duration>, MeasurementUnit.Duration.MILLISECOND)
// after the screen data is loaded, finish TTFD
ttfdSpan.finish()
screenTransaction.setMeasurement("time_to_full_display", <duration>, MeasurementUnit.Duration.MILLISECOND)
// finally, finish the transaction, so it can be sent to sentry
screenTransaction.finish()
Relevant GH issue for adding a screens API is over here.