Skip to content

Commit

Permalink
Add exclusions to abort sentry sending
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHolbrook authored Jan 3, 2019
1 parent 085578d commit e12986c
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
class ErrorHandling {
private static $client;

public static $exclusions = [
'Parameter 1 to wp_default_scripts() expected to be a reference, value given',
'Parameter 1 to wp_default_styles() expected to be a reference, value given',
];

static function init() {
$sentry_url = get_env_value( 'SENTRY_URL' );

Expand All @@ -16,28 +21,40 @@ static function init() {
return self::$client;
}

self::$client = new \Raven_Client( $sentry_url );
$exclusions = self::$exclusions;

$options = [
'send_callback' => function ( $data ) use ( $exclusions ) {

if ( 'error' === $data['level'] ) {
return $data;
}

$value = $data['exception']['values'][0]['value'] ?? null;

if ( empty( $value ) ) {
return $data;
}

if ( in_array( $value, $exclusions ) ) {
return false;
}

return $data;
},
];

self::$client = new \Raven_Client( $sentry_url, $options );
self::$client->install();

return self::$client;
}

/**
* @return \Raven_Client
*/
static function get_client() {
if ( empty( self::$client ) ) {
self::init();
}

return self::$client;
}

static function capture( $exception ) {
if ( empty( self::$client ) ) {
return;
}

self::$client->captureException( $exception );
}
}

0 comments on commit e12986c

Please sign in to comment.