spatie/flare-client-php
PHP 8.2+ client for sending exceptions, errors, and stack traces to Flare. Install via Composer and use in any PHP app; Laravel users should use spatie/laravel-flare. Includes docs, tests, and ongoing maintenance by Spatie.
spatie/flare-client-php package is a first-class observability solution for PHP applications, aligning with modern distributed tracing and logging paradigms. It integrates seamlessly with Flare, a SaaS-based error tracking and performance monitoring tool, offering:
JobRecorder, QueueRecorder, RouteAttributesProvider) that reduce boilerplate for Laravel applications. However, the generic flare-client-php is preferable for non-Laravel PHP apps (e.g., Symfony, Lumen, or custom Silex apps).Flare, Tracer, Logger, Lifecycle) are decoupled.HttpRecorder, JobRecorder) can be extended or replaced.UserAttributesProvider) enable custom context injection.index.php or a service container).guzzlehttp/guzzle for HTTP, symfony/http-foundation for request parsing).symfony/process for queue monitoring).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Breaking Changes | Major version (3.x) introduced backward-incompatible refactors (e.g., removed reportMessage(), renamed collectLogs()). |
- Upgrade path: Follow UPGRADING.md. |
| Performance Overhead | Dynamic sampling and trace collection add ~5–15ms latency per request (varies by sampling rate). | - Use DynamicSampler to limit trace volume (e.g., sample 10% of /checkout requests). |
| Data Privacy | Sensitive data (e.g., passwords, tokens) may leak if not censored. | - Use attribute providers to redact fields (e.g., RequestAttributesProvider::censor()). |
| Flare Daemon Dependency | Relies on a local daemon for offline buffering. If the daemon fails, errors fall back to HTTP (but may be delayed). | - Monitor daemon health via Flare::lifecycle()->isDaemonRunning(). |
| Laravel-Specific Gaps | Non-Laravel apps must manually implement attribute providers (e.g., RouteAttributesProvider). |
- Extend base classes (e.g., BaseRouteAttributesProvider) or use generic RequestAttributesProvider. |
| Testing Complexity | Mocking Flare in unit tests requires custom senders (e.g., FilesystemSender). |
- Use Flare::setSender() in tests to intercept reports. |
spatie/laravel-flare (if applicable) to this generic client?| Technology Stack | Compatibility | Notes |
|---|---|---|
| PHP 8.2+ | ✅ Full support. | Uses modern PHP features (attributes, enums, strict typing). |
| Laravel 10+ | ✅ Optimized (but generic client is preferred over laravel-flare). |
Laravel-specific integrations (e.g., JobRecorder) are included but not enforced. |
| Symfony 6+ | ✅ Full support (uses symfony/http-foundation). |
Works with Symfony’s Request, Response, and Console components. |
| Silex/Lumen | ✅ Partial (requires manual setup for routing/queues). | Missing some Laravel-specific providers (e.g., RouteAttributesProvider). |
| Monolog | ✅ Logs are Monolog-compatible (levels: DEBUG, INFO, etc.). |
Can integrate with existing Monolog handlers. |
| OpenTelemetry | ✅ W3C trace context support. | Traces can be correlated with other OTel-compatible tools (e.g., Jaeger, Zipkin). |
| Queue Systems | ✅ Laravel Queues, Symfony Messenger, generic PHP-PM. | Uses JobRecorder and QueueRecorder for job context. |
| Database Drivers | ⚠️ No direct DB integration (but traces can include SQL via custom providers). | Use RequestAttributesProvider to log query parameters (if needed). |
| Microservices | ✅ Distributed tracing via traceparent headers. |
Works with gRPC, HTTP, and message queues. |
Assessment Phase:
password, api_token)./payments errors, 10% of others").Pilot Integration:
spatie/flare-client-php and configure basic error reporting (via setErrorHandler()).$flare->log()->error("Message")).Full Rollout:
registerShutdownFunction()).DynamicSampler for path-based rules).error_log() in favor of Flare).How can I help you explore Laravel packages today?