Sentry error monitoring integration for PHPNomad applications. Transparently captures errors and exceptions via the PHPNomad logging system — no code changes needed in your application.
composer require phpnomad/sentry-integrationCreate a class that returns your Sentry DSN:
use PHPNomad\Sentry\Interfaces\SentryDsnProvider;
class MySentryDsnProvider implements SentryDsnProvider
{
public function getDsn(): string
{
return $_ENV['SENTRY_DSN'] ?? '';
}
}Add the Sentry initializer and your DSN provider binding to your application boot:
use PHPNomad\Sentry\SentryInitializer;
// In your initializer chain:
new SentryInitializer(),
new MyDsnProviderInitializer(), // binds MySentryDsnProvider => SentryDsnProviderAny $logger->error(), $logger->critical(), etc. calls will now be captured in Sentry. Lower-severity logs (debug, info, notice) are added as breadcrumbs that appear as context on the next error.
- Listens to
ItemLoggedevents broadcast by PHPNomad's logger - WARNING and above: captured as Sentry events
- Below WARNING: added as Sentry breadcrumbs
- If
$context['exception']contains aThrowable, usescaptureException()for full stack traces - Lazy initialization: Sentry SDK is only initialized on the first log event
- Empty DSN gracefully no-ops (no errors if Sentry isn't configured)
- All Sentry calls wrapped in try/catch — monitoring never crashes your app
Override SentryCaptureGate to control what gets captured vs breadcrumbed:
use PHPNomad\Core\Events\ItemLogged;
use PHPNomad\Sentry\Interfaces\SentryCaptureGate;
class MyCaptureGate implements SentryCaptureGate
{
public function shouldCapture(ItemLogged $event): bool
{
// Only capture ERROR and above (skip warnings)
return $event->severityIs('>=', ItemLogged::ERROR);
}
}Bind it in a later initializer to override the default:
return [MyCaptureGate::class => SentryCaptureGate::class];| PHPNomad Level | Sentry Severity |
|---|---|
| DEBUG | debug |
| INFO | info |
| NOTICE | info |
| WARNING | warning |
| ERROR | error |
| CRITICAL | fatal |
| ALERT | fatal |
| EMERGENCY | fatal |
MIT