TraceHawk // browser and PHP errors Group · Count · File the ticket Ingest operational

PHP

PHP exception monitoring.

tracehawk/sdk is a small PHP 8.2 client. You point it at a project, capture the exception, and it keeps the stack, the previous exception, and a trace id.

What it does

There is no automatic hook for a plain PHP app. TraceHawk::init reads the DSN. TraceHawk::capture sends one exception. TraceHawk::trackRequest sends the HTTP request that just finished. Laravel and Symfony call those for you. A plain script calls them itself.

The report includes the exception class and message, up to 40 frames, up to five previous exceptions, the release, the environment, a user id if you set one, and up to 30 breadcrumbs. Vendor frames and the SDK file are marked outside the application so grouping can prefer your code.

Install

composer config repositories.tracehawk composer https://tracehawk.net/sdk
composer require tracehawk/sdk:1.1.0
TRACEHAWK_DSN=https://tracehawk.net/api/<key>
use TraceHawk\Sdk\TraceHawk;

TraceHawk::init(getenv('TRACEHAWK_DSN') ?: '');
TraceHawk::setEnvironment('production');
TraceHawk::setRelease('app@1.0.0');

set_exception_handler(function (Throwable $e): void {
    TraceHawk::capture($e);
});

register_shutdown_function(function (): void {
    if (PHP_SAPI === 'cli') {
        return;
    }
    TraceHawk::trackRequest();
});

Put that where the application boots, before your own code runs. Skip trackRequest in CLI scripts unless you want the command reported as a request. Laravel already avoids that.

A handled exception

try {
    $payment->charge();
} catch (Throwable $e) {
    TraceHawk::addBreadcrumb('payment', 'Charge failed');
    TraceHawk::capture($e);
    throw $e;
}

Supported features

Plain PHP does not collect SQL or cache spans on its own. Those collectors ship with the Laravel provider.

Troubleshooting

Questions

Do I have to use Laravel or Symfony?

No. The same package works from plain PHP if you call init, capture, and trackRequest yourself. Laravel and Symfony are shortcuts for those calls.

What PHP version does the SDK require?

PHP 8.2 or newer, as declared by tracehawk/sdk 1.1.0.

Will secrets in local variables be stored?

Variable names that look like a password, secret, token, credential, or API key are stored as [Filtered]. Do not put secrets in the exception message, tags, or user id.

Related

Ready to turn error noise into actionable issues?