You are here

public static function RavenConfigForm::buildForm in Raven: Sentry Integration 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/RavenConfigForm.php \Drupal\raven\Form\RavenConfigForm::buildForm()
  2. 8 src/Form/RavenConfigForm.php \Drupal\raven\Form\RavenConfigForm::buildForm()

Builds Raven config form.

1 call to RavenConfigForm::buildForm()
raven_form_system_logging_settings_alter in ./raven.module
Implements hook_form_system_logging_settings_alter().

File

src/Form/RavenConfigForm.php, line 17

Class

RavenConfigForm
Implements a Raven Config form.

Namespace

Drupal\raven\Form

Code

public static function buildForm(array &$form) {
  $config = \Drupal::config('raven.settings');
  $form['raven'] = [
    '#type' => 'details',
    '#title' => t('Sentry'),
    '#tree' => TRUE,
    '#open' => TRUE,
  ];
  $form['raven']['js'] = [
    '#type' => 'details',
    '#title' => t('JavaScript'),
    '#open' => TRUE,
  ];
  $form['raven']['js']['javascript_error_handler'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable JavaScript error handler'),
    '#description' => t('Check to capture JavaScript errors (if user has the <a target="_blank" href=":url">send JavaScript errors to Sentry</a> permission).', [
      ':url' => Url::fromRoute('user.admin_permissions', [], [
        'fragment' => 'module-raven',
      ])
        ->toString(),
    ]),
    '#default_value' => $config
      ->get('javascript_error_handler'),
  ];
  $form['raven']['js']['public_dsn'] = [
    '#type' => 'textfield',
    '#title' => t('Sentry DSN'),
    '#default_value' => $config
      ->get('public_dsn'),
    '#description' => t('Sentry client key for current site. This setting can be overridden with the SENTRY_DSN environment variable.'),
  ];
  $form['raven']['js']['browser_traces_sample_rate'] = [
    '#type' => 'number',
    '#title' => t('Browser performance tracing sample rate'),
    '#default_value' => $config
      ->get('browser_traces_sample_rate'),
    '#description' => t('Set the browser performance tracing sample rate, or set to 0 to disable performance tracing.'),
    '#min' => 0,
    '#max' => 1,
    '#step' => 1.0E-6,
  ];
  $form['raven']['js']['auto_session_tracking'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable auto session tracking'),
    '#description' => t('Check to monitor release health by sending a session event to Sentry for each page load; only active if a release is specified below or via the SENTRY_RELEASE environment variable.'),
    '#default_value' => $config
      ->get('auto_session_tracking'),
  ];
  $form['raven']['js']['send_client_reports'] = [
    '#type' => 'checkbox',
    '#title' => t('Send client reports'),
    '#description' => t('Send client report (e.g. number of discarded events), if any, when tab is hidden or closed.'),
    '#default_value' => $config
      ->get('send_client_reports'),
  ];
  $form['raven']['php'] = [
    '#type' => 'details',
    '#title' => t('PHP'),
    '#open' => TRUE,
  ];
  $form['raven']['php']['client_key'] = [
    '#type' => 'textfield',
    '#title' => t('Sentry DSN'),
    '#default_value' => $config
      ->get('client_key'),
    '#description' => t('Sentry client key for current site. This setting can be overridden with the SENTRY_DSN environment variable.'),
  ];

  // "0" is not a valid checkbox option.
  $log_levels = [];
  foreach (RfcLogLevel::getLevels() as $key => $value) {
    $log_levels[$key + 1] = $value;
  }
  $form['raven']['php']['log_levels'] = [
    '#type' => 'checkboxes',
    '#title' => t('Log levels'),
    '#default_value' => $config
      ->get('log_levels'),
    '#description' => t('Check the log levels that should be captured by Sentry.'),
    '#options' => $log_levels,
  ];
  $form['raven']['php']['ignored_channels'] = [
    '#type' => 'textarea',
    '#title' => t('Ignored channels'),
    '#description' => t('A list of log channels for which messages will not be sent to Sentry (one channel per line). Commonly-configured log channels include <em>access denied</em> for 403 errors and <em>page not found</em> for 404 errors.'),
    '#default_value' => implode("\n", $config
      ->get('ignored_channels') ?: []),
  ];
  $form['raven']['php']['fatal_error_handler'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable fatal error handler'),
    '#description' => t('Check to capture fatal PHP errors.'),
    '#default_value' => $config
      ->get('fatal_error_handler'),
  ];
  $form['raven']['php']['drush_error_handler'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable Drush error handler'),
    '#description' => t('Check to capture errors thrown by Drush commands.'),
    '#default_value' => $config
      ->get('drush_error_handler'),
  ];
  $form['raven']['php']['stack'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable stacktraces'),
    '#default_value' => $config
      ->get('stack'),
    '#description' => t('Check to add stacktraces to reports.'),
  ];
  $form['raven']['php']['trace'] = [
    '#type' => 'checkbox',
    '#title' => t('Reflection tracing in stacktraces'),
    '#default_value' => $config
      ->get('trace'),
    '#description' => t('Check to enable reflection tracing (function calling arguments) in stacktraces. Warning: This setting allows sensitive data to be logged by Sentry! To enable for exception stacktraces, PHP configuration flag zend.exception_ignore_args must be disabled.'),
  ];
  $form['raven']['php']['send_user_data'] = [
    '#type' => 'checkbox',
    '#title' => t('Send user data to Sentry'),
    '#default_value' => $config
      ->get('send_user_data'),
    '#description' => t('Check to send user email and username to Sentry with each event. Warning: User data can still be sent to Sentry even when this setting is disabled, for example as part of a log message or request body. Custom code is required to scrub personally-identifying information from events before they are sent.'),
  ];
  $form['raven']['php']['send_request_body'] = [
    '#type' => 'checkbox',
    '#title' => t('Send request body to Sentry'),
    '#default_value' => $config
      ->get('send_request_body'),
    '#description' => t('Check to send the request body (POST data) to Sentry. Warning: This setting allows sensitive data to be logged by Sentry!'),
  ];
  $form['raven']['php']['rate_limit'] = [
    '#type' => 'number',
    '#title' => t('Rate limit'),
    '#default_value' => $config
      ->get('rate_limit'),
    '#description' => t('Maximum log events sent to Sentry per-request or per-execution. To disable the limit, set to zero. You may need to set a limit if you have buggy code which generates a large number of log messages.'),
    '#min' => 0,
    '#step' => 1,
  ];
  $form['raven']['php']['performance'] = [
    '#type' => 'details',
    '#title' => t('Performance tracing'),
    '#open' => TRUE,
  ];
  $form['raven']['php']['performance']['request_tracing'] = [
    '#type' => 'checkbox',
    '#title' => t('Request/response performance tracing'),
    '#default_value' => $config
      ->get('request_tracing'),
    '#description' => t('Check to enable performance tracing on the server side for each request/response, excluding pages served from the page cache.'),
  ];
  $form['raven']['php']['performance']['database_tracing'] = [
    '#type' => 'checkbox',
    '#title' => t('Database performance tracing'),
    '#default_value' => $config
      ->get('database_tracing'),
    '#description' => t('Check to add database queries to request/response performance tracing.'),
  ];
  $form['raven']['php']['performance']['twig_tracing'] = [
    '#type' => 'checkbox',
    '#title' => t('Twig performance tracing'),
    '#default_value' => $config
      ->get('twig_tracing'),
    '#description' => t('Check to add Twig templates to request/response performance tracing.'),
  ];
  $form['raven']['php']['performance']['traces_sample_rate'] = [
    '#type' => 'number',
    '#title' => t('Performance tracing sample rate'),
    '#default_value' => $config
      ->get('traces_sample_rate'),
    '#description' => t('Set the performance tracing sample rate, or set to 0 to disable performance tracing.'),
    '#min' => 0,
    '#max' => 1,
    '#step' => 1.0E-6,
  ];
  $form['raven']['environment'] = [
    '#type' => 'textfield',
    '#title' => t('Environment'),
    '#default_value' => $config
      ->get('environment'),
    '#description' => t('The environment in which this site is running (leave blank to use kernel.environment parameter). This setting can be overridden with the SENTRY_ENVIRONMENT environment variable.'),
  ];
  $form['raven']['release'] = [
    '#type' => 'textfield',
    '#title' => t('Release'),
    '#default_value' => $config
      ->get('release'),
    '#description' => t('The release this site is running (could be a version or commit hash). This setting can be overridden with the SENTRY_RELEASE environment variable.'),
  ];
  $form['#submit'][] = 'Drupal\\raven\\Form\\RavenConfigForm::submitForm';
}