raven_test.module in Raven: Sentry Integration 8.2
Same filename and directory in other branches
Raven test module.
File
tests/modules/raven_test.moduleView source
<?php
/**
* @file
* Raven test module.
*/
use Drupal\Component\Serialization\Json;
/**
* Implements hook_page_attachments().
*/
function raven_test_page_attachments(array &$attachments) {
$client = \Drupal::service('logger.raven')->client;
$client
->setSendCallback(function ($data) use (&$attachments) {
if (!empty($data['logger']) && !empty($data['sentry.interfaces.Message']['formatted'])) {
$attachments['#attached']['http_header'][] = [
$data['logger'],
$data['sentry.interfaces.Message']['formatted'],
FALSE,
];
$last_frame = end($data['stacktrace']['frames']);
$attachments['#attached']['http_header'][] = [
'X-Stacktrace-File',
$last_frame['filename'],
FALSE,
];
if (isset($data['request']['cookies'])) {
$attachments['#attached']['http_header'][] = [
$data['logger'] . '-Cookies',
Json::encode($data['request']['cookies']),
FALSE,
];
}
}
if (!empty($data['exception']['values'][0]['value'])) {
if (preg_match('/Allowed memory size of ([0-9]+) bytes exhausted/', $data['exception']['values'][0]['value'], $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')) {
$client = \Drupal::service('logger.raven')->client;
// Output number of pending requests at end of request.
drupal_register_shutdown_function(function () use (&$client) {
$reflectedPendingEvents = (new \ReflectionObject($client))
->getProperty('_pending_events');
$reflectedPendingEvents
->setAccessible(TRUE);
$pendingEvents = $reflectedPendingEvents
->getValue($client);
echo count($pendingEvents);
$reflectedCurlHandler = (new \ReflectionObject($client))
->getProperty('_curl_handler');
$reflectedCurlHandler
->setAccessible(TRUE);
$curlHandler = $reflectedCurlHandler
->getValue($client);
$reflectedPendingRequests = (new \ReflectionObject($curlHandler))
->getProperty('requests');
$reflectedPendingRequests
->setAccessible(TRUE);
$pendingRequests = $reflectedPendingRequests
->getValue($curlHandler);
echo count($pendingRequests);
});
ini_set('memory_limit', (int) $memory_limit);
while (TRUE) {
$attachments[] = 1;
}
}
$attachments['#cache']['contexts'][] = 'url.query_args:memory_limit';
}
/**
* Implements hook_raven_filter_alter().
*/
function raven_test_raven_filter_alter(&$filter) {
if ($filter['context']['channel'] === 'X-Not-Logged') {
$filter['process'] = FALSE;
}
}
Functions
Name | Description |
---|---|
raven_test_page_attachments | Implements hook_page_attachments(). |
raven_test_raven_filter_alter | Implements hook_raven_filter_alter(). |