Kirby

Global variable for sentry error logging

I am trying to setup sentry error logging.
The docs say: https://docs.sentry.io/clients/php/

The most important part is the creation of the raven client. Create it once and reference it from anywhere you want to interface with Sentry. Once you have the client you can either use it manually or enable the automatic error and exception capturing which is recommended:

$client = new Raven_Client('https://<key>@sentry.io/<project>');
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler();
$error_handler->registerErrorHandler();
$error_handler->registerShutdownFunction();

So I tried to put this in a plugin site/plugins/sentry/index.php

But when I try to use this in ex. a controller I get:

Undefined variable: client

Where should I put the code or how can I hook into kirbys error handling, so that an error is sent to sentry when a exception in kirby occurs?

you could add a site method to your plugin returning the raven client variable.

Or just a function…