sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Add `setBeforeViewHierarchyCaptureCallback` to Cocoa SDK

Open narlei opened this issue 1 year ago • 1 comments

Problem Statement

If we enable the attachViewHierarchy option, we're sending too much attachments, including events that I don't want to get ViewHierarchy, like HTTP request erros.

Solution Brainstorm

The Android SDK contains an interceptor: https://docs.sentry.io/platforms/android/enriching-events/viewhierarchy/#customize-view-hierarchy-capturing

SentryAndroid.init(this, options -> {
    options.setBeforeViewHierarchyCaptureCallback((event, hint, debounce) -> {
        // always capture crashed events
        if (event.isCrashed()) {
            return true;
        }

        // if debounce is active, skip capturing
        if (debounce) {
            return false;
        } else {
            // also capture fatal events
            return event.getLevel() == SentryLevel.FATAL;
        }
    });
});

It allows to customize the ViewHierarchy and send when we want. Another option is allowing to get the event attachments on beforeSend.

Are you willing to submit a PR?

No response

narlei avatar May 22 '24 13:05 narlei

Yes, that makes sense. Thanks for opening the issue, @narlei. This is related to https://github.com/getsentry/sentry-cocoa/issues/3007.

philipphofmann avatar May 22 '24 14:05 philipphofmann