PHPackages                             dotink/slashtrace - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. dotink/slashtrace

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

dotink/slashtrace
=================

SlashTrace - Awesome error handler

1.2.0(2y ago)04.3k↓19.3%1MITPHPPHP &gt;=7.2

Since Sep 26Pushed 1y agoCompare

[ Source](https://github.com/dotink/slashtrace)[ Packagist](https://packagist.org/packages/dotink/slashtrace)[ RSS](/packages/dotink-slashtrace/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (10)Used By (1)

SlashTrace - Awesome error handler
==================================

[](#slashtrace---awesome-error-handler)

[![Build Status](https://camo.githubusercontent.com/745960d3c4951914ef27ac150a5ab7605ce8ddc2a554def5ce828f50cb7cfd82/68747470733a2f2f7472617669732d63692e6f72672f736c61736874726163652f736c61736874726163652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/slashtrace/slashtrace)[![Code Coverage](https://camo.githubusercontent.com/af5292d324d6054422c965a53460cef8ae3b6d2faa27be369d0cb231de9abed0/68747470733a2f2f636f6465636f762e696f2f67682f736c61736874726163652f736c61736874726163652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/slashtrace/slashtrace)

---

[![Screenshot](https://camo.githubusercontent.com/b77a3f0abf893b07fdb0cae5436a7fa58417a16061136b97e3768719e512f4db/68747470733a2f2f736c61736874726163652e636f6d2f64656d6f2e706e67)](https://slashtrace.com/demo.php)

---

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](https://slashtrace.com/demo-ajax.png), the [CLI](https://slashtrace.com/demo-cli.png), and [JSON APIs](https://slashtrace.com/demo.json).

When you're done with local debugging, you can configure SlashTrace to send errors to dedicated error reporting services, like [Sentry](https://sentry.io/), [Raygun](https://raygun.com/), and [Bugsnag](https://www.bugsnag.com/).

Usage
-----

[](#usage)

1. Install using Composer:

    ```
    composer require slashtrace/slashtrace

    ```
2. 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
--------

[](#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:

- [Sentry](https://github.com/slashtrace/slashtrace-sentry)
- [Raygun](https://github.com/slashtrace/slashtrace-raygun)
- [Bugsnag](https://github.com/slashtrace/slashtrace-bugsnag)

Capturing additional data
-------------------------

[](#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

[](#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:

- [Sentry - Capturing the User](https://docs.sentry.io/learn/context/?platform=javascript#capturing-the-user)
- [Raygun - User Tracking](https://raygun.com/docs/workflow/user-tracking)
- [Bugsnag - Identifying users](https://docs.bugsnag.com/platforms/php/other/#identifying-users)

### Recording breadcrumbs

[](#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](https://blog.sentry.io/2016/05/27/php-breadcrumbs.html)
- Raygun - The current PHP SDK doesn't support breadcrumbs
- [Bugsnag - Logging breadcrumbs](https://docs.bugsnag.com/platforms/php/other/#logging-breadcrumbs)

### Tracking releases

[](#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"); //
