{"id":15065467,"url":"https://github.com/itgalaxy/sentry-integration","last_synced_at":"2025-08-20T22:39:19.728Z","repository":{"id":26870422,"uuid":"111432558","full_name":"itgalaxy/sentry-integration","owner":"itgalaxy","description":"WordPress Sentry Integration Plugin","archived":false,"fork":false,"pushed_at":"2023-01-07T03:00:56.000Z","size":1035,"stargazers_count":9,"open_issues_count":14,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-22T01:03:42.992Z","etag":null,"topics":["error-monitoring","error-reporting","sentry","sentry-php","wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":null,"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/itgalaxy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-20T16:05:04.000Z","updated_at":"2022-11-11T12:33:07.000Z","dependencies_parsed_at":"2023-01-14T05:27:19.132Z","dependency_job_id":null,"html_url":"https://github.com/itgalaxy/sentry-integration","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itgalaxy%2Fsentry-integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itgalaxy%2Fsentry-integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itgalaxy%2Fsentry-integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itgalaxy%2Fsentry-integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itgalaxy","download_url":"https://codeload.github.com/itgalaxy/sentry-integration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248252725,"owners_count":21072702,"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":["error-monitoring","error-reporting","sentry","sentry-php","wordpress","wordpress-plugin"],"created_at":"2024-09-25T00:38:50.169Z","updated_at":"2025-04-10T16:40:38.413Z","avatar_url":"https://github.com/itgalaxy.png","language":"PHP","readme":"# [Sentry Integration](https://wordpress.org/plugins/sentry-integration/)\n\n[![Build Status](https://travis-ci.org/itgalaxy/sentry-integration.svg?branch=master)](https://travis-ci.org/itgalaxy/sentry-integration)\n[![Coverage Status](https://coveralls.io/repos/github/itgalaxy/sentry-integration/badge.svg?branch=master)](https://coveralls.io/github/itgalaxy/sentry-integration?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/itgalaxy/sentry-integration/v/stable)](https://packagist.org/packages/itgalaxy/sentry-integration)\n[![Total Downloads](https://poser.pugx.org/itgalaxy/sentry-integration/downloads)](https://packagist.org/packages/itgalaxy/sentry-integration)\n[![Latest Unstable Version](https://poser.pugx.org/itgalaxy/sentry-integration/v/unstable)](https://packagist.org/packages/itgalaxy/sentry-integration)\n[![License](https://poser.pugx.org/itgalaxy/sentry-integration/license)](https://packagist.org/packages/itgalaxy/sentry-integration)\n[![composer.lock](https://poser.pugx.org/itgalaxy/sentry-integration/composerlock)](https://packagist.org/packages/itgalaxy/sentry-integration)\n\nA (unofficial)\n[WordPress plugin](https://wordpress.org/plugins/sentry-integration/) to report\nPHP, JavaScript and security headers (Expect-CT and X-XSS-Protection) errors\nto [Sentry](https://sentry.io).\n\n## Introduction\n\nThis plugin can report PHP errors (optionally), JavaScript errors\n(optionally) and security headers (Expect-CT and X-XSS-Protection) (optionally)\nto [Sentry](https://sentry.io) and integrates with its release tracking.\n\nIt will auto detect authenticated users and add context where possible. All\ncontext/tags can be adjusted using filters mentioned below.\n\n## Usage\n\n1. Install this plugin by cloning or copying this repository to your\n   `wp-contents/plugins` folder\n2. Configure your DSN as explained below\n3. Activate the plugin through the WordPress admin interface\n\n**Note:** this plugin does not do anything by default and has no admin\ninterface. A DSN must be configured first.\n\n## Configuration\n\n### PHP tracker\n\nTrack PHP errors by adding this snippet to your `wp-config.php` and\nreplace `ADDRESS_YOUR_DSN` with your actual DSN that you find in Sentry:\n\n```php\ndefine('SENTRY_INTEGRATION_DSN', 'ADDRESS_YOUR_DSN');\n// Example `ADDRESS_YOUR_DSN` value - https://1fbf25e90f114a3d83a19aa4fa432dcf:3c13a039710e4287900bc71552b1e268@sentry.io/1\n```\n\n**Note:** Do not set this constant to disable the PHP tracker.\n\n---\n\n**(Optionally)** Set the error types the PHP tracker will track:\n\n```php\ndefine(\n  'SENTRY_INTEGRATION_ERROR_TYPES',\n  E_ALL \u0026 ~E_DEPRECATED \u0026 ~E_NOTICE \u0026 ~E_USER_DEPRECATED\n);\n```\n\n### JavaScript tracker\n\nTrack JavaScript errors by adding this snippet to your\n`wp-config.php` and replace `PUBLIC_ADDRESS_YOUR_DSN` with your actual public DSN that you\nfind in Sentry (**never use your private DSN**):\n\n```php\ndefine('SENTRY_INTEGRATION_PUBLIC_DSN', 'PUBLIC_ADDRESS_YOUR_DSN');\n// Example `PUBLIC_ADDRESS_YOUR_DSN` value - https://1fbf25e90f114a3d83a19aa4fa432dcf@sentry.io/1\n```\n\n**Note:** Do not set this constant to disable the JavaScript tracker.\n\n---\n\n**(Optionally)** You can control how plugin should register and enqueue `sentry` JavaScript script (i.e. `raven.min.js`):\n\n```php\ndefine('SENTRY_INTEGRATION_PUBLIC_DSN_ENQUEUE_MODE', 'manual');\n```\n\nThere are 3 values for `SENTRY_INTEGRATION_PUBLIC_DSN_ENQUEUE_MODE` constant.\n\n1. `inline` (**by default** for better performance and avoid problems with order scripts from other plugins/themes) - print inline script and configuration in `head` html tag.\n2. `standard` - use standard `WordPress` api for scripts (i.e. using `wp_register_script`, `wp_enqueue_script` and `wp_add_inline_script` functions on `wp_enqueue_scripts`, `login_enqueue_scripts` and `admin_enqueue_scripts` actions).\n3. `manual` - don't register and enqueue script and configuration. You should manually register and enqueue `sentry` JavaScript script with configuration.\n\n### Expect-CT header tracker\n\nTrack Expect-CT header errors by adding this snippet\nto your `wp-config.php` and replace `ADDRESS_YOUR_DSN` with your actual DSN\nthat you find in Sentry:\n\n```php\ndefine('SENTRY_INTEGRATION_EXPECT_CT_DSN', 'ADDRESS_YOUR_DSN');\n// Example `ADDRESS_YOUR_DSN` value - https://1fbf25e90f114a3d83a19aa4fa432dcf@sentry.io/1\n```\n\n**Note:** Do not set this constant to disable the Expect-CT tracker.\n**Note:** You should send `Expect-CT` header\nwith `report-uri=\"http://you-site.com/sentry-integration/expect-ct/report/\"`\nusing `.htaccess`, `php` or another prefer method. See\nmore about [Expect-CT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT)\nheader.\n\n### X-XSS-Protection tracker\n\nTrack X-XSS-Protection header errors by adding this snippet\nto your `wp-config.php` and replace `ADDRESS_YOUR_DSN` with your actual DSN\nthat you find in Sentry:\n\n```php\ndefine('SENTRY_INTEGRATION_X_XSS_PROTECTION_DSN', 'ADDRESS_YOUR_DSN');\n// Example `ADDRESS_YOUR_DSN` value - https://1fbf25e90f114a3d83a19aa4fa432dcf@sentry.io/1\n```\n\n**Note:** Do not set this constant to disable the X-XSS-Protection tracker.\n**Note:** You should send `X-XSS-Protection` header\nwith `report=\"http://you-site.com/sentry-integration/x-xss-protection/report/\"`\nusing `.htaccess`, `php` or another prefer method. See\nmore about [X-XSS-Protection](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection)\nheader.\n\n### Common configuration for all trackers\n\n**(Optionally)** Define a version of your site; by default the theme version will be\nused. This is used for tracking at which version of your site the error\noccurred. When combined with release tracking this is a very powerful feature.\n\n```php\ndefine('SENTRY_INTEGRATION_VERSION', 'v2.1.3');\n```\n\n**(Optionally)** Define an environment of your site. Defaults to `unspecified`.\n\n```php\ndefine('SENTRY_INTEGRATION_ENV', 'production');\n```\n\n**Note:** By default `SENTRY_INTEGRATION_VERSION` constant contains `wp_get_theme()-\u003eget('Version')` result.\n\n## Filters\n\nThis plugin provides the following filters to plugin/theme developers.\n\nPlease note that some filters are fired when the Sentry trackers are initialized\nso they won't fire if you define them in you theme or in a plugin that loads\nafter Sentry Integration does.\n\n### For PHP, JavaScript, Expect-CT and X-XSS-Protection trackers\n\n#### `sentry_integration_user_context` (array)\n\nYou can use this filter to extend the Sentry user context for both PHP, JS and\nsecurity headers trackers.\n\n\u003e **WARNING:** These values are exposed to the public in the JS tracker, so make\n\u003e sure you do not expose anything private!\n\nExample usage:\n\n```php\n/**\n * Customize sentry user context.\n *\n * @param array $user The current sentry user context.\n *\n * @return array\n */\nfunction customize_sentry_user_context(array $user)\n{\n  return array_merge($user, array(\n    'a-custom-user-meta-key' =\u003e 'custom value'\n  ));\n}\n\nadd_filter('sentry_integration_user_context', 'customize_sentry_user_context');\n```\n\n**Note:** _This filter fires on the WordPress `set_current_user` action._\n\n### Specific to PHP tracker\n\n#### `sentry_integration_dsn` (string)\n\nYou can use this filter to override the Sentry DSN used for the PHP tracker.\n\nExample usage:\n\n```php\n/**\n * Customize sentry dsn.\n *\n * @param string $dsn The current sentry public dsn.\n *\n * @return string\n */\nfunction customize_sentry_dsn($dsn)\n{\n  return 'https://\u003ckey\u003e:\u003csecret\u003e@sentry.io/\u003cproject\u003e';\n}\n\nadd_filter('sentry_integration_dsn', 'customize_sentry_dsn');\n```\n\n**Note:** _This filter fires on when Sentry Integration initializes and after\nthe WP `after_setup_theme`._\n\n---\n\n#### `sentry_integration_options` (array)\n\nYou can use this filter to customize the Sentry options used to initialize the\nPHP tracker.\n\nExample usage:\n\n```php\n/**\n * Customize sentry options.\n *\n * @param array $options The current sentry options.\n *\n * @return array\n */\nfunction customize_sentry_options(array $options)\n{\n  return array_merge($options, array(\n    'tags' =\u003e array(\n      'my-custom-tag' =\u003e 'custom value'\n    )\n  ));\n}\n\nadd_filter('sentry_integration_options', 'customize_sentry_options');\n```\n\n**Note:** _This filter fires on when Sentry Integration initializes and after\nthe WP `after_setup_theme`._\n\n---\n\n#### `sentry_integration_send_data` (array|bool)\n\nProvide a function which will be called before Sentry PHP tracker sends any\ndata, allowing you both to mutate that data, as well as prevent it from being\nsent to the server.\n\nExample usage:\n\n```php\n/**\n * Customize sentry send data.\n *\n * @param array $data The sentry send data.\n *\n * @return array|bool Return the data array or false to cancel the send operation.\n */\nfunction filter_sentry_send_data(array $data)\n{\n  $data['tags']['my_custom_key'] = 'my_custom_value';\n\n  return $data;\n}\n\nadd_filter('sentry_integration_send_data', 'filter_sentry_send_data');\n```\n\n**Note:** _This filter fires whenever the Sentry SDK is sending data to the\nSentry server._\n\n### Specific to JavaScript tracker\n\n#### `sentry_integration_public_dsn` (string)\n\nYou can use this filter to override the Sentry DSN used for the JS tracker.\n\n\u003e **WARNING:** This value is exposed to the public, so make sure you do not use\n\u003e your private DSN!\n\nExample usage:\n\n```php\n/**\n * Customize public sentry dsn.\n *\n * @param string $dsn The current sentry public dsn.\n *\n * @return string\n */\nfunction customize_public_sentry_dsn($dsn)\n{\n  return 'https://\u003ckey\u003e@sentry.io/\u003cproject\u003e';\n}\n\nadd_filter('sentry_integration_public_dsn', 'customize_public_sentry_dsn');\n```\n\n---\n\n#### `sentry_integration_public_options` (array)\n\nYou can use this filter to customize/override the sentry options used to\ninitialize the JS tracker.\n\n\u003e **WARNING:** These values are exposed to the public, so make sure you do not\n\u003e expose anything private !\n\nExample usage:\n\n```php\n/**\n * Customize public sentry options.\n *\n * @param array $options The current sentry public options.\n *\n * @return array\n */\nfunction customize_public_sentry_options(array $options)\n{\n  return array_merge($options, array(\n    'tags' =\u003e array(\n      'custom-tag' =\u003e 'custom value'\n    )\n  ));\n}\n\nadd_filter(\n  'sentry_integration_public_options',\n  'customize_sentry_public_options'\n);\n```\n\n### Specific to Expect-CT tracker\n\n#### `sentry_integration_expect_ct_dsn` (string)\n\nYou can use this filter to override the Sentry DSN used for the\nExpect-CT tracker.\n\nExample usage:\n\n```php\n/**\n * Customize sentry dsn.\n *\n * @param string $dsn The current sentry public dsn.\n *\n * @return string\n */\nfunction customize_sentry_dsn($dsn)\n{\n  return 'https://\u003ckey\u003e:\u003csecret\u003e@sentry.io/\u003cproject\u003e';\n}\n\nadd_filter('sentry_integration_expect_ct_dsn', 'customize_sentry_dsn');\n```\n\n**Note:** _This filter fires on when Sentry Integration initializes and after\nthe WP `after_setup_theme`._\n\n---\n\n#### `sentry_integration_expect_ct_options` (array)\n\nYou can use this filter to customize the Sentry options used to initialize the\nExpect-CT tracker.\n\nExample usage:\n\n```php\n/**\n * Customize sentry options.\n *\n * @param array $options The current sentry options.\n *\n * @return array\n */\nfunction customize_sentry_options(array $options)\n{\n  return array_merge($options, array(\n    'tags' =\u003e array(\n      'my-custom-tag' =\u003e 'custom value'\n    )\n  ));\n}\n\nadd_filter('sentry_integration_expect_ct_options', 'customize_sentry_options');\n```\n\n**Note:** _This filter fires on when Sentry Integration initializes and after\nthe WP `after_setup_theme`._\n\n---\n\n#### `sentry_integration_expect_ct_send_data` (array|bool)\n\nProvide a function which will be called before Sentry Expect-CT tracker\nsends any data, allowing you both to mutate that data, as well as prevent\nit from being sent to the server.\n\nExample usage:\n\n```php\n/**\n * Customize sentry send data.\n *\n * @param array $data The sentry send data.\n *\n * @return array|bool Return the data array or false to cancel the send operation.\n */\nfunction filter_sentry_send_data(array $data)\n{\n  $data['tags']['my_custom_key'] = 'my_custom_value';\n\n  return $data;\n}\n\nadd_filter('sentry_integration_expect_ct_send_data', 'filter_sentry_send_data');\n```\n\n**Note:** _This filter fires whenever the Sentry SDK is sending data to the\nSentry server._\n\n### Specific to X-XSS-Protection tracker\n\n#### `sentry_integration_x_xss_protection_dsn` (string)\n\nYou can use this filter to override the Sentry DSN used for the\nX-XSS-Protection tracker.\n\nExample usage:\n\n```php\n/**\n * Customize sentry dsn.\n *\n * @param string $dsn The current sentry public dsn.\n *\n * @return string\n */\nfunction customize_sentry_dsn($dsn)\n{\n  return 'https://\u003ckey\u003e:\u003csecret\u003e@sentry.io/\u003cproject\u003e';\n}\n\nadd_filter('sentry_integration_x_xss_protection_dsn', 'customize_sentry_dsn');\n```\n\n**Note:** _This filter fires on when Sentry Integration initializes and after\nthe WP `after_setup_theme`._\n\n---\n\n#### `sentry_integration_x_xss_protection_options` (array)\n\nYou can use this filter to customize the Sentry options used to initialize the\nExpect-CT tracker.\n\nExample usage:\n\n```php\n/**\n * Customize sentry options.\n *\n * @param array $options The current sentry options.\n *\n * @return array\n */\nfunction customize_sentry_options(array $options)\n{\n  return array_merge($options, array(\n    'tags' =\u003e array(\n      'my-custom-tag' =\u003e 'custom value'\n    )\n  ));\n}\n\nadd_filter(\n  'sentry_integration_x_xss_protection_options',\n  'customize_sentry_options'\n);\n```\n\n**Note:** _This filter fires on when Sentry Integration initializes and after\nthe WP `after_setup_theme`._\n\n---\n\n#### `sentry_integration_x_xss_protection_send_data` (array|bool)\n\nProvide a function which will be called before Sentry Expect-CT tracker\nsends any data, allowing you both to mutate that data, as well as prevent\nit from being sent to the server.\n\nExample usage:\n\n```php\n/**\n * Customize sentry send data.\n *\n * @param array $data The sentry send data.\n *\n * @return array|bool Return the data array or false to cancel the send operation.\n */\nfunction filter_sentry_send_data(array $data)\n{\n  $data['tags']['my_custom_key'] = 'my_custom_value';\n\n  return $data;\n}\n\nadd_filter(\n  'sentry_integration_x_xss_protection_send_data',\n  'filter_sentry_send_data'\n);\n```\n\n**Note:** _This filter fires whenever the Sentry SDK is sending data to the\nSentry server._\n\n## Catching plugin errors\n\nSince this plugin is called `sentry-integration` it loads a bit late which could\nmiss 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\nthe file `wp-content/mu-plugins/sentry-integration.php` (if the `mu-plugins`\ndirectory does not exists you must create that too).\n\n```php\n\u003c?php\n\n/**\n * Plugin Name: Sentry Integration\n * Plugin URI: https://github.com/itgalaxy/sentry-integration\n * Description: A (unofficial) WordPress plugin to report PHP and JavaScript and security headers errors to Sentry.\n * Version: must-use-proxy\n * Author: Alexander Krasnoyarov\n * Author URI: https://github.com/evilebottnawi\n * License: MIT\n */\n\n$sentry_integration =\n  __DIR__ . '/../plugins/sentry-integration/sentry-integration.php';\n\nif (!file_exists($sentry_integration)) {\n  return;\n}\n\nrequire $sentry_integration;\n\ndefine('SENTRY_INTEGRATION_MU_LOADED', true);\n```\n\nNow `sentry-integration` will load always and before all other plugins.\n\n**Note**: We advise you leave the original `sentry-integration` in the\n`/wp-content/plugins` folder to still have updates come in through the WordPress\nupdater. However enabling or disabling does nothing if the above script is\nactive (since it will always be enabled).\n\n## License\n\nSentry Integration plugin is open-sourced software\nlicensed under the [MIT license](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitgalaxy%2Fsentry-integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitgalaxy%2Fsentry-integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitgalaxy%2Fsentry-integration/lists"}