getsentry / sentry-java

A Sentry SDK for Java, Android and other JVM languages.
https://docs.sentry.io/
MIT License
1.15k stars 435 forks source link

Track composable functions with @SentryTraceable annotation #2071

Open romtsn opened 2 years ago

romtsn commented 2 years ago

Description

Create transactions/spans for @Composable functions annotated with @SentryTraceable, so we can enrich events that pop up within that composable lifetime. The code to measure that could roughly look like this:

    DisposableEffect(Unit) {
        Log.e("SENTRY", "ENTERED COMPOSITION")
        onDispose {
            Log.e("SENTRY", "LEFT COMPOSITION")
        }
    }

Would require bytecode manipulation through SAGP.

marandaneto commented 2 years ago

@romtsn The Java SDK already has such annotations https://github.com/getsentry/sentry-java/blob/main/sentry-spring/src/main/java/io/sentry/spring/tracing/SentryTransaction.java In case the target and retention match, we could e.g. move it to the core package.

romtsn commented 2 years ago

Also, we'd probably need this to correctly measure the App Startup/Screen TTID, because onResume currently doesn't give you the correct value when the composable is actually rendered. Not sure how to detect it automatically yet, but we'd need to find a way where to place this code snippet