dotink/slashtrace
Composer 安装命令:
composer require dotink/slashtrace
包简介
SlashTrace - Awesome error handler
README 文档
README
SlashTrace is, at its core, an error and exception handler. You hook it into your error handling routine (or let it set itself up to catch all errors and exceptions), and it captures and displays a lot of nice information about your errors. It does this for normal browser requests, but also for AJAX, the CLI, and JSON APIs.
When you're done with local debugging, you can configure SlashTrace to send errors to dedicated error reporting services, like Sentry, Raygun, and Bugsnag.
Usage
-
Install using Composer:
composer require slashtrace/slashtrace -
Capture errors:
use SlashTrace\SlashTrace; use SlashTrace\EventHandler\DebugHandler; $slashtrace = new SlashTrace(); $slashtrace->addHandler(new DebugHandler()); // Register the error and exception handlers $slashtrace->register();
Alternatively, you can explicitly handle exceptions:
try { // Your code } catch (Exception $exception) { $slashtrace->handleException($exception); }
Handlers
SlashTrace comes bundled with the DebugHandler used in the example above, but you will usually want to set it up to send errors to an error tracking service when running in production. Currently, there are handlers implemented for the following providers, and more are on the way. Click each link to view the usage documentation:
Capturing additional data
Besides the complex error information that SlashTrace captures out of the box, you can attach other types of data to each report. This is especially useful when using one of the external handlers above.
This way, SlashTrace acts like an abstraction layer between you and these providers, and normalizes the data that you provide into a single format. This helps you to avoid vendor lock-in and lets you switch error reporting providers simply by switching the handler.
Capturing user data
If you want to attach information about the affected user, you can do so like this:
use SlashTrace\Context\User; $user = new User(); $user->setId(12345); $user->setEmail('pfry@planetexpress.com'); $user->setName('Philip J. Fry'); $slashtrace->addUser($user);
Note that a user needs at least an ID or an email. The name is completely optional.
This feature corresponds to the respective implementations in each error tracker:
Recording breadcrumbs
Sometimes a stack trace isn't enough to figure out what steps lead to an error. To this end, SlashTrace lets you record breadcrumbs during execution:
$slashtrace->recordBreadcrumb("Router loaded"); $slashtrace->recordBreadcrumb("Matched route", [ "controller" => "orders", "action" => "confirm", ]);
Relevant tracker docs:
- Sentry - Breadcrumbs in PHP
- Raygun - The current PHP SDK doesn't support breadcrumbs
- Bugsnag - Logging breadcrumbs
Tracking releases
Often, it's useful to know which release introduced a particular bug, or which release triggered a regression. Tagging events with a particular release or version number is very easy:
$slashtrace->setRelease("1.0.0"); // <- Your version number, commit hash, etc.
Tracker docs:
- Sentry - Releases
- Raygun - Version numbers
- Bugsnag - The release version cannot be explicitly set per event. Read the Bugsnag docs for more details.
Debug renderers
When you use the bundled debug handler, it tries to choose an appropiate output renderer based on the environment in which it's running, like this:
- The CLI renderer when
php_sapi_name() === "cli. Example output. - The plain text renderer, for AJAX requests (requests with the
X-Requested-With: XMLHttpRequestheader). Example output. - The JSON renderer, for requests with the
Accept: application/jsonheader. This takes precedence over the text renderer, in case both headers are present. Example output. - The Web renderer, for all other requests. Example output.
Alternatively, you can force the debug handler to use a particular renderer:
use SlashTrace\EventHandler\DebugHandler; use SlashTrace\DebugRenderer\DebugJsonRenderer; $handler = new DebugHandler(); $handler->setRenderer(new DebugJsonRenderer()); $slashtrace->addHandler($handler);
dotink/slashtrace 适用场景与选型建议
dotink/slashtrace 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.85k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dotink/slashtrace 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dotink/slashtrace 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-13