function raven_test_page_attachments in Raven: Sentry Integration 3.x
Same name and namespace in other branches
- 8.2 tests/modules/raven_test.module \raven_test_page_attachments()
Implements hook_page_attachments().
File
- tests/
modules/ raven_test.module, line 11 - Raven test module.
Code
function raven_test_page_attachments(array &$attachments) {
$client = \Drupal::service('logger.raven')
->getClient();
$client
->getOptions()
->setBeforeSendCallback(function ($event) use (&$attachments) {
if (!empty($event
->getLogger()) && !empty($event
->getMessageFormatted())) {
$attachments['#attached']['http_header'][] = [
$event
->getLogger(),
$event
->getMessageFormatted(),
FALSE,
];
$frames = $event
->getStacktrace()
->getFrames();
$last_frame = end($frames);
$attachments['#attached']['http_header'][] = [
'X-Stacktrace-File',
$last_frame
->getFile(),
FALSE,
];
}
if (!empty($event
->getExceptions())) {
if (preg_match('/Allowed memory size of ([0-9]+) bytes exhausted/', $event
->getExceptions()[0]
->getValue(), $matches)) {
echo $matches[1];
}
}
});
\Drupal::logger('X-Logged')
->error('Logged');
\Drupal::logger('X-Not-Logged')
->error('Not logged');
\Drupal::logger('X-Logged')
->error('Logged');
if ($memory_limit = \Drupal::request()->query
->get('memory_limit')) {
ini_set('memory_limit', $memory_limit);
while (TRUE) {
$attachments[] = 1;
}
}
$attachments['#cache']['contexts'][] = 'url.query_args:memory_limit';
}