sentry-react-native: Duplicate Breadcrumbs

Environment

How do you use Sentry? sentry.io

Which SDK and version?

Steps to Reproduce

const dsn = Config.SENTRY_DSN;
const debug = false;
const release = `${DeviceInfo.getBundleId()}@${versionName}@${versionCode}+codepush:${codepushDist}`;
const dist = `${versionName}.${codepushDist}`;
const environment = isProductionEnv ? 'production' : 'staging';
const sampleRate = debug ? 1 : 0.5;
const tracesSampleRate = 0.2;
const maxBreadcrumbs = 150; 

    Sentry.init({
        dsn,
        debug,
        release,
        dist,
        environment,
        sampleRate,
        tracesSampleRate,
        maxBreadcrumbs,
    });

Set those initialization and surfing on my app normally until I get some errors.

Expected Result

breadcrumb data is not logged twice.

Actual Result

Looking at Breadcrumb section, I found that each breadcrumb data logged twice. xhr breadcrumb is logged by default by Sentry SDK. btn_clicked and navigate is manually logged, I mean, my code that logged it. Both of them logged twice.

image

this is how I add a breadcrumb.

export function recordBreadcrumb(key, message, level = Sentry.Severity.Info) {
    Sentry.addBreadcrumb({
        category: key,
        message,
        level,
    });
}
...
function logButtonClicked(buttonOrFunctionName, value = {}){
   ...
   CrashLoggingUtils.recordBreadcrumb('btn_clicked', buttonOrFunctionName);
}

I’ve ensured that logButtonClicked() only called once a time.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 22 (11 by maintainers)

Most upvoted comments

https://github.com/getsentry/sentry-react-native/blob/a085ec4ef6e9506cca568d8841e1e1bc8dfb63a2/src/js/wrapper.ts#L108-L110 Messages get duplicated breadcrumbs because it doesn’t have an exception so the above condition gets skipped. Perhaps we should also delete all the breadcrumbs if there isnt an exception or the exception was handled, or

 if (event.exception?.values?.[0]?.mechanism?.handled != false) { 
   event.breadcrumbs = []; 
 } 

Found the same problem on Android Platform.

The next line fix it.

Sentry.init({
      beforeSend: event => {
        if (event.breadcrumbs && Platform.OS === 'android') {
          delete event.breadcrumbs
        }
        return event
      },

Maybe the reason is:

package io.sentry

// line 491
  private void sortBreadcrumbsByDate(
      final @NotNull SentryEvent event, final @NotNull Collection<Breadcrumb> breadcrumbs) {
    final List<Breadcrumb> sortedBreadcrumbs = event.getBreadcrumbs();

    if (!breadcrumbs.isEmpty()) {
      sortedBreadcrumbs.addAll(breadcrumbs);
      Collections.sort(sortedBreadcrumbs, sortBreadcrumbsByDate);
    }
  }

The sortedBreadcrumbs come from:

// package io.sentry.react;
@ReactMethod
public void captureEnvelope(String envelope, Promise promise) {

}

And the breadcrumbs come from:

// package io.sentry.react;
@ReactMethod
public void addBreadcrumb(final ReadableMap breadcrumb) {

}

could be, breadcrumbs are merged so it’s likely this