ReviewOS

bughq/bughq-php

public
Clone

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

main
· 11 commits

Mirrored from bughq/bughq-php · synced 12 minutes ago

README.md

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/bughq

Quick 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

optiondefault
project, key-or provide dsn
hosthttps://bughq.orgself-hosted ingest
release, environment- / production
sampleRate1.0fraction of events to send
dedupeSeconds5drop repeats of the same error site
maxBreadcrumbs30ring 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
errorTypesE_ALLmask for the global error handler
captureUnhandledtrueinstall global handlers on init()
timeout / connectTimeout5 / 2transport (seconds)

License

MIT