1
0
mirror of https://github.com/beestat/app.git synced 2025-05-24 02:14:03 -04:00

Added logging of API errors to Sentry.

This commit is contained in:
Jon Ziebell 2020-01-18 21:34:32 -05:00
parent 974d847707
commit 64d0a72252
2 changed files with 55 additions and 0 deletions

View File

@ -691,6 +691,55 @@ final class cora {
'error_extra_info' => $this->error_extra_info
]
];
$session = session::get_instance();
$user_id = $session->get_user_id();
if(isset($this->request['api_key']) === true) {
$api_user_resource = new api_user();
$api_users = $api_user_resource->read(['api_key' => $this->request['api_key']]);
$api_user_id = $api_users[0]['api_user_id'];
}
else {
$api_user_id = null;
}
// Send data to Sentry for error logging.
$data = [
'event_id' => str_replace('-', '', exec('uuidgen -r')),
'timestamp' => date('c'),
'logger' => 'cora',
'platform' => 'php',
'level' => 'error',
'tags' => [
'api_call' => 'foo',
'error_code' => $error_code
],
'extra' => [
'user_id' => $user_id,
'api_user_id' => $api_user_id,
'error_file' => $error_file,
'error_line' => $error_line,
'error_trace' => $error_trace
],
'exception' => [
'type' => 'Exception',
'value' => $error_message,
'handled' => false
]
];
exec(
'curl ' .
'-H "Content-Type: application/json" ' .
'-H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=' . $this->setting->get('sentry_key') . '" ' .
'--silent ' . // silent; keeps logs out of stderr
'--show-error ' . // override silent on failure
'--max-time 10 ' .
'--connect-timeout 5 ' .
'--data \'' . json_encode($data) . '\' ' .
'"https://sentry.io/api/' . $this->setting->get('sentry_project_id') . '/store/" > /dev/null &'
);
}
/**

View File

@ -163,6 +163,12 @@ final class setting {
'influx_database_username' => '',
'influx_database_password' => '',
/**
* Key and project id obtained from the Sentry DSN. See sentry.io.
*/
'sentry_key' => '',
'sentry_project_id' => '',
/**
* Whether or not SSL is required.
*/