You are here

function raven_init in Raven: Sentry Integration 7.3

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

Implements hook_init().

File

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

Code

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

  // Bind the logged in user.
  $context['id'] = $user->uid;
  $context['ip_address'] = ip_address();
  $context['roles'] = implode(', ', $user->roles);
  if (user_is_logged_in()) {
    $context['name'] = $user->name;
    $context['email'] = $user->mail;
  }
  drupal_alter('raven_user', $context);
  $client
    ->user_context($context);

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

  // Provide a bit of additional context.
  $context = array();
  drupal_alter('raven_extra', $context);
  $client
    ->extra_context($context);
}