You are here

function raven_library in Raven: Sentry Integration 7.2

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

Implements hook_library().

File

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

Code

function raven_library() {
  global $user;
  $libraries['raven']['version'] = '3.27.2';
  $path = drupal_get_path('module', 'raven');
  if (variable_get('raven_js_source', 'library') == 'cdn') {
    $libraries['raven']['js'][variable_get('raven_js_cdn_url')] = array(
      'type' => 'external',
    );
  }
  else {
    $libraries['raven']['js']["{$path}/js/raven-js/raven.min.js"] = array();
  }
  $options = new stdClass();
  if (!empty($_SERVER['SENTRY_RELEASE'])) {
    $options->release = $_SERVER['SENTRY_RELEASE'];
  }
  elseif ($release = variable_get('raven_release')) {
    $options->release = $release;
  }
  if (!empty($_SERVER['SENTRY_ENVIRONMENT'])) {
    $options->environment = $_SERVER['SENTRY_ENVIRONMENT'];
  }
  elseif ($environment = variable_get('raven_environment')) {
    $options->environment = $environment;
  }
  $libraries['raven']['js'][] = array(
    'data' => array(
      'raven' => array(
        'dsn' => empty($_SERVER['SENTRY_DSN']) ? variable_get('raven_public_dsn', '') : $_SERVER['SENTRY_DSN'],
        // Other modules can alter the Raven.js options.
        'options' => $options,
        'user' => array(
          'id' => $user->uid,
        ),
      ),
    ),
    'type' => 'setting',
  );
  $libraries['raven']['js']["{$path}/js/raven.js"] = array(
    // Load in the footer to ensure settings are available.
    'scope' => 'footer',
  );
  return $libraries;
}