Search code examples
react-nativesentryreact-native-sentry

How to exclude App Cold Start from duration in Sentry


I have React Native app with Sentry integrated. I use Performance from Sentry with automatic instrumentation in order to measure screen load times within react-navigation library). Is there any way to exclude app.start.cold span from p50 or p95 calculation on the transactions list? I am only interested in the time of navigation operation, but p95 shows duration in seconds starting from App Cold Start (i.e 15.60s for first transaction on the list) which is not meaningful for me. Is there any way to change it and show duration just for navigation span?

Transactions summary

Transaction details


Solution

  • if you don't want to see the app.start.* spans you can disable the App Start tracking in the SDK.

    Sentry.init({
      dsn: __YOUR_DSN__,
      integrations: [
        new Sentry.ReactNativeTracing({
          enableAppStartTracking: false,
          // ... other options
        }),
      ],
      // ...
    });
    

    Or you can keep the app starts tracking and remove the spans in the beforeSendTransaction callback, this way you will still have the information about the app start in the measurements.

    Note that this might lead to inaccurate data, as the transaction is trimmed to the start of the first span after the app start.

      beforeSendTransaction(event, hint) {
        let spanIndexToDelete = null;
        let newTransactionStart: number | null = null;
        event.spans?.forEach((span, index) => {
          if (span.op?.startsWith('app.start')) {
            spanIndexToDelete = index;
          } else {
            if (newTransactionStart === null) {
              newTransactionStart = span.startTimestamp;
            } else if (newTransactionStart > span.startTimestamp) {
              newTransactionStart = span.startTimestamp;
            }
          }
        });
        if (newTransactionStart) {
          event.start_timestamp = newTransactionStart;
        }
        spanIndexToDelete && event.spans?.splice(spanIndexToDelete, 1);
        return event;
      },
    

    More about the callback https://docs.sentry.io/platforms/react-native/configuration/options/#before-send-transaction