You are here

function raven_init in Raven: Sentry Integration 7

Same name and namespace in other branches
  1. 7.4 raven.module \raven_init()
  2. 7.2 raven.module \raven_init()
  3. 7.3 raven.module \raven_init()

Implements hook_init().

File

./raven.module, line 123
Allows to track errors to Sentry server.

Code

function raven_init() {
  if (!variable_get('raven_enabled', FALSE)) {
    return;
  }
  $client = _raven_get_client();
  if (!$client) {
    return;
  }

  // Get enabled error handlers.
  $exception_handler = variable_get('raven_exception_handler', TRUE);
  $fatal_error_handler = variable_get('raven_fatal_error_handler', TRUE);
  $error_handler = variable_get('raven_error_handler', TRUE);

  // Bind the logged in user.
  $user = array();
  drupal_alter('raven_user', $user);
  $client
    ->user_context($user);

  // Tag the request with something interesting.
  $tags = array();
  drupal_alter('raven_tags', $tags);
  $client
    ->tags_context($tags);

  // Provide a bit of additional context.
  $extra = array();
  drupal_alter('raven_extra', $extra);
  $client
    ->extra_context($extra);
  $raven_error_handler = _raven_get_error_handler();
  if ($exception_handler) {
    $raven_error_handler
      ->registerExceptionHandler();
  }
  if ($fatal_error_handler) {
    $reserved_memory = variable_get('raven_fatal_error_handler_memory', 2.5 * 1024);
    $raven_error_handler
      ->registerShutdownFunction($reserved_memory);
  }
  if ($error_handler) {
    $old_error_handler = set_error_handler('_raven_error_handler');
    $GLOBALS['_raven_old_error_handler'] = $old_error_handler;
  }
}