function raven_page_attachments in Raven: Sentry Integration 3.x
Same name and namespace in other branches
- 8.2 raven.module \raven_page_attachments()
- 8 raven.module \raven_page_attachments()
Implements hook_page_attachments().
File
- ./
raven.module, line 15 - 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')) {
return;
}
// 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';
// Add performance tracing meta tag for attaching traces to errors.
if (!class_exists(SentrySdk::class) || !SentrySdk::getCurrentHub()
->getSpan()) {
return;
}
$placeholder = Crypt::randomBytesBase64();
$page['#attached']['html_head'][] = [
[
'#tag' => 'meta',
'#attributes' => [
'name' => 'sentry-trace',
'content' => $placeholder,
],
'#attached' => [
'placeholders' => [
$placeholder => [
'#create_placeholder' => TRUE,
'#lazy_builder' => [
'raven.request_subscriber:getTraceparent',
[],
],
],
],
],
],
'raven_sentry_trace',
];
}