-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set Sentry sample rate to 1 for admin and preview screens.
- Loading branch information
1 parent
24cb897
commit c05690a
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* Modifications to adapt the wp-sentry plugin. | ||
* | ||
* @package Clarity | ||
*/ | ||
|
||
namespace MOJ\Intranet; | ||
|
||
if (!defined('ABSPATH')) { | ||
die(); | ||
} | ||
|
||
class WpSentry | ||
{ | ||
|
||
public function __construct() | ||
{ | ||
$this->addHooks(); | ||
} | ||
|
||
public function addHooks() | ||
{ | ||
add_filter('wp_sentry_public_options', [$this, 'filterSentryJsOptions']); | ||
error_log('added wp_sentry_public_options hook'); | ||
} | ||
|
||
/** | ||
* Filter the options used by sentry-javascript for `Sentry.init()` | ||
*/ | ||
|
||
public function filterSentryJsOptions(array $options) | ||
{ | ||
// If we're not on an admin or preview screen, then return early. | ||
if (!(is_admin() || is_preview())) { | ||
return $options; | ||
} | ||
|
||
// We are either on an admin screen or a preview screen. | ||
// Add custom settings for admin screens. | ||
return array_merge($options, array( | ||
'sendDefaultPii' => true, | ||
'sampleRate' => 1, | ||
'tracesSampleRate' => 1, | ||
'replaysSessionSampleRate' => 1, | ||
'replaysOnErrorSampleRate' => 1, | ||
'wpSessionReplayOptions' => [ | ||
// To capture additional information such as request and response headers or bodies, | ||
// you'll need to opt-in via networkDetailAllowUrls | ||
'networkDetailAllowUrls' => [get_home_url()], | ||
] | ||
)); | ||
} | ||
} | ||
|
||
new WpSentry(); |