Download the PHP package stayallive/wp-sentry without Composer
On this page you can find all versions of the php package stayallive/wp-sentry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stayallive/wp-sentry
More information about stayallive/wp-sentry
Files in stayallive/wp-sentry
Package wp-sentry
Short Description A (unofficial) WordPress plugin to report PHP and JavaScript errors to Sentry.
License MIT
Homepage https://github.com/stayallive/wp-sentry
Informations about the package wp-sentry
WordPress Sentry (wp-sentry)
A (unofficial) WordPress plugin to report PHP and JavaScript errors to Sentry.
What?
This plugin can report PHP errors (optionally) and JavaScript errors (optionally) to Sentry and integrates with its release tracking.
It will auto detect authenticated users and add context where possible. All context/tags can be adjusted using filters mentioned below.
Requirements
This 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.
- Version
2.1.*
of this plugin will be the last to support PHP5.3
. - Version
2.2.*
of this plugin will be the last to support PHP5.4
. - Version
3.11.*
of this plugin will be the last to support PHP7.1
.
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.
- Version
2.x
of the wp-sentry plugin uses the1.x
version of the official Sentry PHP SDK. - Version
3.x
of the wp-sentry plugin uses the2.x
version of the official Sentry PHP SDK. - Version
4.x
,5.x
, &6.x
of the wp-sentry plugin uses the3.x
version of the official Sentry PHP SDK. - Version
7.x
+ of the wp-sentry plugin uses the4.x
version of the official Sentry PHP SDK.
Usage
There are a couple of options to start using the plugin.
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.
WordPress plugin repository
- Install this plugin from the WordPress plugin repository: https://wordpress.org/plugins/wp-sentry-integration/
- Configure your DSN as explained in the configuration section
- Activate the plugin through the WordPress admin interface or wp-cli
Manual plugin installation
- Download the plugin from the releases page
- Extract it and place the folder in your
wp-content/plugins
folder - Configure your DSN as explained in the configuration section
- Activate the plugin through the WordPress admin interface or wp-cli
Using composer
- Run
composer require stayallive/wp-sentry
in your project - Configure your DSN as explained in the configuration section
- Activate the plugin through the WordPress admin interface or wp-cli
Configuration
To start using the plugin first setup the DSN for either the PHP side or the Browser side or both.
All 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.
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!
DSN
Sentry uses something called a DSN (read more) to configure the SDK.
WP_SENTRY_PHP_DSN
(PHP)
To 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)":
Note: Do not set this constant to disable the PHP tracker.
Note: This constant was previously called WP_SENTRY_DSN
and is still supported.
WP_SENTRY_BROWSER_DSN
(Browser)
To 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)":
Note: Do not set this constant to disable the JavaScript tracker.
Note: This constant was previously called WP_SENTRY_PUBLIC_DSN
and is still supported.
Privacy
WP_SENTRY_SEND_DEFAULT_PII
If 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.
If possible, it’s recommended to turn on this feature and use the server side PII stripping to remove the values instead.
When enabled the current logged in user and IP address will be added to the event.
Options
WP_SENTRY_VERSION
Define a version of your site. By default the active theme version will be used or unspecified
if theme version could not be resolved.
This is used for tracking at which version of your site the error occurred. When combined with release tracking this is a very powerful feature.
WP_SENTRY_ENV
Define an environment of your site. Defaults to the WordPress environment type from wp_get_environment_type()
or unspecified
if none configured.
This is used for tracking on which environment of your site the error occurred.
WP_SENTRY_ERROR_TYPES
(PHP)
Set the error types the PHP tracker will track:
Note: You can set any combination of error types you want, see the PHP documentation for more information.
Set Up Tracing
WP_SENTRY_TRACES_SAMPLE_RATE
(PHP)
Set the desired sampling rate for performane tracing. Replace 0.3
with your desired sampling rate (0.3
means sample ~30% of your traffic):
Enabling 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
.
Note: Do not set this constant or set the sample rate to 0.0
to disable the performance monitoring.
WP_SENTRY_TRACING_FEATURES
(PHP)
Enable performance monitoring features by adding this snippet to your wp-config.php
:
Note: Not configuring this constant will default to the above configuration.
WP_SENTRY_BROWSER_TRACES_SAMPLE_RATE
(Browser)
Enable 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):
Note: Do not set this constant or set the sample rate to 0.0
to disable the JavaScript performance tracing.
WP_SENTRY_BROWSER_REPLAYS_SESSION_SAMPLE_RATE
(Browser)
Enable 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):
Note: Do not set these constants or set the sample rates to 0.0
to disable the JavaScript Session Replay.
Set Up Profiling
WP_SENTRY_PROFILES_SAMPLE_RATE
(PHP)
Note: This feature requires the Excimer PHP extension to be installed. See the Sentry PHP SDK documentation for more information.
Sentry'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.
Set the desired sampling rate for profiling. Replace 0.3
with your desired sampling rate (0.3
means sample ~30% of your traffic):
Note: Do not set this constant or set the sample rate to 0.0
to disable the performance monitoring.
Set Up User Feedback
WP_SENTRY_BROWSER_FEEDBACK_OPTIONS
(Browser)
You can enable the User Feedback Widget (official documentation) by adding this snippet to your wp-config.php
:
All option are passed directly to feedbackIntegration()
, you can read about all the available options in the official documentation.
Filters
This plugin provides the following filters to plugin/theme developers.
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.
Common to PHP & Browser
wp_sentry_user_context
(array)
You can use this filter to extend the Sentry user context for both PHP and JS trackers.
WARNING: These values are exposed to the public in the JS tracker, so make sure you do not expose anything private!
Example usage:
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
._
Specific to PHP
wp_sentry_dsn
(string)
You can use this filter to override the Sentry DSN used for the PHP tracker.
WARNING: This is not recommended, please set the DSN using the
WP_SENTRY_PHP_DSN
constant in yourwp-config.php
!
Example usage:
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_
wp_sentry_scope
(void)
You can use this filter to customize the Sentry scope.
Example usage:
Note: _This filter fires on the WordPress after_setup_theme
action._
wp_sentry_options
You can use this filter to customize the Sentry options.
Example usage:
Note: _This filter fires on the WordPress after_setup_theme
action._
wp_sentry_before_send
You can use this filter to filter error events sent to Sentry. Read more about filtering in the docs.
Example usage:
Note: Do not forget to return the $event
if you want to send it to Sentry, returning null
discards the event.
Specific to Browser
wp_sentry_public_dsn
(string)
You can use this filter to override the Sentry DSN used for the JS tracker.
WARNING: This is not recommended, please set the DSN using the
WP_SENTRY_BROWSER_DSN
constant in yourwp-config.php
!
Example usage:
wp_sentry_public_options
(array)
You can use this filter to customize/override the Sentry options used to initialize the JS tracker.
WARNING: These values are exposed to the public, so make sure you do not expose anything private !
Example usage:
Note: Items prefixed with regex:
in denyUrls
, allowUrls
and ignoreErrors
option arrays will be translated into pure RegExp.
wp_sentry_public_context
(array)
You can use this filter to customize/override the Sentry context, you can modify the user
and tags
context.
WARNING: These values are exposed to the public, so make sure you do not expose anything private !
Example usage:
Advanced usages
High volume of notices
Many plugin in the WordPress ecosystem generate notices that are captured by the Sentry plugin.
This can cause a high volume of events and even slower page loads because of those events being transmitted to Sentry.
The prevent this you can set the following in your wp-config.php
to filter out errors of the notice type.
Note: You can set any combination of error types you want, see the PHP documentation for more information.
Capturing handled exceptions
The best thing to do with an exception is to capture and handle it, however you might still want to know an exception happened.
The Sentry plugin only captures unhandled exceptions and fatal errors, to capture handled exception you can do the following:
If you need to attach extra data only for the handled exception, you could add Structured Context:
If you need to add data to the scope in every case use configureScope
in wp_sentry_scope filter.
Loading Sentry before WordPress
Since WP Sentry is a WordPress plugin it loads after WordPress and unless you are using a must-use plugin (see Capturing plugin errors) even after some other plugins loaded throwing errors which are not captured by Sentry.
To remedy this you can opt to load the plugin from your wp-config.php
file before WordPress is started.
It'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:
Also make sure that any configuration options like WP_SENTRY_PHP_DSN
are set before the snippet above otherwise they have no effect.
Capturing plugin errors
Since 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.
You 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).
Now wp-sentry-integration
will load always and before all other plugins.
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).
Capturing errors only from certain theme and/or plugin
This 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.
See also the filter docs: wp_sentry_option.
Client side hook
When 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.
You 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).
A quick example on how you would disable the Browser SDK using wp_add_inline_script
:
When the wp_sentry_hook
function returns false
the initialization of the Sentry Brower SDK will be stopped. Any other return value will be ignored.
To 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.
Modifying the PHP SDK ClientBuilder
or options before initialisation
Because 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.
There 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
.
The callback will be executed whenever the plugin creates a new ClientBuilder
instance to create a new PHP SDK client.
You would place the example below in your wp-config.php
file to make sure it's available before the PHP SDK is initialized:
HTTP proxy
If 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.
Read more about how to setup the WordPress Proxy constants here: https://developer.wordpress.org/reference/classes/wp_http_proxy/#description.
There 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!
Security Vulnerabilities
If you discover a security vulnerability within WordPress Sentry (wp-sentry), please send an e-mail to Alex Bouma at [email protected]
. All security vulnerabilities will be swiftly addressed.
License
The WordPress Sentry (wp-sentry) plugin is open-sourced software licensed under the MIT license.
All versions of wp-sentry with dependencies
sentry/sentry Version ^4.8
composer/installers Version ^1.0 || ^2.0
jean85/pretty-package-versions Version ^1.5