bughq/bughq-php
publicClone
Push over the same URL. A password will not work: create a token under access tokens and use it in place of one.
bughq error tracking — PHP SDK
- .github
- src
- tests
- .gitignore 71 B
- composer.json 958 B
- LICENSE 1.0 KB
- phpunit.xml 482 B
- README.md 2.6 KB
bughq PHP SDK
Privacy-first error tracking for PHP. Captures exceptions, PHP errors, and fatal shutdowns, enriches them with breadcrumbs, tags, contexts, and user data, and reports them to bughq.
Using Laravel? Install bughq/bughq-laravel
instead - it wires everything below into the framework automatically.
Install
Requires PHP 8.4+.
composer require bughq/bughqQuick start
use BugHQ\BugHQ;
BugHQ::init([
'project' => 'acme-api', // from your bughq dashboard
'key' => 'pk_...', // public ingest key (safe to ship)
// or: 'dsn' => 'https://pk_...@bughq.org/acme-api',
'release' => '1.4.2',
'environment' => 'production',
]);That's it - uncaught exceptions, PHP errors, and fatal shutdown errors are
reported automatically (set 'captureUnhandled' => false to opt out).
Manual capture
try {
$charger->charge($order);
} catch (PaymentException $e) {
BugHQ::captureException($e, ['orderId' => $order->id]);
throw $e;
}
BugHQ::captureMessage('cache rebuild took ' . $secs . 's', 'warning');Context
BugHQ::setUser(['id' => $user->id, 'email' => $user->email]);
BugHQ::setTag('plan', 'pro');
BugHQ::setContext('order', ['id' => $order->id, 'total' => $order->total]);
BugHQ::setExtra('attempt', $attempt);
BugHQ::addBreadcrumb([
'category' => 'payment',
'message' => 'charge submitted',
'data' => ['gateway' => 'stripe'],
]);
// force related errors into one issue (or split one apart):
BugHQ::setFingerprint(['checkout', 'gateway-timeout']);Runtime (PHP version, SAPI), server (hostname, OS), and request (method, URL, IP, user agent) contexts are attached automatically.
Options
| option | default | |
|---|---|---|
project, key | - | or provide dsn |
host | https://bughq.org | self-hosted ingest |
release, environment | - / production | |
sampleRate | 1.0 | fraction of events to send |
dedupeSeconds | 5 | drop repeats of the same error site |
maxBreadcrumbs | 30 | ring buffer size |
ignoreExceptions | [] | class names, instanceof match |
ignoreMessages | [] | substrings or /regex/ |
beforeSend | - | fn (array $payload): ?array - return null to drop |
beforeBreadcrumb | - | fn (Breadcrumb $b): ?Breadcrumb |
errorTypes | E_ALL | mask for the global error handler |
captureUnhandled | true | install global handlers on init() |
timeout / connectTimeout | 5 / 2 | transport (seconds) |
License
MIT