Skip to content
Bugtail Docs
Menu

PHP

For PHP without Laravel, use the framework-agnostic Sentry SDK. It works with any framework, or none. On Laravel, follow the Laravel guide instead.

Install

composer require sentry/sentry

Configure

Initialise the SDK as early as you can, before anything that might throw:

\Sentry\init([
    'dsn' => 'https://<key>@ingest.bugtail.eu/<project-id>',
    'environment' => 'production',
    'release' => '1.4.0',
]);

Copy the DSN from your collector under Settings > Projects and collectors.

init() installs its own error and exception handlers, so uncaught errors are reported without further wiring. Report the ones you catch yourself:

try {
    $invoice->send();
} catch (\Throwable $e) {
    \Sentry\captureException($e);
}

Send a test event

\Sentry\captureMessage('Bugtail test event');

Logs

Turn logs on in the SDK and write through its logger. The SDK collects the lines and sends them when you flush, so flush once at the end of the request or script:

\Sentry\init([
    'dsn' => 'https://<key>@ingest.bugtail.eu/<project-id>',
    'enable_logs' => true,
]);

\Sentry\logger()->warn('Payment provider answered slowly');

\Sentry\logger()->flush();

The lines appear under Logs.