Symfony
Symfony exception monitoring.
Register one bundle. It reports uncaught HTTP exceptions, console errors, and each web request from TRACEHAWK_DSN.
What it does
TraceHawkBundle subscribes to the kernel and the console. On the main request it starts a trace. On terminate it sends the method and path. An exception that is not an HTTP exception below status 500 is captured. A 404 is not sent. A console error is sent. A normal console command is not reported as an HTTP request.
The listener reads TRACEHAWK_DSN, then TRACEX_DSN. The environment comes from APP_ENV, or prod when that value is missing. If TraceHawk is unreachable, the report gives up in under half a second.
Install
composer config repositories.tracehawk composer https://tracehawk.net/sdk composer require tracehawk/sdk:1.1.0
TRACEHAWK_DSN=https://tracehawk.net/api/<key>
# config/bundles.php TraceHawk\Sdk\Symfony\TraceHawkBundle::class => ['all' => true],
Symfony Flex will not discover this package from Packagist. The line above is the whole registration. The bundle does not ship a configuration file.
Release, user, and a handled exception
The bundle does not read a release from the container. Set it once the client has initialized, which the listener does on the first kernel or console event. A practical place is a listener of your own on kernel.request with a later priority, or immediately before a capture.
use TraceHawk\Sdk\TraceHawk;
TraceHawk::setRelease('app@1.4.2');
TraceHawk::setUser($userId);
TraceHawk::addBreadcrumb('checkout', 'Card step opened');
try {
$order->charge();
} catch (\Throwable $e) {
TraceHawk::capture($e);
throw $e;
}
Supported features
- Uncaught HTTP exceptions at status 500 and above, plus non-HTTP throwables.
- Console errors.
- One transaction per web request, named from the method and path.
- Release, environment, user id, and breadcrumbs, using the same client as plain PHP.
- Previous exceptions on the captured throwable.
- The same issue page and Jira rule as the other clients.
The Symfony bundle does not attach SQL, HTTP client, or cache spans. That collector is part of the Laravel provider. You can still call TraceHawk::addSpan yourself.
Troubleshooting
- No events: the bundle line is missing, or TRACEHAWK_DSN is empty in the environment the web server actually uses. Symfony does not load a Laravel-style config/tracex.php.
- 404s and other HTTP exceptions below 500 are ignored on purpose.
- A catch block that does not rethrow, and does not call TraceHawk::capture, is invisible.
- Allowed origins do not apply to PHP.
- A console command that exits cleanly does not create an event. An error during the command does.
Questions
Does a Symfony 404 open an issue?
No. The listener skips HTTP exceptions whose status is below 500.
Where does the DSN come from?
The environment variable TRACEHAWK_DSN. TRACEX_DSN is still read if the first name is empty. There is no Symfony config tree for the bundle.
Are console commands reported?
A command that finishes normally is not sent as a request. An error during the command is captured.