getsentry / sentry-cocoa

The official Sentry SDK for iOS, tvOS, macOS, watchOS.
https://sentry.io/for/cocoa/
MIT License
780 stars 311 forks source link

Add `setBeforeViewHierarchyCaptureCallback` to Cocoa SDK #4004

Open narlei opened 1 month ago

narlei commented 1 month ago

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

philipphofmann commented 1 month ago

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