我们在很多项目中使用 Laravel(5.x 到 7.x),并且全部与 Sentry 集成。
在某些边缘情况下,我们需要捕获一些可恢复的异常,以允许页面流使用回退继续进行,但我们也希望将这些捕获的异常记录到哨兵。
我找不到手动登录 Sentry 的有记录或无记录的方法。
有没有办法将已经捕获的异常记录到哨兵?
^ 这是这样做的方法。
如果你想使用 Laravel 容器,它可能看起来更像这样:
try {
// your code that could throw an exception
} catch (\Throwable $e) {
if (app()->bound('sentry')) {
app('sentry')->captureException($e);
}
}
您还可以报告使用情况,这也应该将异常记录到您的日志文件中:
try {
// your code that could throw an exception
} catch (\Throwable $e) {
report($e); // this is a Laravel helper, not from Sentry
}
此外,您可以手动使用 Sentry 的助手 - 源代码在这里
\Sentry\captureMessage("This handle a text message");
// this handle everything derives from \Exception
\Sentry\captureException($e);
这在文档中:https://docs.sentry.io/platforms/php/#capturing-errors
您可以使用
Sentry\captureException
方法:
try {
$this->functionFailsForSure();
} catch (\Throwable $exception) {
Sentry\captureException($exception);
}
Duis adipisicing saedadsada reff2 2efavd rd