You are here

function _raven_get_client in Raven: Sentry Integration 7

Returns an instance of the Raven PHP client.

Return value

Raven_Client Raven PHP client library instance.

4 calls to _raven_get_client()
raven_init in ./raven.module
Implements hook_init().
raven_settings_form in ./raven.admin.inc
Returns set settings form for Raven.
raven_watchdog in ./raven.module
Implements hook_watchdog().
_raven_get_error_handler in ./raven.module
Returns an instance of the Raven PHP error handler.

File

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

Code

function _raven_get_client() {
  static $client;
  if (!isset($client)) {
    if (!raven_libraries_load()) {
      return;
    }

    // Prepare config.
    $dsn = variable_get('raven_dsn', NULL);
    $timeout = variable_get('raven_timeout', 2);
    $stack = variable_get('raven_stack', TRUE);
    $trace = variable_get('raven_trace', FALSE);

    // Build the field sanitization regular expression.
    $fields = array(
      'SESS',
      'key',
      'token',
      'pass',
      'authorization',
      'password',
      'passwd',
      'secret',
      'password_confirmation',
      'card_number',
      'auth_pw',
    );
    drupal_alter('raven_sanitize_fields', $fields);
    $fields_re = '/(' . implode('|', $fields) . ')/i';
    $options = array(
      'timeout' => $timeout,
      'auto_log_stacks' => $stack,
      'trace' => $trace,
      'tags' => array(
        'php_version' => phpversion(),
      ),
      'processorOptions' => array(
        'Raven_SanitizeDataProcessor' => array(
          'fields_re' => $fields_re,
        ),
      ),
      'curl_method' => 'async',
      'verify_ssl' => TRUE,
    );
    $raven_ssl = variable_get('raven_ssl', 'verify_ssl');

    // Verify against a CA certificate.
    if ($raven_ssl == 'ca_cert') {
      $options['ca_cert'] = drupal_realpath(variable_get('raven_ca_cert', ''));
    }
    elseif ($raven_ssl == 'no_verify_ssl') {
      $options['verify_ssl'] = FALSE;
    }

    // Instantiate a new client with a compatible DSN.
    $client = new Raven_Client($dsn, $options);
  }
  return $client;
}