stayallive / wp-sentry

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

WP_SENTRY_BROWSER_DSN and WP_SENTRY_VERSION not working #92

Closed Giacomo92 closed 2 years ago

Giacomo92 commented 3 years ago

HI everyone, I have activated the plugin and I have setup the configuration key on wp-config.php like this:

define('WP_SENTRY_PHP_DSN', 'MY_PHP_URL');
define('WP_SENTRY_BROWSER_DSN', 'MY_JS_URL');

This is a screen from admin panel:

Schermata 2021-06-29 alle 14 34 41

As you can see the js tracing is not enabled. I also tested WP_ENVIRONMENT_TYPE that is not working.

How can I solve this?

stayallive commented 3 years ago

Okay, fir the WP_ENVIRONMENT_TYPE, make sure you are using any of these values:

    $wp_environments = array(
        'local',
        'development',
        'staging',
        'production',
    );

If you are setting WP_ENVIRONMENT_TYPE to anything else it defaults to production (read more here).


I tried both and they are both working for me:

define( 'WP_SENTRY_PUBLIC_DSN', 'https://asdasd@sentry.io/12345' );
define( 'WP_SENTRY_BROWSER_DSN', 'https://asdasd@sentry.io/12345' );

Make sure your host is not using opcache (or clear it) and that you add these define calls in your wp-config.php.

If that all is not working for some reason please let me know your PHP version and also what version of the plugin you are using.

Giacomo92 commented 3 years ago

Hi @stayallive, WP_ENVIRONMENT_TYPE is solved. I did not know it is a standard wordpress constant with a fixed amount of value.

WP_SENTRY_BROWSER_DSN still not working, I have also tried a filter in my function file:

/**
   * Customize public sentry dsn.
   *
   * @param string $dsn The current sentry public dsn.
   *
   * @return string
   */
  function oa_public_sentry_dsn( $dsn ) {
    return 'https://asdasd@sentry.io/12345';
  }
  add_filter( 'wp_sentry_public_dsn', 'oa_public_sentry_dsn' );

but the JavaScript checkbox never get enabled.

PHP Version: 7.4.20 Plugin Version: 4.4.1

Thanks

stayallive commented 3 years ago

Yeah WP_ENVIRONMENT_TYPE is a fixed list indeed but you can use WP_SENTRY_ENV to put in anything you want.

The browser DSN is puzzling me why it will not work for you... I did make some changes to make the code a bit simpler for 4.5.0 of the plugin (just released) but I doubt it will solve your issue.

But I did not see if you are placing the define( 'WP_SENTRY_BROWSER_DSN', 'https://asdasd@sentry.io/12345' ); in your wp-config.php file? Is it in the same place as the define( 'WP_SENTRY_DSN', 'https://asdasd@sentry.io/12345' );?

Giacomo92 commented 3 years ago

I have updated the plugin and now the checkbox is enabled. Schermata 2021-06-30 alle 13 50 57

When I try to send a Javascript test event I got this: Schermata 2021-06-30 alle 13 52 50

I notice that wp-sentry-browser file is not include in my page, so this condition is never satisfied and I always get the error: if (typeof Sentry === 'object' && typeof Sentry.captureMessage === 'function') {

WP_SENTRY_BROWSER_DSN is right after WP_SENTRY_PHP_DSN in my wp-config.php file.

stayallive commented 3 years ago

It's getting more interesting by the minute here :D

Happy to see changes to the plugin helped make it work... somehow...

But at least the JS tracker is enabled now so we can move forward!

Are you using a plugin to concatenate scripts and or styles that might be in play here or maybe even other caching plugins?

You can see the code it hooks into admin_enqueue_scripts so I don't see how that wouldn't work unless something is messing with enqueues. You can also search your HTML for var wp_sentry which should always be there becomes that comes from the localize script.

stefs7 commented 3 years ago

Hi,

I'm also experiencing issues with WP_SENTRY_PHP_DSN & WP_SENTRY_BROWSER_DSN. Using the latest WP plugin version (4.5.0) with the following defined in my wp-config:

define('WP_SENTRY_PHP_DSN', 'https://XXX');
define('WP_SENTRY_ERROR_TYPES', E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_USER_DEPRECATED);
define('WP_SENTRY_SEND_DEFAULT_PII', true);
define('WP_SENTRY_BROWSER_DSN', 'https://XXX');

OPcache & normal cache where emptied.

image

stayallive commented 3 years ago

Hey @stefs7 are you a new user or did you update the plugin from an earlier version where it was working?

Did you also put the defines above the /* That's all, stop editing! Happy blogging. */ line in the wp-config.php file?

stefs7 commented 3 years ago

Hey Alex,

Correct, I created my account today. The defines are defined above the /* That's all, stop editing! Happy blogging. */.

Thanks for your fast reply!

stayallive commented 3 years ago

Okay I'm super puzzled why this is an issue... I have copied your defines (but added correct DSN's of course) and it works just fine in my testing... so I must be missing something in my tests.

Can you also tell me what PHP version you are using and what version of WordPress so I can try to replicate?

stefs7 commented 3 years ago

PHP version: 7.2 WordPress (multisite): 5.7.2

I don't know for sure if I did use the correct keys. I'm supposed to use the "DSN" key for WP_SENTRY_PHP_DSN & WP_SENTRY_BROWSER_DSN right?

image

stayallive commented 3 years ago

Yes the values are indeed 90% of the time the same. But only the PHP SDK does some validation (and crashes hard if the value is invalid, needs to be fixed) but the browser DSN is not validated at all and only checked if it's not empty, so any value will be accepted there so that's why I am so puzzled why it's not working 😄

I will try to figure it out with 7.2 and WP 5.7.

About multisite, did you enable the plugin site-wide or per site?

stefs7 commented 3 years ago

The plugin is site-wide: enabled for two domains (Dutch and Belgium).

Thanks for your help!

stayallive commented 3 years ago

Hey @stefs7 I have tried to replicate the issue but I'm not getting anywhere :(

My wp-config.php looks like this for testing which might help you spot the problem in yours:

<?php

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

define('WP_SENTRY_PHP_DSN', '<redacted>');
define('WP_SENTRY_BROWSER_DSN', '<redacted>');

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', '<redacted>');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

// ** MySQL settings ** //
/** The name of the database for WordPress */
define( 'DB_NAME', '<redacted>' );

/** MySQL database username */
define( 'DB_USER', '<redacted>' );

/** MySQL database password */
define( 'DB_PASSWORD', '<redacted>' );

/** MySQL hostname */
define( 'DB_HOST', '<redacted>' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY', '<redacted>');
define('SECURE_AUTH_KEY', '<redacted>');
define('LOGGED_IN_KEY', '<redacted>');
define('NONCE_KEY', '<redacted>');
define('AUTH_SALT', '<redacted>');
define('SECURE_AUTH_SALT', '<redacted>');
define('LOGGED_IN_SALT', '<redacted>');
define('NONCE_SALT', '<redacted>');

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'Rg6EsNn4_';

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

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) )
    define( 'ABSPATH', dirname( __FILE__ ) . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Are you using some interesting deployment tools like Deployer or Capistrano or Bedrock or something to manage and/or update your WordPress installation? I'm grasping at straws here thinking about what could possibly be going wrong... I appreciate the patience and the info you are providing figuring this out!

stefs7 commented 3 years ago

Hi @stayallive,

Sorry for my late reply.

I'm gonna try Sentry on a non-WordPress project first to exclude any other possible problems from my side. Gonna let you know what my results are!

stefs7 commented 3 years ago

Update: problem was caused by a migration to a new server, so the changed wp-config with Sentry credentials was never used ._. It instead loaded a different wp-config...

Bit of a dumb fault, sorry!

stayallive commented 3 years ago

@stefs7 Woooops... well that would explain why it wasn't working, it happens! 😆

Great to hear it was solved for you at least!

Now I only need to figure out what the issue with @Giacomo92 is, is the JS file loading now or is that still broken for you?

dquinteros commented 3 years ago

I have updated the plugin and now the checkbox is enabled. Schermata 2021-06-30 alle 13 50 57

When I try to send a Javascript test event I got this: Schermata 2021-06-30 alle 13 52 50

I notice that wp-sentry-browser file is not include in my page, so this condition is never satisfied and I always get the error: if (typeof Sentry === 'object' && typeof Sentry.captureMessage === 'function') {

WP_SENTRY_BROWSER_DSN is right after WP_SENTRY_PHP_DSN in my wp-config.php file.

I have this same issue

stayallive commented 3 years ago

Are you using a plugin to concatenate scripts and or styles that might be in play here or maybe even other caching plugins?

Can you try and disable all other plugins to see if it solves the problem? (do not do this on a production environment but only a test site).

dquinteros commented 3 years ago

I do not use any specific plugin to concatenate scripts or styles, nor do I use any plugin for caching. I manage the cache mainly through cloudflare.

I will try to discard plugins compatibility issues, will share my findings on the next days.

stayallive commented 2 years ago

I am closing this issue because of inactivity, if there is still an issue please re-open / open a new issue so we can investigate 👍

shintaii commented 2 years ago

Same issue here, i'm willing to help debug.

So i have cleared OPcache and cache, there is no JS minifying. There are no sentry js scripts in my frontend session.

stayallive commented 2 years ago

Hi @shintaii, please tell us a bit more about your environment, like what PHP version, what version of the plugin, what version of WordPress and what exactly you did configure in your wp-config.php file 👍

shintaii commented 2 years ago

Hi @shintaii, please tell us a bit more about your environment, like what PHP version, what version of the plugin, what version of WordPress and what exactly you did configure in your wp-config.php file 👍

Config file: define( 'WP_SENTRY_PHP_DSN', 'https://123@567.ingest.sentry.io/890' ); define( 'WP_SENTRY_BROWSER_DSN', 'https://123@567.ingest.sentry.io/890' ); define( 'WP_SENTRY_BROWSER_TRACES_SAMPLE_RATE', 0.3 );

PHP version 7.4 plugin version: 4.14.0 wp version: 5.7.2

stayallive commented 2 years ago

@shintaii are you by chance running on a hosting provider that is using Lightspeed or have your site behind Cloudflare?

Giacomo92 commented 2 years ago

Hi @stayallive, sorry for my late reply. I am stil experiencing this issue. If it can be useful my website is behind Cloudflare

shintaii commented 2 years ago

Im using Kinsta, not sure what they use, but probably something like Cloudflare yes.