You are here

function raven_init in Raven: Sentry Integration 7.4

Same name and namespace in other branches
  1. 7 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 48
Allows to track errors to Sentry server.

Code

function raven_init() {
  if (!variable_get('raven_enabled', FALSE) || !raven_get_client()) {
    return;
  }

  // Bind the logged-in user.
  \Sentry\configureScope(function (Scope $scope) : void {
    global $user;

    // Bind the logged in user.
    $context['id'] = $user->uid;
    $context['ip_address'] = ip_address();
    $context['roles'] = implode(', ', $user->roles);
    if (user_is_logged_in() && variable_get('raven_send_user_data', FALSE)) {
      $context['username'] = $user->name;
      $context['email'] = $user->mail;
    }
    drupal_alter('raven_user', $context);
    $scope
      ->setUser($context);
  });

  // Tag the request with something interesting.
  \Sentry\configureScope(function (Scope $scope) : void {
    $context = [];
    drupal_alter('raven_tags', $context);
    $scope
      ->setTags($context);
  });

  // Provide a bit of additional context.
  \Sentry\configureScope(function (Scope $scope) : void {
    $context = [];
    drupal_alter('raven_extra', $context);
    $scope
      ->setExtras($context);
  });
}