Surpressing issues from going to Sentry
-
I would like to block a few events from going to Sentry using the
before_send
callback, however the events kept on showing on Sentry. I have followed the approach on this topic, but seems it still doesn’t work. Here are the code snippet on my wp-sentry.php to block the issues, could someone point out the mistake?add_filter( 'wp_sentry_options', function ( \Sentry\Options $options ) { $options->setBeforeSendCallback( function ( \Sentry\Event $event ) { $exceptions = $event->getExceptions(); // Little helper and fallback for PHP versions without the str_contains function $strContainsHelper = function ( $haystack, $needle ) { if ( function_exists( 'str_contains' ) ) { return str_contains( $haystack, $needle ); } return $needle !== '' && mb_strpos( $haystack, $needle ) !== false; }; // No exceptions in the event? Send the event to Sentry, it's most likely a log message if ( empty( $exceptions ) ) { return $event; } if ( $strContainsHelper( $exceptions[0]->getType(), 'UnhandledRejection') && $strContainsHelper( $exceptions[0]->getValue(), 'Non-Error promise rejection captured with value: ')) { return null; } $stacktrace = $exceptions[0]->getStacktrace(); // No stacktrace in the first exception? Send it to Sentry just to be safe then if ( $stacktrace === null ) { return $event; } foreach ( $stacktrace->getFrames() as $frame ) { // Check the the frame happened inside our theme or plugin // Change THEME_NAME and PLUGIN_NAME to whatever is required // And / or modify this
if
statement to detect other variables if ( $strContainsHelper( $frame->getAbsoluteFilePath(), 'utils/build/esm/supports' ) ) { return null; } if ( $strContainsHelper( $frame->getAbsoluteFilePath(), 'addthis_widget' ) ) { return null; } if ( $strContainsHelper( $frame->getAbsoluteFilePath(), 'plugins/addthis') ) { return null; } } // Stacktrace contained no frames in our theme and/or plugin? We send nothing to Sentry return null; } ); return $options; } );The stacktrace shows that system>exception>stack-trace>frame>module contains
'utils/build/esm/supports'
and'addthis_widget'
for the two issues I’m trying to filter out.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Surpressing issues from going to Sentry’ is closed to new replies.