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

Cannot configure in wp-config.php #108

Closed androidacy-user closed 2 years ago

androidacy-user commented 2 years ago

https://github.com/stayallive/wp-sentry#loading-sentry-before-wordpress says you can now add the call to sentry in wp-config, but it throws an error:

PHP Fatal error:  Uncaught Error: Call to undefined function get_bloginfo() in /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php:134
Stack trace:
#0 /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php(47): WP_Sentry_Js_Tracker->get_default_context()
#1 /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php(36): WP_Sentry_Js_Tracker->__construct()
#2 /var/www/www/wp-content/plugins/wp-sentry-integration/wp-sentry.php(99): WP_Sentry_Js_Tracker::get_instance()
#3 /var/www/www/wp-config.php(102): require_once('...')
#4 /var/www/www/wp-load.php(50): require_once('...')
#5 /var/www/www/wp-blog-header.php(13): require_once('...')
#6 /var/www/www/index.php(17): require('...')
#7 {main}
  thrown in /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php on line 134

Please either correct the documentation, or find out how you can replace the call to a function that isn't defined until wordpress is fully loaded.

androidacy-user commented 2 years ago

I can confirm replacing the two calls to get_bloginfo() with static values is enough for that to work as expected, but for obvious reasons static values won't work for everyone.

stayallive commented 2 years ago

Please either correct the documentation, or find out how you can replace the call to a function that isn't defined until wordpress is fully loaded.

Woah, easy there. This was just released in good faith and obviously something was overlooked which can always happen.

Have a little patience while I investigate on how to fix this nicely or submit a PR if you feel like you have a good solution yourself.

stayallive commented 2 years ago

This should be fixed in v4.10.1 that was just released.

androidacy-user commented 2 years ago

Still not solved.....

PHP Fatal error:  Uncaught Error: Call to undefined function get_bloginfo() in /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php:139
Stack trace:
#0 /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php(47): WP_Sentry_Js_Tracker->get_default_context()
#1 /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php(36): WP_Sentry_Js_Tracker->__construct()
#2 /var/www/www/wp-content/plugins/wp-sentry-integration/wp-sentry.php(99): WP_Sentry_Js_Tracker::get_instance()
#3 /var/www/www/wp-config.php(102): require_once('...')
#4 /var/www/www/wp-load.php(50): require_once('...')
#5 /var/www/www/wp-blog-header.php(13): require_once('...')
#6 /var/www/www/index.php(17): require('...')
#7 {main}
  thrown in /var/www/www/wp-content/plugins/wp-sentry-integration/src/class-wp-sentry-js-tracker.php on line 139

I do apologize if I sounded rude, that was not my intention

androidacy-user commented 2 years ago

https://github.com/stayallive/wp-sentry/blob/493626b7d73ac6a143320c0f0bf6df1b3958ab32/src/class-wp-sentry-js-tracker.php#L139-L140 is the problematic code. get_bloginfo() is not yet defined. I don't know of any other good way to get this information, so I've been hand editing to set those to static values

androidacy-user commented 2 years ago

Since that looks like the JS tracker, there's no reason to load it that early, and it would probably be safer to attempt to load it once we're in the WordPress env proper. You could, perhaps, add a couple action hooks so that logic doesn't get executed until we know we have the proper info ready.

stayallive commented 2 years ago

My apologies, in the rush trying to get multiple fixes out I totally forgot to even look at the JavaScript side assuming it worked (never assume, never rush).

This time it should be fixed in v4.10.2 that was just released. The JS tracker did way too much way to early anyway as you suspected.

androidacy-user commented 2 years ago

Waiting for the update to roll out to my site, but no problem. I do a bit of work with plugin development myself (custom plugin for some behind the scenes API interaction and authentication) myself, so i kinda get it. It's always the simple mistakes that get you the hardest 😆

stayallive commented 2 years ago

Yeah WordPress plugin repo is alway a little slow with the release processing, it'll get there!

Do let me know if it's broken still for some reason of course but I think I got all the "edge" cases this time 😄