首页 > 解决方案 > Sentry Android:忽略不包含我的包的堆栈跟踪

问题描述

我在一个供其他开发人员使用的 Android 库中使用 Sentry。我从使用我的库的应用程序中得到了很多异常,但这些异常与库无关,并且真的很想忽略这些。有什么方法可以过滤异常,所以我只报告那些在堆栈跟踪中某处有我的库包的异常吗?

标签: javaandroidsentry

解决方案


您可以使用ShouldSendEventCallback

public static void example() {
    SentryClient client = Sentry.getStoredClient();

    client.addShouldSendEventCallback(new ShouldSendEventCallback() {
        @Override
        public boolean shouldSend(Event event) {
            // decide whether to send the event

            for (Map.Entry<String, SentryInterface> interfaceEntry : event.getSentryInterfaces().entrySet()) {
                if (interfaceEntry.getValue() instanceof ExceptionInterface) {
                    ExceptionInterface i = (ExceptionInterface) interfaceEntry.getValue();
                    for (SentryException sentryException : i.getExceptions()) {
                        // this example checks the exception class
                        if (sentryException.getExceptionClassName().equals("foo")) {
                            // don't send the event
                            return false;
                        }
                    }
                }
            }

            // send event
            return true;
        }
    });
}

有一张票可以让这更容易:https ://github.com/getsentry/sentry-java/issues/575


推荐阅读