Skip to content

Commit

Permalink
Set Sentry sample rate to 1 for admin and preview screens.
Browse files Browse the repository at this point in the history
  • Loading branch information
EarthlingDavey committed Oct 24, 2024
1 parent 24cb897 commit c05690a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions public/app/themes/clarity/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
require_once 'inc/admin/plugins/wp-elasticsearch.php';
require_once 'inc/admin/plugins/wp-document-revisions.php';
require_once 'inc/admin/plugins/wp-offload-media.php';
require_once 'inc/admin/plugins/wp-sentry.php';
require_once 'inc/admin/prior-party/prior-party-banner-admin.php';
require_once 'inc/admin/prior-party/prior-party-banner-email.php';
require_once 'inc/admin/prior-party/prior-party-banner.php';
Expand Down
57 changes: 57 additions & 0 deletions public/app/themes/clarity/inc/admin/plugins/wp-sentry.php
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();

0 comments on commit c05690a

Please sign in to comment.