-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsentry.module
More file actions
executable file
·120 lines (103 loc) · 2.93 KB
/
Copy pathsentry.module
File metadata and controls
executable file
·120 lines (103 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* @file
* Integration with the Sentry event logging platform via the Raven-PHP library.
*/
/**
* Implements hook_boot().
*/
function sentry_boot() {
$client = sentry_get_client();
if ($client) {
$error_handler = new Raven_ErrorHandler($client, TRUE);
$error_handler->registerExceptionHandler();
$error_handler->registerErrorHandler();
$error_handler->registerShutdownFunction();
}
}
/**
* Implements hook_watchdog().
*/
function sentry_watchdog($log_entry) {
if ($log_entry['severity'] <= variable_get('sentry_severity', WATCHDOG_ERROR)) {
$client = sentry_get_client();
if ($client) {
if (!is_array($log_entry['variables'])) {
$log_entry['variables'] = array();
}
$message = t($log_entry['message'], $log_entry['variables']);
$message = strip_tags($message);
$severity_levels = watchdog_severity_levels();
// Get trace of original watchdog call.
$stack = array_slice(debug_backtrace(), 3);
$module = '';
// Set a file name if provided.
if (isset($stack[0]['file'])) {
$module .= $stack[0]['file'];
}
// Set a line nuumber if provided.
if (isset($stack[0]['line'])) {
$module .= ':' . $stack[0]['line'];
}
$data = array(
'message' => $message,
'level' => sentry_severity_watchdog_to_sentry($log_entry['severity']),
'sentry.interfaces.Exception' => array(
'value' => $message,
'type' => 'watchdog',
'module' => $module,
),
'extra' => array(
'watchdog type' => $log_entry['type'],
'watchdog severity' => $severity_levels[$log_entry['severity']],
'watchdog uid' => isset($log_entry['user']) ? $log_entry['user']->uid : 0,
),
);
$client->capture($data, $stack);
}
}
}
/**
* Returns a sentry client.
*/
function sentry_get_client() {
static $client = FALSE;
if ($client === FALSE) {
sentry_require();
$sentry_dsn = variable_get('sentry_dsn', FALSE);
if ($sentry_dsn === FALSE) {
return FALSE;
}
$client = new Raven_Client($sentry_dsn);
$client->store_errors_for_bulk_send = TRUE;
}
return $client;
}
/**
* Maps watchdog severity levels to Sentry severity levels.
*/
function sentry_severity_watchdog_to_sentry($watchdog_severity) {
sentry_require();
$map = array(
WATCHDOG_EMERGENCY => Raven_Client::FATAL,
WATCHDOG_ALERT => Raven_Client::ERROR,
WATCHDOG_CRITICAL => Raven_Client::ERROR,
WATCHDOG_ERROR => Raven_Client::ERROR,
WATCHDOG_WARNING => Raven_Client::WARNING,
);
if (isset($map[$watchdog_severity])) {
return $map[$watchdog_severity];
}
return Raven_Client::WARNING;
}
/**
* Get Sentry.
*/
function sentry_require() {
static $required = FALSE;
if (!$required) {
require_once dirname(__FILE__) . '/lib/raven-php/lib/Raven/Autoloader.php';
Raven_Autoloader::register();
$required = TRUE;
}
}