You are here

public static function RavenConfigForm::buildForm in Raven: Sentry Integration 8.2

Same name and namespace in other branches
  1. 8 src/Form/RavenConfigForm.php \Drupal\raven\Form\RavenConfigForm::buildForm()
  2. 3.x 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']['fatal_error_handler_memory'] = [
    '#type' => 'number',
    '#title' => t('Reserved memory'),
    '#description' => t('Reserved memory for fatal error handler (KB).'),
    '#default_value' => $config
      ->get('fatal_error_handler_memory'),
    '#size' => 10,
    '#min' => 0,
  ];
  $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']['message_limit'] = [
    '#type' => 'number',
    '#title' => t('Message limit'),
    '#default_value' => $config
      ->get('message_limit'),
    '#description' => t('Log message maximum length in characters.'),
    '#size' => 10,
    '#min' => 0,
    '#step' => 1,
    '#required' => TRUE,
  ];
  $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!'),
  ];
  $form['raven']['php']['timeout'] = [
    '#type' => 'number',
    '#title' => t('Timeout'),
    '#default_value' => $config
      ->get('timeout'),
    '#description' => t('Connection timeout in seconds.'),
    '#size' => 10,
    '#min' => 0,
  ];
  $form['raven']['php']['ssl'] = [
    '#type' => 'radios',
    '#title' => t('SSL Verification'),
    '#default_value' => $config
      ->get('ssl'),
    '#options' => [
      'verify_ssl' => t('Verify SSL'),
      'ca_cert' => t('Verify against a CA certificate'),
      'no_verify_ssl' => t("Don't verify SSL (not recommended)"),
    ],
  ];
  $form['raven']['php']['ca_cert'] = [
    '#type' => 'textfield',
    '#title' => t('Path to CA certificate'),
    '#default_value' => $config
      ->get('ca_cert'),
    '#description' => t('Path to the CA certificate file of the Sentry server specified in the DSN.'),
    // Only visible when 'ssl' set to ca_cert.
    '#states' => [
      'visible' => [
        ':input[name="raven[php][ssl]"]' => [
          'value' => 'ca_cert',
        ],
      ],
    ],
  ];
  $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';
}