spatie/laravel-flare
Send Laravel 11+ (PHP 8.2+) exceptions and logs to Flare for production error tracking, alerts, and sharing. Configure with your Flare API key to automatically report issues and get notified when they occur.
## Technical Evaluation
### **Architecture Fit**
- **Enhanced Livewire Support**: The 2.8.0 release adds explicit support for **Livewire v4 Server Components (SFCs)** in stack traces, improving debugging for modern Livewire applications. This aligns with Laravel’s growing adoption of Livewire for reactive UI and reduces friction for teams using both Flare and Livewire.
- **Improved Error Grouping**: Unmatched route 4xx errors (e.g., `404`, `403`) are now grouped under `errors::{status_code}` in Flare’s dashboard. This enhances **error categorization** and reduces noise in the UI, making it easier to triage HTTP-specific issues.
- **Backward Compatibility**: Changes are additive (no breaking modifications to core error handling or API contracts). The package continues to leverage Laravel’s `ExceptionHandler` and service container without disruption.
### **Integration Feasibility**
- **Livewire v4 Readiness**: Critical for teams migrating from Livewire v3 or adopting SFCs. The fix ensures Flare captures **component-level context** (e.g., `Livewire\Livewire::mount()` calls) in stack traces, which was previously fragmented.
- **4xx Error Clarity**: The grouping feature reduces clutter in the Flare dashboard, particularly for APIs or applications with dynamic routing (e.g., SPA-like behavior with Laravel). Example:
- Before: Scattered `404` errors under "Not Found."
- After: All `404` errors grouped under `errors::404`, with sub-filtering by route.
- **Dependency Alignment**:
- **Livewire v4**: Explicit support for SFCs (e.g., `<x-my-component />`) in traces.
- **Laravel 11+**: No changes required; the package remains compatible with Laravel’s latest error handling pipeline.
- **PHP 8.2+**: Continued reliance on modern PHP features for Livewire’s SFC parsing.
### **Technical Risk**
| Risk Area | Severity | Mitigation Strategy |
|-------------------------|----------|-----------------------------------------------|
| **Livewire SFC Parsing** | Low | Test in staging with Livewire v4 apps to validate SFC trace accuracy. Fallback: Manually inspect `resources/views` for missing context. |
| **4xx Grouping Logic** | Low | Verify grouping doesn’t interfere with custom error handlers (e.g., `App\Exceptions\Handler::render()`). |
| **Livewire v3 Deprecation** | Medium | Monitor Livewire’s roadmap; Flare’s v4 support may lag if Livewire deprecates older patterns. |
| **API Key Exposure** | High | Unchanged from prior assessment; mitigate via IAM roles and `.env` restrictions. |
| **Performance Overhead**| Low | SFC parsing is incremental; benchmark in staging with Livewire-heavy workloads. |
### **Key Questions**
1. **Livewire Adoption**:
- Are we using **Livewire v4 SFCs**? If yes, validate that Flare’s traces accurately reflect component hierarchy (e.g., nested `<x-*/>`).
- *Action*: Test with a sample SFC:
```php
// resources/views/components/my-component.blade.php
<div>...</div>
```
Trigger an error in `mount()` and verify Flare shows the full component path.
2. **4xx Error Strategy**:
- Should we **suppress** certain 4xx errors (e.g., `404` for non-critical routes) from Flare?
- *Example*: Ignore `404` for static assets:
```php
Flare::ignoreExceptions([
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
], statusCodes: [404]);
```
3. **Livewire + API Hybrid Apps**:
- How should Flare handle errors in **Livewire components calling APIs**? Ensure cross-component traces are preserved.
- *Tool*: Use Flare’s [request inspection](https://flareapp.io/docs/integration/laravel-requests) to validate payloads.
4. **Custom 4xx Handlers**:
- Do we override `render()` for 4xx errors in `App\Exceptions\Handler`? Confirm Flare’s grouping doesn’t conflict with custom logic.
- *Test*: Throw a `403` in a controller and check Flare’s grouping vs. your handler’s output.
5. **Legacy Livewire Support**:
- If using **Livewire v3**, will Flare’s v4 SFC optimizations break existing traces?
- *Mitigation*: Monitor Flare’s logs for degraded trace quality in v3 apps.
---
## Integration Approach
### **Stack Fit**
- **Livewire v4 Integration**:
- **Server Components**: Flare now parses SFCs (e.g., `<x-my-component />`) in stack traces, providing **component-level debugging** for reactive UI issues.
- **Hybrid Apps**: Works seamlessly with Laravel APIs called from Livewire (e.g., `wire:call`).
- **4xx Error Handling**:
- **Grouping**: Reduces dashboard noise for teams with dynamic routing (e.g., SPA-like apps). Ideal for:
- API-first Laravel apps.
- Single-page applications using Laravel as a backend.
- **Compatibility**: No changes to existing `App\Exceptions\Handler` required unless customizing 4xx logic.
### **Migration Path**
1. **Pre-Integration Checklist**:
- **Livewire Audit**: Verify version (`composer show livewire/livewire`) and SFC usage.
- **4xx Strategy**: Document current handling of HTTP errors (e.g., custom `render()` methods).
- *Tool*: Run `php artisan flare:check` (if available) to validate Livewire compatibility.
2. **Update Flare**:
```bash
composer update spatie/laravel-flare --with-dependencies
config/flare.php has:
'ignore_exceptions' => [
// Add Livewire-specific exceptions if needed
],
Livewire-Specific Validation:
throw new \Exception in mount()).resources/views/components/user/profile.blade.php).// app/Livewire/UserProfile.php
public function mount()
{
throw new \Exception("Test Livewire SFC trace");
}
4xx Grouping Validation:
404 in a route (e.g., Route::get('/nonexistent', fn() => abort(404))).errors::404 group.config/flare.php to exclude specific 4xx codes:
'ignore_status_codes' => [404, 429],
Fallback Testing:
FLARE_ENABLED=false) and verify existing error handling (e.g., Monolog, Sentry) remains intact.| Component | Compatibility Notes |
|---|---|
| Livewire v3 | Traces may lack SFC context; monitor for degraded debugging. |
| Livewire v4 SFCs | Full support for <x-component /> syntax in stack traces. |
| Custom 4xx Handlers | Flare’s grouping is post-processing; custom render() methods take precedence. |
| API Routes | 4xx grouping applies to both web and API routes (e.g., Route::apiResource()). |
| Queue Workers | Livewire errors in queues (e.g., HandleLivewireRequests) are captured if FLARE_ENABLED=true. |
Phase 1: Core Update (1 day):
Phase 2: Customization (1 day):
ignore_exceptions and ignore_status_codes in config/flare.php.404 for static assets but keep 403 for auth errors.Phase 3: Livewire Deep Dive (1–2 days):
mount(), hydrate).Phase 4: Monitoring (Ongoing):
500 in mount()).errors::404 group weekly to identify missing routes.How can I help you explore Laravel packages today?