简介
Sentry 是什么?中文翻译过来是 哨兵
的意思,从字面中可以知道 『站岗、放哨、巡逻、稽查的士兵』,不错,Sentry 是程序的 哨兵
,它可以监控我们在生产环境中项目的运行状态,一旦某段代码运行报错,或者异常,会第一时间把报错的 路由
,异常文件
,请求方式
等一些非常详细的信息以消息或者邮件给我们,让我们第一时间知道:程序出错了
,然后我们可以从 Sentry
给我们的详细的错误信息中瞬间找到我们需要处理的代码,在老板不知情的情况下悄悄把 Bug
修复调,你肯定不想等着老板来找你吧。
开始
你如果试用 Sentry 官方提供给你的服务是需要收费的,不过可以免费试用,当然你也可以自己搭建 Sentry
:文档 自行搭建当然就不收费啦。文档最下方有两种安装方式一个是 docker
一个是 python
,Docker 安装 Here,Python 安装 Here
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048625-5150-171246ad334266c4.png)
这是 Sentry 的官网,我们先不管来体验一把,注册一个账号
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048638-5100-171246ad33f65730.png)
准备完毕之后先看文档,其实官方给出的文档非常详细
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048633-4037-171246ad343095c1.png)
选择我们大爱的 PHP Laravel 框架,
拉取
$ composer require sentry/sentry-laravel
复制代码
添加进服务提供者和门面
'providers' => array(
// ...
Sentry\SentryLaravel\SentryLaravelServiceProvider::class,
)
'aliases' => array(
// ...
'Sentry' => Sentry\SentryLaravel\SentryFacade::class,
)
复制代码
然后在 App/Exceptions/Handler.php
report
修改如下方法
public function report(Exception $exception)
{
if ($this->shouldReport($exception)) {
app('sentry')->captureException($exception);
}
parent::report($exception);
}
复制代码
生成配置文件, 配置文件在 config/sentry.php
中
$ php artisan vendor:publish --provider="Sentry\SentryLaravel\SentryLaravelServiceProvider"
复制代码
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048641-9135-171246ad35851278.png)
在配置文件中 dsn
就在我们看的文档下方,每个用户的 dsn 都是唯一的,在你的项目中配置了 dsn ,Sentry 就能监控你的项目。
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048626-1818-171246ad366b21e7.png)
好了基本配置就这么完事儿,然后现在我们访问当前项目,然后在路由上面乱输入一通。
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048640-6092-171246ad376fd56f.png)
我们会及时收到错误反馈
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048632-3270-171246ad6e2c8ecc.png)
当然也会往我们的邮箱里面发送
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048626-1887-171246ad710ab8bf.png)
并且非常详细!!
Sentry 可以和澳大利亚公司旗下的产品 HipChat 互相通信 www.atlassian.com/software
![](https://pic.ithothub.com/wp-content/uploads/2020/04/1587048642-3938-171246ad71be8fe0.png)
HipChat 也会受到 Sentry
的错误消息 ^_^
End !
评论前必须登录!
注册