摘要:注册登录登录创建选择安装扩展使用方法来自配置获取测试少写个分号查看效果发送到对象当方法调用时执行资源你也可以本地搭建之部署到生产环境搭建自己的服务基于安装自
注册登录
GitHub登录
创建project 选择 laravel
composer require sentry/sentry-laravel
php artisan vendor:publish --provider="SentrySentryLaravelSentryLaravelServiceProvider"
</>复制代码
public function report(Exception $exception)
{
if (app()->bound("sentry") && $this->shouldReport($exception)) {
app("sentry")->captureException($exception);
}
parent::report($exception);
}
vi config/sentry.php
return array(
"dsn" => env("DSN"),
// capture release as git sha
// "release" => trim(exec("git log --pretty="%h" -n1 HEAD")),
// Capture bindings on SQL queries
"breadcrumbs.sql_bindings" => true,
// Capture default user context
"user_context" => false,
//transport function https://docs.sentry.io/clients/php/config/
"transport"=>new AppSentryTransport(),
);
vi /app/SentryTransport.php
namespace App;
//
class SentryTransport
{
public static function __set_state($array){
return function($raven_client,$data){
Queue::pushOn("sentry_log",new AppCommandssentry($raven_client,$data));
};
}
}
vi app/commands/sentry.php
class sentry extends Command implements SelfHandling, ShouldBeQueued {
use InteractsWithQueue, SerializesModels;
private $raven_client;
protected $data;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct($raven_client, $data)
{
$raven_client->setTransport(null);
$raven_client->close_curl_resource();
$this->raven_client=$raven_client;
$this->data=$data;
}
/**
* Execute the command.
*
* @return void
*/
public function handle()
{
$this->raven_client->send($this->data);//send方法来自 /vendor/sentry/sentry/lib/Raven/Client.php:1019
}
}
vi /vendor/sentry/sentry/lib/Raven/Client.php
public function send(&$data)
{
if (is_callable($this->send_callback)
&& call_user_func_array($this->send_callback, array(&$data)) === false
) {
// if send_callback returns false, end native send
return;
}
if (!$this->server) {
return;
}
if ($this->transport) {
call_user_func($this->transport, $this, $data);
return;
}
// should this event be sampled?
if (rand(1, 100) / 100.0 > $this->sample_rate) {
return;
}
$message = $this->encode($data);
$headers = array(
"User-Agent" => static::getUserAgent(),
"X-Sentry-Auth" => $this->getAuthHeader(),
"Content-Type" => "application/octet-stream"
);
$this->send_remote($this->server, $message, $headers);
}
配置dsn
获取 dsn
测试少写个分号,查看效果
</>复制代码
composer require monolog/monolog
vi config/app.php
"AppProviderssentrylog"
vi AppProviderssentrylog.php
use MonologHandlerRedisHandler;
use MonologFormatterJsonFormatter;
use MonologFormatterLineFormatter;
use MonologProcessorMemoryPeakUsageProcessor;
use MonologProcessorWebProcessor;
use MonologHandlerRavenHandler;
class sentrylog extends ServiceProvider {
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot() {
$logger = Log::getMonolog();
$handler = new RedisHandler($redis, "sentry:monolog", MonologLogger::DEBUG);
$handler->setFormatter(new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES, true));
$handler->pushProcessor(new MemoryPeakUsageProcessor(true));
/*$logger->pushProcessor(function ($record) {
$record["extra"]["dummy"] = "Hello world!";
return $record;
});
class MemoryPeakUsageProcessor extends MemoryProcessor
{
/**
* @param array $record 对象当方法调用时执行
* @return array
*/
public function __invoke(array $record)
{
$bytes = memory_get_peak_usage($this->realUsage);
$formatted = $this->formatBytes($bytes);
$record["extra"]["memory_peak_usage"] = $formatted;
return $record;
}
}*/
$arr = [
"uri" => "REQUEST_URI",
"ip" => "REMOTE_ADDR",
"method" => "REQUEST_METHOD",
"query_string" => "QUERY_STRING",
"cookie" => "HTTP_COOKIE",
"host" => "HTTP_HOST",
];
$handler->pushProcessor(new WebProcessor(null, $arr));
$logger->pushHandler($handler);
}
/**
* Register the application services.
*
* @return void
*/
public function register() {
//
}
}
vi app/commands/sentry_monolog.php
use MonologHandlerRavenHandler;
while (true) {
$data = $redis->lpop("sentry:monolog");
if (!$data) {
sleep(5);
continue;
}
$data = json_decode($data, true);
$raven_client= new Raven_Client($dsn,["extra" => $data["extra"]]);
$raven_hanlder = new RavenHandler($raven_client);
$raven_hanlder->handle($data);//https://pagerefresh.co.uk/apigen/monolog/class-Monolog.Handler.RavenHandler.html vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php:handle vendor/monolog/monolog/src/Monolog/Handler/RavenHandler.php :write
$raven_client->__destruct();
}
资源
你也可以本地搭建
Sentry 之部署到生产环境
搭建自己的 sentry 服务
CentOS6 基于 Python 安装 Sentry
Sentry 自动化异常提醒
Laravel学习笔记之Errors Tracking神器——Sentry
sentry使用
利用 entry/onpremise 搭建一个 Sentry 异常汇总工具
高效利用Sentry追踪日志发现问题
sentry monolog
Sentry - 处理异常日志的正确姿势
Sentry监控Django应用并使用email+钉钉通知
搭建私有的前端监控服务: sentry
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/29567.html
摘要:中异常处理类主要包含两个方法和,其中就是主要用来向第三方发送异常报告,这里选择向这个神器发送异常报告,并使用通知开发人员。通过也能发现的执行流程。 说明:Laravel学习笔记之bootstrap源码解析中聊异常处理时提到过Sentry这个神器,并打算以后聊聊这款神器,本文主要就介绍这款Errors Tracking神器Sentry,Sentry官网有一句话个人觉得帅呆了: Stop ...
摘要:查阅官方文档后得知,新版为了防止对象的序列化反序列化漏洞被利用,不再对值进行自动的序列化和反序列化处理。举个栗子更新到后,因为不再自动对值进行序列化处理,而只能加密字符串数据,这个时候程序就会抛出错误。 最近手残升级了项目里 Laravel 的小版本号(v5.5.39 => v5.5.45),这不升级则已,一升级就出了问题! Sentry 平台上提示错误:openssl_encrypt...
摘要:简介另一个令人喜欢的地方,是拥有活跃的开发者社区,而活跃的开发者社区带来的,是繁华的扩展包生态该项目统计了目前下载量最高的个扩展包。记得哟相信下面这些扩展包会让你的编码更加高效。排名下载量排名包地址下载次数描述图片处理。 简介 Laravel 另一个令人喜欢的地方,是拥有活跃的开发者社区,而活跃的开发者社区带来的,是繁华的扩展包生态 ———— @Summer 该项目统计了目前 pack...
摘要:现在的提供了一种更易于使用和维护的计划任务方式。注意事项建议开启这样会极大的加速类的加载。 lumen 为速度而生的 Laravel 框架 官网的介绍很简洁,而且 lumen 确实也很简单,我在调研了 lumen 相关组件(比如缓存,队列,校验,路由,中间件和最重要的容器)之后认为已经能够满足我目前这个微服务的需求了。 任务目标 showImg(https://segmentfault...
摘要:请求未通过的验证时会抛出此异常。异常处理是非常重要但又容易让开发者忽略的功能,这篇文章简单解释了内部异常处理的机制以及扩展异常处理的方式方法。 异常处理是编程中十分重要但也最容易被人忽视的语言特性,它为开发者提供了处理程序运行时错误的机制,对于程序设计来说正确的异常处理能够防止泄露程序自身细节给用户,给开发者提供完整的错误回溯堆栈,同时也能提高程序的健壮性。 这篇文章我们来简单梳理一下...
阅读 2157·2023-04-25 17:48
阅读 3627·2021-09-22 15:37
阅读 2972·2021-09-22 15:36
阅读 6079·2021-09-22 15:06
阅读 1677·2019-08-30 15:53
阅读 1470·2019-08-30 15:52
阅读 749·2019-08-30 13:48
阅读 1157·2019-08-30 12:44