

GitHub - slashtrace/slashtrace: Awesome error handler. Demo: https://slashtrace....
source link: https://github.com/slashtrace/slashtrace
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
SlashTrace - Awesome error handler
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 and the CLI.
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('[email protected]'); $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.
Recommend
-
105
README.md secure_dotenv The secure_dotenv library provides an easy way to handle the encryption and decryption of the information in your .env file. One of the...
-
33
README.md Goproxy
-
17
-
35
Go’s infamous error handling has caught quite the attention from outsiders to the programming language, often touted as one of the language’s most questionable design decisions. If you look into any project on Github written in Go, it’s almost a...
-
14
Bad Ansible Error Message - No handler was ready to authenticate Jul 8, 2019 Of all the multitude of sins that software engineers wreak upon the world, I have a personal hatred for crappy error messages. Crap...
-
5
Complete Node.js CheatSheet --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets · GitHub Instantly share code, notes, and snippets. ...
-
7
What is Error Handler Error handler is responsible of identifying and handling runtime issues. Express.js comes pre-configured with a built-in Error Handler by default. Error Handlers In ExpressJS🚀 W...
-
9
解决 error: failed to push some refs to 'https://github.com/ 精选 原创
-
12
Member
-
6
Warning Awesome-errors is still being worked on. If you want to help, feel free to send a pull request or an issue.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK