stayallive / wp-sentry

A (unofficial) WordPress plugin reporting PHP and JavaScript errors to Sentry.
https://wordpress.org/plugins/wp-sentry-integration/
MIT License
300 stars 48 forks source link

Browser failed to send test. Check your configuration to make sure your DSN is set correctly. #199

Closed nachogrxdev closed 1 month ago

nachogrxdev commented 1 month ago

I'm trying to configure Browser Javascript and I'm getting this error when testing.

Browser failed to send test. Check your configuration to make sure your DSN is set correctly.

I have run the tests incognito without any extension.

// It's possible your WordPress installation is different, check to make sure this path is correct for your installation
require_once __DIR__ . '/wp-content/plugins/wp-sentry-integration/wp-sentry.php';

/** Set up Sentry */
define('WP_SENTRY_PHP_DSN', 'https://XXXXX.ingest.de.sentry.io/XX');
define('WP_SENTRY_SEND_DEFAULT_PII', true);
define('WP_SENTRY_TRACES_SAMPLE_RATE', 0.7); // traces_sample_rate
define('WP_SENTRY_PROFILES_SAMPLE_RATE', 0.7);
define('WP_SENTRY_TRACING_FEATURES', [
        'db' => [
                'spans' => true,
                'breadcrumbs' => defined( 'SAVEQUERIES' ) && SAVEQUERIES,
        ],
        'http' => [
                'spans' => true,
                'breadcrumbs' => true,
        ],
        'transients' => [
                'spans' => true,
                'breadcrumbs' => true,
        ],
]);

define( 'WP_SENTRY_BROWSER_DSN', 'https://XXXXX.ingest.de.sentry.io/XX' );

/* That's all, stop editing! Happy publishing. */
stayallive commented 1 month ago

What does your browser console tell you?

nachogrxdev commented 1 month ago

What does your browser console tell you?

image

stayallive commented 1 month ago

Does your network tab make a request out to Sentry? Does that fail?

nachogrxdev commented 1 month ago

Does your network tab make a request out to Sentry? Does that fail?

image

Clicking Send Browser test error

Even if you don't have any of the notification receiving buttons

stayallive commented 1 month ago

Okay, you might need to inspect your HTML to see if the Sentry SDK is even loaded.

There might be a conflict with another plugin or some optimization plugin causing issues.

You would expect to see: wp-content/plugins/wp-sentry/public/wp-sentry-browser.min.js being loaded on your page. If that script is not loaded it could explain why there are no other errors or requests visible.

nachogrxdev commented 1 month ago

Okay, you might need to inspect your HTML to see if the Sentry SDK is even loaded.

There might be a conflict with another plugin or some optimization plugin causing issues.

You would expect to see: wp-content/plugins/wp-sentry/public/wp-sentry-browser.min.js being loaded on your page. If that script is not loaded it could explain why there are no other errors or requests visible.

I currently have all plugins disabled except Sentry.

Inspecting the HTML code of the wordpress sentry configuration page does not find any js loaded with the name wp-sentry-browser.min.js

stayallive commented 1 month ago

Interesting. It works like a charm on a few of my installations.

What version of PHP, the plugin and/or WordPress are you using?

And is the installation a network installation or regular.

Anything else that might be different or non-standard that you can think of (maybe a theme)?

nachogrxdev commented 1 month ago

Interesting. It works like a charm on a few of my installations.

What version of PHP, the plugin and/or WordPress are you using?

And is the installation a network installation or regular.

Anything else that might be different or non-standard that you can think of (maybe a theme)?

It's a freshly installed wordpress, nothing special.

image

I'm using a dockerized version image: wordpress:latest with a reverse proxy with Traefik and the entire network under cloudflare

/var/www/html# php -v
PHP 8.0.30 (cli) (built: Oct 12 2023 05:07:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies

To clarify, the PHP notification works correctly.

nachogrxdev commented 1 month ago

Plugin installed on a WordPress hosted on Dreamhost with PHP 8.1, the integration with JS does not work either.

In this case, I don't see that it has loaded the corresponding .js either.

stayallive commented 1 month ago

The plot thickens, interesting. On what WordPress version are you?

You both don't have WP_SENTRY_BROWSER_ADMIN_ENABLED defined right?

nachogrxdev commented 1 month ago

The plot thickens, interesting. On what WordPress version are you?

You both don't have WP_SENTRY_BROWSER_ADMIN_ENABLED defined right?

image

image

image

/* Set Sentry configuration */

// It's possible your WordPress installation is different, check to make sure this path is correct for your installation
require_once __DIR__ . '/wp-content/plugins/wp-sentry-integration/wp-sentry.php';

define('WP_SENTRY_PHP_DSN', 'https://X@X.ingest.us.sentry.io/X');
define('WP_SENTRY_SEND_DEFAULT_PII', true);
define('WP_SENTRY_TRACES_SAMPLE_RATE', 0.7); // traces_sample_rate
define('WP_SENTRY_PROFILES_SAMPLE_RATE', 0.7);

define('WP_SENTRY_BROWSER_DSN', 'https://X@X.ingest.us.sentry.io/X');
define('WP_SENTRY_BROWSER_TRACES_SAMPLE_RATE', 0.7); // tracesSampleRate
// These options are injected into the `Sentry.init()` call
// https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration
define('WP_SENTRY_BROWSER_REPLAYS_SESSION_SAMPLE_RATE', 0.1); // replaysSessionSampleRate
define('WP_SENTRY_BROWSER_REPLAYS_ON_ERROR_SAMPLE_RATE', 1.0); // replaysOnErrorSampleRate

/* That's all, stop editing! Happy publishing. */

This is the configuration of this last Dreamhost environment that I mention. I don't have any definition for the variable commented out by WP_SENTRY_BROWSER_ADMIN_ENABLED

stayallive commented 1 month ago

Move your require_once to AFTER your define statements πŸ˜…

The issue is that your config is not defined when you are loading Sentry.

However the admin page loads a lot later and thus picks up on the config just fine.

I have to think of a good way to detect this better πŸ€”

nachogrxdev commented 1 month ago

Move your require_once to AFTER your define statements πŸ˜…

The issue is that your config is not defined when you are loading Sentry.

However the admin page loads a lot later and thus picks up on the config just fine.

I have to think of a good way to detect this better πŸ€”

Indeed, now it works. Thank you so much!

stayallive commented 1 month ago

For future readers, please make sure you do them in the correct order, (all) configuration first the require_once next otherwise values might not be picked up correctly.

afbeelding