====== sentry Plugin ====== ---- plugin ---- description: Log errors to Sentry author : Andreas Gohr, Michael Große email : dokuwiki@cosmocode.de type : action, helper lastupdate : 2020-07-02 compatible : Greebo depends : conflicts : similar : tags : logging, devel downloadurl: https://github.com/cosmocode/dokuwiki-plugin-sentry/zipball/master bugtracker : https://github.com/cosmocode/dokuwiki-plugin-sentry/issues sourcerepo : https://github.com/cosmocode/dokuwiki-plugin-sentry/ donationurl: screenshot_img : ---- [[https://www.cosmocode.de/en/open-source/dokuwiki-plugins/|{{ http://cosmocode.de/static/img/dokuwiki/dwplugins.png?recache|A CosmoCode Plugin}}]] This plugin will log errors and exceptions in DokuWiki's PHP backend and the JavaScript frontend to a Sentry instance. You can either use [[https://sentry.io|sentry.io]] or a self hosted instance. ===== Installation ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. **Privacy Info:** when you install this plugin in a live wiki, you probably need to inform your users that their personal information (username, email, IP-Address, browser info) is logged to Sentry in case of an unforeseen error. Sentry also offers some detailed setting to configure how long personal data is retained. **Changes** {{rss>https://github.com/cosmocode/dokuwiki-plugin-sentry/commits/master.atom date}} ===== Configuration ===== Use the extension manager and configure the DSN to you sentry project. You can find it under //Project// -> //Settings// -> //Client Keys//. It should look like this: ''%%https://:@/%%''. You can configure which kind of errors should be logged via the ''errors'' configuration setting. It defaults to what is set for PHP's [[phpfn>error_reporting]] and accepts the same integer. You can use this [[https://maximivanov.github.io/php-error-reporting-calculator/|calculator]] to figure out the value you want. The ''env'' variable allows you to easily differentiate between multiple wikis being logged into the same Sentry. This is useful when you have a local development and a live wiki for example. ===== Usage ===== Once installed and configured, it will log all unhandled errors to Sentry automatically. You can also use it in your code for specialized logging. ==== PHP ==== To log an error use the helper plugin: try { // some code } catch(\Exception $e) { $sentry = plugin_load('helper', 'sentry'); if($sentry) $sentry->logException($e); msg(hsc($e->getMessage()), -1); } The helper plugin exposes some more public methods in case you need more control. You can also use the following to log an arbitrary message and additional data. (Useful when debugging problems on a live server): $sentry = plugin_load('helper','sentry'); if($sentry) { $sentry->logMessage('my log message', array( 'something' => $info) ); } ==== JavaScript ==== To log an error, call the ''SentryPlugin.logSentryException()'' method. try { // some code } catch(error) { window.SentryPlugin && SentryPlugin.logSentryException(error, {}); console.log(error) }