Skip to content

Instantly share code, notes, and snippets.

@bbelyeu
Created June 17, 2013 17:25
Show Gist options
  • Save bbelyeu/5798569 to your computer and use it in GitHub Desktop.
Save bbelyeu/5798569 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
/**
* @package YouVersion_API
*/
Event::add('system.ready', 'sentry_setup');
function sentry_setup()
{
// Setup an ad-hoc rate limiting system for logging
// errors to Sentry app so we don't cross our daily limit
// Pick a random number
$rate_limiting_rand = rand(1, 25);
// Instead of a % operation, we'll just check if the
// random number equals a specific value in the middle
// of the range since we picked a range for the random
// number generator.
//$log_exceptions_for_request = ($rate_limiting_rand === 12);
$log_exceptions_for_request = TRUE;
// Always run these two lines of code so that we
// log Sentry exceptions as needed from model methods
require(MODPATH . 'core/libraries/Raven/Autoloader.php');
Raven_Autoloader::register();
if (($_SERVER['PHP_ENV'] != 'prod') || ($log_exceptions_for_request === TRUE))
{
// YouVersion API Dev DSN Hard-coded for Testing
$sentry_dsn = $_SERVER['SENTRY_DSN'];
$options = array(
'exclude' => array('Kohana_404_Exception'),
'timeout' => 1,
);
$client = new Raven_Client($sentry_dsn, $options);
$error_handler = new Raven_ErrorHandler($client);
// Register exception & error handler callbacks
$call_existing_exception_handler = TRUE;
$error_handler->registerExceptionHandler($call_existing_exception_handler);
$call_existing_error_handler = TRUE;
$error_types = E_ALL;
$error_handler->registerErrorHandler($call_existing_error_handler, $error_types);
$error_handler->registerShutdownFunction();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment