You are here

function raven_seckit_options_alter in Raven: Sentry Integration 7.4

Same name and namespace in other branches
  1. 7.3 raven.module \raven_seckit_options_alter()

Implements hook_seckit_options_alter().

File

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

Code

function raven_seckit_options_alter(&$options) {
  if (!class_exists(Dsn::class)) {
    return;
  }
  try {
    $dsn = Dsn::createFromString(empty($_SERVER['SENTRY_DSN']) ? variable_get('raven_public_dsn') : $_SERVER['SENTRY_DSN']);
  } catch (InvalidArgumentException $e) {

    // Raven is incorrectly configured.
    return;
  }
  $query = [
    'sentry_key' => $dsn
      ->getPublicKey(),
  ];
  if ($environment = empty($_SERVER['SENTRY_ENVIRONMENT']) ? variable_get('raven_environment') : $_SERVER['SENTRY_ENVIRONMENT']) {
    $query['sentry_environment'] = $environment;
  }
  if ($release = empty($_SERVER['SENTRY_RELEASE']) ? variable_get('raven_release') : $_SERVER['SENTRY_RELEASE']) {
    $query['sentry_release'] = $release;
  }
  $url = url(str_replace('/store/', '/security/', $dsn
    ->getStoreApiEndpointUrl()), [
    'query' => $query,
  ]);
  if (variable_get('raven_set_report_uri')) {
    $options['seckit_ct']['report-uri'] = $url;
    $options['seckit_xss']['csp']['report-uri'] = $url;
  }
  if (variable_get('raven_js_enabled', FALSE)) {
    $options['seckit_xss']['csp']['connect-src'] .= $options['seckit_xss']['csp']['connect-src'] ? " {$dsn->getStoreApiEndpointUrl()} {$dsn->getEnvelopeApiEndpointUrl()}" : "{$options['seckit_xss']['csp']['default-src']} {$dsn->getStoreApiEndpointUrl()} {$dsn->getEnvelopeApiEndpointUrl()}";
  }
}