You are here

function raven_page_attachments in Raven: Sentry Integration 8.2

Same name and namespace in other branches
  1. 8 raven.module \raven_page_attachments()
  2. 3.x raven.module \raven_page_attachments()

Implements hook_page_attachments().

File

./raven.module, line 13
Raven Drupal module.

Code

function raven_page_attachments(array &$page) {
  $config = \Drupal::config('raven.settings');
  if ($config
    ->get('javascript_error_handler') && \Drupal::currentUser()
    ->hasPermission('send javascript errors to sentry')) {

    // Other modules can attach Sentry browser client options to the page.
    if (!isset($page['#attached']['drupalSettings']['raven']['options'])) {
      $page['#attached']['drupalSettings']['raven']['options'] = new \stdClass();
    }
    $page['#attached']['drupalSettings']['raven']['options']->dsn = empty($_SERVER['SENTRY_DSN']) ? $config
      ->get('public_dsn') : $_SERVER['SENTRY_DSN'];
    $page['#attached']['drupalSettings']['raven']['options']->environment = empty($_SERVER['SENTRY_ENVIRONMENT']) ? $config
      ->get('environment') ?: \Drupal::getContainer()
      ->getParameter('kernel.environment') : $_SERVER['SENTRY_ENVIRONMENT'];
    if (!empty($_SERVER['SENTRY_RELEASE'])) {
      $page['#attached']['drupalSettings']['raven']['options']->release = $_SERVER['SENTRY_RELEASE'];
    }
    elseif ($release = $config
      ->get('release')) {
      $page['#attached']['drupalSettings']['raven']['options']->release = $release;
    }
    $page['#attached']['drupalSettings']['raven']['options']->integrations = [];
    if ($traces = $config
      ->get('browser_traces_sample_rate')) {
      $page['#attached']['drupalSettings']['raven']['options']->tracesSampleRate = $traces;
    }
    $page['#attached']['drupalSettings']['raven']['options']->autoSessionTracking = $config
      ->get('auto_session_tracking');
    $page['#attached']['drupalSettings']['raven']['options']->sendClientReports = $config
      ->get('send_client_reports');
    $page['#attached']['library'][] = 'raven/raven';
  }
}