Sentry的异常上报分为两种方式:
捕获全部异常:
$this->sentryClient->install();
捕获指定异常:
$error_handler = new Raven_ErrorHandler($sentryClient);
//捕获已经预料到的异常
$error_handler->registerExceptionHandler();
//捕获未预料到的异常
$error_handler->registerErrorHandler();
//捕获registerShutdownFunction异常,一般是程序异常终止,例如终止脚本等。
$error_handler->registerShutdownFunction();
分captureException和captureMessage两个方法
captureException:
try {
$num=0;
echo 1 / $num;
} catch (Exception $e) {
$sentryClient->captureException($e);
}
captureMessage:
//上报一条消息
$sentryClient->captureMessage('test message');
captureMessage携带参数:
$sentryClient->captureMessage('my %s message', array('loooooo','ssssss'), array(
//消息指纹,用于消息的分类
'fingerprint' => ['2'],
//消息级别
'level' => 'error',
//logger标签
'logger' => 'default',
//手动添加标签
'tags' => array('crontab' => 'xujaintao'),
//显示在用户数据,如果不设置就自动捕获
'user' => array(
'id' => 42,
'email' => 'clever-girl'
),
//额外数据
'extra' => array(
'tester' => 'echo',
),
));