{"id":13647230,"url":"https://github.com/stayallive/wp-sentry","last_synced_at":"2025-04-13T11:47:13.205Z","repository":{"id":12434721,"uuid":"71796600","full_name":"stayallive/wp-sentry","owner":"stayallive","description":"A (unofficial) WordPress plugin reporting PHP and JavaScript errors to Sentry.","archived":false,"fork":false,"pushed_at":"2024-10-07T12:57:11.000Z","size":4571,"stargazers_count":317,"open_issues_count":4,"forks_count":48,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-10-29T15:48:36.418Z","etag":null,"topics":["sentry","wordpress-plugin"],"latest_commit_sha":null,"homepage":"https://wordpress.org/plugins/wp-sentry-integration/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stayallive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"stayallive"}},"created_at":"2016-10-24T14:19:11.000Z","updated_at":"2024-10-28T20:07:49.000Z","dependencies_parsed_at":"2023-11-13T14:29:31.297Z","dependency_job_id":"7dac2011-2592-48e4-bf19-faf27de69d13","html_url":"https://github.com/stayallive/wp-sentry","commit_stats":{"total_commits":570,"total_committers":26,"mean_commits":"21.923076923076923","dds":0.5368421052631579,"last_synced_commit":"a677dcec38bd4a2cc3829ad1c6ba10aa41cbe74a"},"previous_names":[],"tags_count":151,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stayallive%2Fwp-sentry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stayallive%2Fwp-sentry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stayallive%2Fwp-sentry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stayallive%2Fwp-sentry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stayallive","download_url":"https://codeload.github.com/stayallive/wp-sentry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710409,"owners_count":21149186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sentry","wordpress-plugin"],"created_at":"2024-08-02T01:03:24.839Z","updated_at":"2025-04-13T11:47:13.182Z","avatar_url":"https://github.com/stayallive.png","language":"PHP","funding_links":["https://github.com/sponsors/stayallive"],"categories":["PHP"],"sub_categories":[],"readme":"# [WordPress Sentry](https://wordpress.org/plugins/wp-sentry-integration/) (wp-sentry)\n\nA (unofficial) [WordPress plugin](https://wordpress.org/plugins/wp-sentry-integration/) to report PHP and JavaScript errors to [Sentry](https://sentry.io).\n\n\n## What?\n\nThis plugin can report PHP errors (optionally) and JavaScript errors (optionally) to [Sentry](https://sentry.io) and integrates with its release tracking.\n\nIt will auto detect authenticated users and add context where possible. All context/tags can be adjusted using filters mentioned below.\n\n\n## Requirements\n\nThis plugin requires PHP `7.2`+ but urges users to use a PHP version that is not end of life (EOL) and no longer supported. For an up-to-date list of PHP versions that are still supported see: http://php.net/supported-versions.php.\n\n- Version `2.1.*` of this plugin will be the last to support PHP `5.3`.\n- Version `2.2.*` of this plugin will be the last to support PHP `5.4`.\n- Version `3.11.*` of this plugin will be the last to support PHP `7.1`.\n\n**Note:** Version `5.x` is the most recent version of the wp-sentry plugin and only supports PHP `7.2` and up. If you need PHP `5.4-7.1` support check out version `2.x` or `3.x` but do keep in mind there are a lot of differences in the Sentry PHP SDK used.\n\n- Version [`2.x`](https://github.com/stayallive/wp-sentry/tree/2.x) of the wp-sentry plugin uses the [`1.x`](https://github.com/getsentry/sentry-php/tree/1.x) version of the official Sentry PHP SDK.\n- Version [`3.x`](https://github.com/stayallive/wp-sentry/tree/3.x) of the wp-sentry plugin uses the [`2.x`](https://github.com/getsentry/sentry-php/tree/2.x) version of the official Sentry PHP SDK.\n- Version [`4.x`](https://github.com/stayallive/wp-sentry/tree/4.x), [`5.x`](https://github.com/stayallive/wp-sentry/tree/5.x), \u0026 [`6.x`](https://github.com/stayallive/wp-sentry/tree/6.x) of the wp-sentry plugin uses the [`3.x`](https://github.com/getsentry/sentry-php/tree/3.x) version of the official Sentry PHP SDK.\n- Version [`7.x`](https://github.com/stayallive/wp-sentry/tree/master)+ of the wp-sentry plugin uses the [`4.x`](https://github.com/getsentry/sentry-php/tree/master) version of the official Sentry PHP SDK.\n\n\n## Usage\n\nThere are a couple of options to start using the plugin.\n\n**Note:** This plugin does not do anything by default and only has a diagnostic admin interface to test if you have setup the DSN properly and send test events. Setting up the DSN is required.\n\n### WordPress plugin repository\n\n1. Install this plugin from the WordPress plugin repository: https://wordpress.org/plugins/wp-sentry-integration/\n2. Configure your DSN as explained in the [configuration](#configuration) section\n3. Activate the plugin through the WordPress admin interface or wp-cli\n\n### Manual plugin installation\n\n1. Download the plugin from the [releases page](https://github.com/stayallive/wp-sentry/releases)\n2. Extract it and place the folder in your `wp-content/plugins` folder\n3. Configure your DSN as explained in the [configuration](#configuration) section\n4. Activate the plugin through the WordPress admin interface or wp-cli\n\n### Using composer\n\n1. Run `composer require stayallive/wp-sentry` in your project\n2. Configure your DSN as explained in the [configuration](#configuration) section\n3. Activate the plugin through the WordPress admin interface or wp-cli\n\n\n## Configuration\n\nTo start using the plugin first setup the [DSN](#dsn) for either the PHP side or the Browser side or both.\n\nAll other configuration options are optional but it's advised you read through them to see if any are applicable to you or are thing you'd like to configure.\n\n**Note:** When configuring constants in your `wp-config.php` do this **before** the `That's all, stop editing! Happy publishing.` line, otherwise they won't work!\n\n### DSN\n\nSentry uses something called a DSN ([read more](https://docs.sentry.io/product/sentry-basics/dsn-explainer/)) to configure the SDK.\n\n#### `WP_SENTRY_PHP_DSN` (PHP)\n\nTo track PHP errors add this snippet to your `wp-config.php` and replace `PHP_DSN` with your actual DSN that you find inside Sentry in the project settings under \"Client Keys (DSN)\":\n\n```php\ndefine( 'WP_SENTRY_PHP_DSN', 'PHP_DSN' );\n```\n\n**Note:** Do not set this constant to disable the PHP tracker.\n\n**Note:** This constant was previously called `WP_SENTRY_DSN` and is still supported.\n\n#### `WP_SENTRY_BROWSER_DSN` (Browser)\n\nTo track JavaScript errors add this snippet to your `wp-config.php` and replace `JS_DSN` with your actual DSN that you find inside Sentry in the project settings under \"Client Keys (DSN)\":\n\n```php\ndefine( 'WP_SENTRY_BROWSER_DSN', 'JS_DSN' );\n\n// You can _optionally_ enable or disable the JavaScript tracker in certain parts of your site with these constants:\ndefine('WP_SENTRY_BROWSER_ADMIN_ENABLED', true);    // Add the JavaScript tracker to the admin area. Default: true\ndefine('WP_SENTRY_BROWSER_LOGIN_ENABLED', true);    // Add the JavaScript tracker to the login page. Default: true\ndefine('WP_SENTRY_BROWSER_FRONTEND_ENABLED', true); // Add the JavaScript tracker to the front end. Default: true\n```\n\n**Note:** Do not set this constant to disable the JavaScript tracker.\n\n**Note:** This constant was previously called `WP_SENTRY_PUBLIC_DSN` and is still supported.\n\n### Privacy\n\n#### `WP_SENTRY_SEND_DEFAULT_PII`\n\nIf this flag is enabled, certain personally identifiable information is added by active integrations. Without this flag they are never added to the event, to begin with.\n\nIf possible, it’s recommended to turn on this feature and use the server side PII stripping to remove the values instead.\n\nWhen enabled the current logged in user and IP address will be added to the event.\n\n```php\ndefine( 'WP_SENTRY_SEND_DEFAULT_PII', true );\n```\n\n### Options\n\n#### `WP_SENTRY_VERSION`\n\nDefine a version of your site. By default the active theme version will be used or `unspecified` if theme version could not be resolved.\n\nThis is used for tracking at which version of your site the error occurred. When combined with release tracking this is a very powerful feature.\n\n```php\ndefine( 'WP_SENTRY_VERSION', 'v8.3.1' );\n```\n\n#### `WP_SENTRY_ENV`\n\nDefine an environment of your site. Defaults to the WordPress environment type from `wp_get_environment_type()` or `unspecified` if none configured.\n\nThis is used for tracking on which environment of your site the error occurred.\n\n```php\ndefine( 'WP_SENTRY_ENV', 'production' );\n```\n\n#### `WP_SENTRY_ERROR_TYPES` (PHP)\n\nSet the error types the PHP tracker will track:\n\n```php\ndefine( 'WP_SENTRY_ERROR_TYPES', E_ALL \u0026 ~E_DEPRECATED \u0026 ~E_NOTICE \u0026 ~E_USER_DEPRECATED \u0026 ~E_USER_NOTICE );\n```\n\n**Note**: You can set any combination of error types you want, see the [PHP documentation](https://www.php.net/manual/en/errorfunc.constants.php) for more information.\n\n### Set Up Tracing\n\n#### `WP_SENTRY_TRACES_SAMPLE_RATE` (PHP)\n\nSet the desired sampling rate for performane tracing. Replace `0.3` with your desired sampling rate (`0.3` means sample ~30% of your traffic):\n\n```php\n// https://docs.sentry.io/platforms/php/performance/#configure\ndefine( 'WP_SENTRY_TRACES_SAMPLE_RATE', 0.3 ); // traces_sample_rate\n```\n\nEnabling tracing will also set `SAVEQUERIES`, this can use more memory to save all the executed queries in your environment. If this is not desirable you can disable query tracing by configuring `WP_SENTRY_TRACING_FEATURES`.\n\n**Note:** Do not set this constant or set the sample rate to `0.0` to disable the performance monitoring.\n\n#### `WP_SENTRY_TRACING_FEATURES` (PHP)\n\nEnable performance monitoring features by adding this snippet to your `wp-config.php`:\n\n```php\ndefine( 'WP_SENTRY_TRACING_FEATURES', [\n\t'db' =\u003e [\n\t\t'spans' =\u003e true,\n\t\t'breadcrumbs' =\u003e defined( 'SAVEQUERIES' ) \u0026\u0026 SAVEQUERIES,\n\t],\n\t'http' =\u003e [\n\t\t'spans' =\u003e true,\n\t\t'breadcrumbs' =\u003e true,\n\t],\n\t'transients' =\u003e [\n\t\t'spans' =\u003e true,\n\t\t'breadcrumbs' =\u003e true,\n\t],\n] );\n```\n\n**Note:** Not configuring this constant will default to the above configuration.\n\n#### `WP_SENTRY_BROWSER_TRACES_SAMPLE_RATE` (Browser)\n\nEnable JavaScript performance tracing by adding this snippet to your `wp-config.php` and replace `0.3` with your desired sampling rate (`0.3` means sample ~30% of your traffic):\n\n```php\n// https://docs.sentry.io/platforms/javascript/performance/#configure-the-sample-rate\ndefine( 'WP_SENTRY_BROWSER_TRACES_SAMPLE_RATE', 0.3 ); // tracesSampleRate\n\n// These options are passed directly to `new BrowserTracing({})`\n// define( 'WP_SENTRY_BROWSER_TRACING_OPTIONS', [] );\n```\n\n**Note:** Do not set this constant or set the sample rate to `0.0` to disable the JavaScript performance tracing.\n\n#### `WP_SENTRY_BROWSER_REPLAYS_SESSION_SAMPLE_RATE` (Browser)\n\nEnable JavaScript Session Replay by adding this snippet to your `wp-config.php` and replace `0.3` with your desired sampling rate (`0.3` means sample ~30% of your traffic):\n\n```php\n// These options are injected into the `Sentry.init()` call\n// https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration\ndefine( 'WP_SENTRY_BROWSER_REPLAYS_SESSION_SAMPLE_RATE', 0.1 ); // replaysSessionSampleRate\ndefine( 'WP_SENTRY_BROWSER_REPLAYS_ON_ERROR_SAMPLE_RATE', 1.0 ); // replaysOnErrorSampleRate\n\n// These options are passed directly to `new Replay({})`\n// - https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration\n// - https://docs.sentry.io/platforms/javascript/session-replay/privacy/#privacy-configuration\n// define( 'WP_SENTRY_BROWSER_SESSION_REPLAY_OPTIONS', [ 'maskAllText' =\u003e true ] );\n```\n\n**Note:** Do not set these constants or set the sample rates to `0.0` to disable the JavaScript Session Replay.\n\n### Set Up Profiling\n\n#### `WP_SENTRY_PROFILES_SAMPLE_RATE` (PHP)\n\n**Note:** This feature requires the Excimer PHP extension to be installed. See the [Sentry PHP SDK documentation](https://docs.sentry.io/platforms/php/profiling/#configure) for more information.\n\nSentry's tracing has to be enabled in order for profiling to work. So you also need to configure `WP_SENTRY_TRACES_SAMPLE_RATE` to enable profiling.\n\nSet the desired sampling rate for profiling. Replace `0.3` with your desired sampling rate (`0.3` means sample ~30% of your traffic):\n\n```php\ndefine( 'WP_SENTRY_TRACES_SAMPLE_RATE', 0.3 ); // traces_sample_rate\n// https://docs.sentry.io/platforms/php/profiling/#configure\ndefine( 'WP_SENTRY_PROFILES_SAMPLE_RATE', 0.3 ); // profiles_sample_rate\n```\n\n**Note:** Do not set this constant or set the sample rate to `0.0` to disable the performance monitoring.\n\n### Set Up User Feedback\n\n#### `WP_SENTRY_BROWSER_FEEDBACK_OPTIONS` (Browser)\n\nYou can enable the User Feedback Widget ([official documentation](https://docs.sentry.io/platforms/javascript/user-feedback/#user-feedback-widget)) by adding this snippet to your `wp-config.php`:\n\n```php\ndefine( 'WP_SENTRY_BROWSER_FEEDBACK_OPTIONS', [ 'enabled' =\u003e true ] );\n```\n\nAll option are passed directly to `feedbackIntegration()`, you can read about all the available options in the [official documentation](https://docs.sentry.io/platforms/javascript/user-feedback/configuration/#user-feedback-widget).\n\n## Filters\n\nThis plugin provides the following filters to plugin/theme developers.\n\n**Note:** Some filters are fired when the Sentry trackers are initialised so they won't fire if you define them in your theme or in a plugin that loads after WP Sentry does.\n\n### Common to PHP \u0026 Browser\n\n#### `wp_sentry_user_context` (array)\n\nYou can use this filter to extend the Sentry user context for both PHP and JS trackers.\n\n\u003e **WARNING:** These values are exposed to the public in the JS tracker, so make sure you do not expose anything private!\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_user_context', function ( array $user ) {\n\treturn array_merge( $user, array(\n\t\t'a-custom-user-meta-key' =\u003e 'custom value',\n\t));\n} );\n```\n\n**Note:** _This filter fires on the WordPress `set_current_user` action and only if the `WP_SENTRY_SEND_DEFAULT_PII` constant is set to `true`._\n\n### Specific to PHP\n\n#### `wp_sentry_dsn` (string)\n\nYou can use this filter to override the Sentry DSN used for the PHP tracker.\n\n\u003e **WARNING:** This is not recommended, please set the DSN using the `WP_SENTRY_PHP_DSN` constant in your `wp-config.php`!\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_dsn', function ( $dsn ) {\n\treturn 'https://\u003ckey\u003e:\u003csecret\u003e@sentry.io/\u003cproject\u003e';\n} );\n```\n\n**Note:** _This filter fires on the WordPress `after_setup_theme` action. It is discouraged to use this and instead define the DSN in the `wp-config.php` using the `WP_SENTRY_PHP_DSN` constant_\n\n---\n\n#### `wp_sentry_scope` (void)\n\nYou can use this filter to customize the Sentry [scope](https://docs.sentry.io/platforms/php/enriching-events/context/).\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_scope', function ( \\Sentry\\State\\Scope $scope ) {\n\t$scope-\u003esetTag('my-custom-tag', 'tag-value');\n\n\treturn $scope;\n} );\n```\n\n**Note:** _This filter fires on the WordPress `after_setup_theme` action._\n\n---\n\n#### `wp_sentry_options`\n\nYou can use this filter to customize the Sentry [options](https://docs.sentry.io/platforms/php/configuration/options/).\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_options', function ( \\Sentry\\Options $options ) {\n\t// Only sample 90% of the events\n\t$options-\u003esetSampleRate(0.9);\n\n\treturn $options;\n} );\n```\n\n**Note:** _This filter fires on the WordPress `after_setup_theme` action._\n\n---\n\n#### `wp_sentry_before_send`\n\nYou can use this filter to filter error events sent to Sentry. Read more about [filtering in the docs](https://docs.sentry.io/platforms/php/configuration/filtering/#filtering-error-events).\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_before_send', function ( \\Sentry\\Event $event, ?\\Sentry\\EventHint $hint = null ) {\n    // Don't send error event with level `warning` for the Hello Dolly example plugin\n    if ( $hint-\u003eexception !== null \u0026\u0026 $event-\u003egetLevel() === \\Sentry\\Severity::warning() \u0026\u0026 strpos( $hint-\u003eexception-\u003egetFile(), 'plugins/hello.php' ) !== false ) {\n        return null;\n    }\n    \n    return $event;\n}, 2 );\n```\n\n**Note:** _Do not forget to return the `$event` if you want to send it to Sentry, returning `null` discards the event._\n\n### Specific to Browser\n\n#### `wp_sentry_public_dsn` (string)\n\nYou can use this filter to override the Sentry DSN used for the JS tracker.\n\n\u003e **WARNING:** This is not recommended, please set the DSN using the `WP_SENTRY_BROWSER_DSN` constant in your `wp-config.php`!\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_public_dsn', function ( $dsn ) {\n\treturn 'https://\u003ckey\u003e@sentry.io/\u003cproject\u003e';\n} );\n```\n\n#### `wp_sentry_public_options` (array)\n\nYou can use this filter to customize/override the Sentry [options](https://docs.sentry.io/platforms/javascript/configuration/options/) used to initialize the JS tracker.\n\n\u003e **WARNING:** These values are exposed to the public, so make sure you do not expose anything private !\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_public_options', function ( array $options ) {\n\treturn array_merge( $options, array(\n\t\t'sampleRate' =\u003e '0.5',\n\t\t'denyUrls' =\u003e array(\n\t\t\t'https://github.com/',\n\t\t\t'regex:\\\\w+\\\\.example\\\\.com',\n\t\t),\n\t));\n} );\n```\n\n**Note:** _Items prefixed with `regex:` in `denyUrls`, `allowUrls` and `ignoreErrors` option arrays will be translated into pure RegExp._\n\n#### `wp_sentry_public_context` (array)\n\nYou can use this filter to customize/override the Sentry context, you can modify the `user` and `tags` context.\n\n\u003e **WARNING:** These values are exposed to the public, so make sure you do not expose anything private !\n\nExample usage:\n\n```php\nadd_filter( 'wp_sentry_public_context', function ( array $context ) {\n\t$context['tags']['my-custom-tag'] = 'tag-value';\n\n\treturn $context;\n} );\n```\n\n\n## Advanced usages\n\n### High volume of notices\n\nMany plugin in the WordPress ecosystem generate notices that are captured by the Sentry plugin.\n\nThis can cause a high volume of events and even slower page loads because of those events being transmitted to Sentry.\n\nThe prevent this you can set the following in your `wp-config.php` to filter out errors of the notice type.\n\n```php\ndefine( 'WP_SENTRY_ERROR_TYPES', E_ALL \u0026 ~E_NOTICE \u0026 ~E_USER_NOTICE );\n```\n\n**Note**: You can set any combination of error types you want, see the [PHP documentation](https://www.php.net/manual/en/errorfunc.constants.php) for more information.\n\n### Capturing handled exceptions\n\nThe best thing to do with an exception is to capture and handle it, however you might still want to know an exception happened.\n\nThe Sentry plugin only captures unhandled exceptions and fatal errors, to capture handled exception you can do the following:\n\n```php\ntry {\n\tmyMethodThatCanThrowAnException();\n} catch ( \\Throwable $e ) {\n    // Option #1: Use the `captureException` or `captureMessage` action\n    // It's safe to call these actions even if the plugin is disabled (it will simply do nothing)\n    do_action( 'sentry/captureException', $e );\n    do_action( 'sentry/captureMessage', $e-\u003egetMessage() ); // it is recommended to use `captureException`\n\n    // Option #2: Use the `wp_sentry_safe` function to interact with the Sentry SDK directly\n\t// It's advised to wrap this in a function_exists check to prevent errors when the plugin is disabled\n\tif ( function_exists( 'wp_sentry_safe' ) ) {\n\t\twp_sentry_safe( function ( \\Sentry\\State\\HubInterface $client ) use ( $e ) {\n\t\t\t$client-\u003ecaptureException( $e );\n\t\t} );\n\t}\n\n\twp_die( 'There was an error doing this thing you were doing, we have been notified!' );\n}\n```\n\nIf you need to attach extra data only for the handled exception, you could add [Structured Context](https://docs.sentry.io/platforms/php/enriching-events/context/#structured-context):\n\n```php\n$e = new Exception('Some exception I want to capture with extra data.');\n\nif (function_exists('wp_sentry_safe')) {\n\twp_sentry_safe(function (\\Sentry\\State\\HubInterface $client) use ($e) {\n\t\t$client-\u003ewithScope(function (\\Sentry\\State\\Scope $scope) use ($client, $e) {\n\t\t\t$scope-\u003esetContext('user_data', $e-\u003egetData());\n\t\t\t$client-\u003ecaptureException($e);\n\t\t});\n\t});\n}\n```\n\nIf you need to add data to the scope in every case use `configureScope` in [wp_sentry_scope filter](#wp_sentry_scope-void).\n\n### Loading Sentry before WordPress\n\nSince WP Sentry is a WordPress plugin it loads after WordPress and unless you are using a must-use plugin (see [Capturing plugin errors](#capturing-plugin-errors)) even after some other plugins loaded throwing errors which are not captured by Sentry.\n\nTo remedy this you can opt to load the plugin from your `wp-config.php` file before WordPress is started.\n\nIt's really simple to do this by adding the following snippet to your `wp-config.php` before the `/* That's all, stop editing! Happy blogging. */` comment:\n\n```php\n// It's possible your WordPress installation is different, check to make sure this path is correct for your installation\nrequire_once __DIR__ . '/wp-content/plugins/wp-sentry-integration/wp-sentry.php';\n```\n\nAlso make sure that any configuration options like `WP_SENTRY_PHP_DSN` are set before the snippet above otherwise they have no effect.\n\n### Capturing plugin errors\n\nSince this plugin is called `wp-sentry-integration` it loads a bit late which could miss errors or notices occuring in plugins that load before it.\n\nYou can remedy this by loading WordPress Sentry as a must-use plugin by creating the file `wp-content/mu-plugins/wp-sentry-integration.php` (if the `mu-plugins` directory does not exist you must create that too).\n\n```php\n\u003c?php\n\n/**\n * Plugin Name: WordPress Sentry\n * Plugin URI: https://github.com/stayallive/wp-sentry\n * Description: A (unofficial) WordPress plugin to report PHP and JavaScript errors to Sentry.\n * Version: must-use-proxy\n * Author: Alex Bouma\n * Author URI: https://alex.bouma.dev\n * License: MIT\n */\n\n$wp_sentry = WP_CONTENT_DIR . '/plugins/wp-sentry-integration/wp-sentry.php';\n\n// Do not crash in case the plugin is not installed\nif ( ! file_exists( $wp_sentry ) ) {\n\treturn;\n}\n\nrequire $wp_sentry;\n```\n\nNow `wp-sentry-integration` will load always and before all other plugins.\n\n**Note**: It is advised you leave the original `wp-sentry-integration` in the `/wp-content/plugins` folder to still have updates come in through the WordPress updater. However enabling or disabling does nothing if the above script is active (since it will always be enabled).\n\n### Capturing errors only from certain theme and/or plugin\n\nThis is an example on how to use the `before_send` callback of the Sentry SDK to only capture errors occuring in a certain theme or plugin.\n\nSee also the filter docs: [wp_sentry_option](#wp_sentry_options).\n\n```php\nadd_filter( 'wp_sentry_options', function ( \\Sentry\\Options $options ) {\n\t$options-\u003esetBeforeSendCallback( function ( \\Sentry\\Event $event ) {\n\t\t$exceptions = $event-\u003egetExceptions();\n\n\t\t// No exceptions in the event? Send the event to Sentry, it's most likely a log message\n\t\tif ( empty( $exceptions ) ) {\n\t\t\treturn $event;\n\t\t}\n\n\t\t$stacktrace = $exceptions[0]-\u003egetStacktrace();\n\n\t\t// No stacktrace in the first exception? Send it to Sentry just to be safe then\n\t\tif ( $stacktrace === null ) {\n\t\t\treturn $event;\n\t\t}\n\n\t\t// Little helper and fallback for PHP versions without the str_contains function\n\t\t$strContainsHelper = function ( $haystack, $needle ) {\n\t\t\tif ( function_exists( 'str_contains' ) ) {\n\t\t\t\treturn str_contains( $haystack, $needle );\n\t\t\t}\n\n\t\t\treturn $needle !== '' \u0026\u0026 mb_strpos( $haystack, $needle ) !== false;\n\t\t};\n\n\t\tforeach ( $stacktrace-\u003egetFrames() as $frame ) {\n\t\t\t// Check the the frame happened inside our theme or plugin\n\t\t\t// Change THEME_NAME and PLUGIN_NAME to whatever is required\n\t\t\t// And / or modify this `if` statement to detect other variables\n\t\t\tif ( $strContainsHelper( $frame-\u003egetFile(), 'themes/THEME_NAME' )\n\t\t\t\t || $strContainsHelper( $frame-\u003egetFile(), 'plugins/PLUGIN_NAME' )\n\t\t\t) {\n\t\t\t\t// Send the event to Sentry\n\t\t\t\treturn $event;\n\t\t\t}\n\t\t}\n\n\t\t// Stacktrace contained no frames in our theme and/or plugin? We send nothing to Sentry\n\t\treturn null;\n\t} );\n\n\treturn $options;\n} );\n```\n\n### Client side hook\n\nWhen using the Sentry Browser integration it is possible to do some work in the client browser before Sentry is initialized to change options and/or prevent the Browser SDK from initializing at all.\n\nYou do this by defining a `wp_sentry_hook` JavaScript function before the Sentry Browser JavaScript file is included (keep this function small and easy since any errors that occur in there are not tracked by the Browser SDK).\n\nA quick example on how you would disable the Browser SDK using `wp_add_inline_script`:\n\n```php\nadd_action( 'wp_enqueue_scripts', function () {\n\twp_add_inline_script( 'wp-sentry-browser', 'function wp_sentry_hook(options) { return someCheckInYourCode() ? true : false; }', 'before' );\n} );\n```\n\nWhen the `wp_sentry_hook` function returns `false` the initialization of the Sentry Brower SDK will be stopped. Any other return value will be ignored.\n\nTo modify the options you can modify the object passed as the first argument of the `wp_sentry_hook`, this object will later be passed to `Sentry.init` to initialize the Browser SDK.\n\n### Modifying the PHP SDK `ClientBuilder` or options before initialisation\n\nBecause the PHP SDK is initialized as quick as possible to capture early errors, it's impossible to modify the options or the `ClientBuilder` before the initialization with WordPress hooks.\n\nThere exists a way to modify the options and the `ClientBuilder` before the initialization of the PHP SDK by setting a callback using a constant called `WP_SENTRY_CLIENTBUILDER_CALLBACK`.\n\nThe callback will be executed whenever the plugin creates a new `ClientBuilder` instance to create a new PHP SDK client.\n\nYou would place the example below in your `wp-config.php` file to make sure it's available before the PHP SDK is initialized:\n\n```php\nfunction wp_sentry_clientbuilder_callback( \\Sentry\\ClientBuilder $builder ): void {\n    // For example, disabling the default integrations\n\t$builder-\u003egetOptions()-\u003esetDefaultIntegrations( false );\n}\n\ndefine( 'WP_SENTRY_CLIENTBUILDER_CALLBACK', 'wp_sentry_clientbuilder_callback' );\n```\n\n### HTTP proxy\n\nIf you need to use a HTTP proxy to send events to Sentry you can setup the WordPress HTTP proxy support and this plugin will transfer those settings to the Sentry SDK.\n\nRead more about how to setup the WordPress Proxy constants here: https://developer.wordpress.org/reference/classes/wp_http_proxy/#description.\n\nThere is one caveat, if you are using an HTTP proxy in WordPress but don't want Sentry to use it you should set `WP_SENTRY_PROXY_ENABLED` to `false` in your `wp-config.php`. Setting `WP_PROXY_BYPASS_HOSTS` will not work!\n\n\n## Security Vulnerabilities\n\nIf you discover a security vulnerability within WordPress Sentry (wp-sentry), please send an e-mail to Alex Bouma at `alex+security@bouma.me`. All security vulnerabilities will be swiftly addressed.\n\n\n## License\n\nThe WordPress Sentry (wp-sentry) plugin is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstayallive%2Fwp-sentry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstayallive%2Fwp-sentry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstayallive%2Fwp-sentry/lists"}