michalpospiech / sentry
Opinionated Sentry bootstrap for PHP 8.2+ apps, CLI scripts, workers and Nette - consistent tags, non-blocking async flush, env-based config, Tracy bridge with debug panel.
Requires
- php: ^8.2
- ext-json: *
- sentry/sentry: ^4.0
Requires (Dev)
- nette/application: ^3.2
- nette/di: ^3.2
- nette/http: ^3.3
- nette/schema: ^1.3
- nette/security: ^3.2
- nette/tester: ^2.4
- orisai/coding-standard: ^3.0
- phpstan/phpstan: ^1.0
- tracy/tracy: ^2.10
Suggests
- nette/application: Required for Nette Application presenter context integration
- nette/di: Required to use SentryExtension for neon-based configuration
- nette/http: Required for Nette Session integration (session ID tag enrichment)
- nette/security: Required for Nette Security user identity integration
- tracy/tracy: Required to use SentryLogger and MultiLogger Tracy bridge
Provides
None
Conflicts
None
Replaces
None
README
Opinionated Sentry bootstrap for plain PHP apps, legacy codebases, CLI scripts, cron jobs, workers, and Nette Framework applications.
If DSN is missing or Sentry is disabled, initialization becomes a safe no-op.
This package continues the development of
esportscz/sentry(versions up to 2.2.0), which was originally created by the same author and published under the MIT license. Since 3.0.0 it is published asmichalpospiech/sentrywith theMichalPospiech\Sentrynamespace. See Upgrading from esportscz/sentry.
What This Package Provides
- One unified
Bootstrap::init()for web + CLI (non-Nette). - Common, consistent tags and metadata (
service,project,stack, PHP info, git commit, memory limit). - Non-blocking async flush by default - on PHP-FPM the HTTP response is sent before Sentry flushes, so errors never add latency to the user-facing request.
- Configuration via environment variables, with optional per-key overrides in code.
- Safe
context_providerhook - never blocks reporting if it throws. flush()helper for short-lived processes (CLI jobs, cron, workers).- Nette Framework integration - DI extension, Tracy bridge, presenter/user/session enrichment, performance monitoring.
- Tracy Bar panel - real-time Sentry status, configuration overview, and captured events in the Tracy debug bar. Fully configurable via neon.
Installation
composer require michalpospiech/sentry
Quick Start
Plain PHP
use MichalPospiech\Sentry\Bootstrap;
Bootstrap::init([
'service' => 'my-service', // treat as required
'project' => 'my-project',
'stack' => 'php',
]);
Nette
extensions:
sentry: MichalPospiech\Sentry\Nette\SentryExtension
sentry:
dsn: %env.SENTRY_DSN%
service: my-service
project: my-project
stack: php
No PHP bootstrap changes needed - the extension handles initialization automatically.
Documentation
- Configuration Reference - all config keys, env vars, defaults, automatic tags
- Nette Integration - DI extension, Tracy bridge, Application/Security/Session integrations, performance monitoring
- Helper Methods -
setUser,tag,flush,configureScope,context_provider - Troubleshooting - common issues, server saturation, timeout tuning
- Examples - full implementation examples for web, CLI, Nette, and worker
Requirements
- PHP
^8.2(tested on PHP 8.2 and 8.4) sentry/sentry ^4.0
Nette integration requires nette/di ^3.2.
For PHP 7.2 - 8.1 use the 2.x line of esportscz/sentry.
Versioning (SemVer)
- MAJOR - breaking API changes and/or a PHP version bump
- MINOR - backward-compatible features
- PATCH - backward-compatible bug fixes
See CHANGELOG.md for a full history of changes.
Upgrading from esportscz/sentry
Version 3.0.0 changes the package name and the namespace and requires PHP 8.2+; configuration keys and behavior stay the same.
-
Replace the package:
composer remove esportscz/sentry composer require michalpospiech/sentry -
Replace the namespace
eSportsCZ\SentrywithMichalPospiech\Sentryin your PHP code and neon configuration (e.g.MichalPospiech\Sentry\Nette\SentryExtension). -
If you used the PHP 7.2 compatible Nette integration (
eSportsCZ\Sentry\Nette72\...), switch toMichalPospiech\Sentry\Nette\...- the classes and neon options are the same.
License
MIT - see LICENSE.
Contributing
Anyone can open a Pull Request. Please tag @michalpospiech as reviewer.