- Can I use TweedeGolfPrometheusBundle directly in Laravel without Symfony?
- No, this bundle is designed for Symfony and relies on its kernel and dependency injection. For Laravel, you’d need to create a facade wrapper to abstract Symfony’s `CollectorRegistry` and route registration. The core dependency (tweedegolf/prometheus-client) is also outdated and lacks Laravel compatibility.
- What Laravel alternatives exist for Prometheus metrics?
- For Laravel, consider `spatie/laravel-prometheus` (modern, Laravel-native) or `prometheus/client_php` (standalone). These avoid Symfony dependencies and integrate better with Laravel’s service container. If you’re tied to Prometheus, a custom wrapper around `client_php` is likely more maintainable.
- How do I secure the `/metrics` endpoint in Laravel?
- Since this bundle exposes `/metrics` via Symfony routing, you’ll need middleware to restrict access. In Laravel, use `app/Http/Middleware` to add IP whitelisting or basic auth. Example: `Route::get('/metrics', [MetricsController::class, 'metrics'])->middleware('trusted');` with a custom middleware class.
- Is the storage adapter (APCu) persistent across server restarts?
- No, APCu is in-memory and resets on server restart. For persistence, you’d need to implement a custom adapter (e.g., Redis or database-backed) or use a separate storage solution like Prometheus’s built-in remote write. The bundle doesn’t provide Laravel-native storage options out of the box.
- How do I define custom collectors (e.g., for database queries) in Laravel?
- You’d need to extend the bundle’s YAML configuration or create a Laravel-specific config file (e.g., `config/prometheus.php`). Define collectors like `database_queries: { counter: { labels: [query_type], help: 'DB query count' } }`, then update them via a facade wrapper (e.g., `Prometheus::counter('database_queries')->inc()`).
- Will this bundle work with Laravel 10+ and Symfony 6+?
- Unlikely. The bundle and its core dependency (`tweedegolf/prometheus-client`) are archived (last update: 2018) and lack compatibility with modern Symfony/Laravel versions. You’d need to fork and update dependencies or switch to a maintained alternative like `spatie/laravel-prometheus`.
- How do I test Prometheus metrics in Laravel’s PHPUnit/Pest?
- Mocking this bundle in Laravel tests is complex due to Symfony coupling. Use partial mocks for the `CollectorRegistry` service or create a test double that mimics its methods (e.g., `inc()`, `observe()`). For integration tests, verify the `/metrics` endpoint returns expected Prometheus-formatted output.
- Can I track Laravel queues (Horizon) or HTTP requests with this bundle?
- Not natively. The bundle lacks integration with Laravel’s queues or HTTP middleware. You’d need to manually instrument these components (e.g., middleware for requests, queue listeners for jobs) and update metrics via the `CollectorRegistry` service through a facade wrapper.
- What’s the performance impact of using Prometheus metrics in Laravel?
- Minimal for counters/gauges, but histograms (e.g., response timings) add overhead due to bucket calculations. For high-traffic apps, batch metric updates or use a lighter alternative like StatsD. Profile with Laravel’s `bench()` or Blackfire to measure impact.
- How do I migrate from this bundle to a Laravel-native Prometheus solution?
- Start by identifying your current collectors (counters/gauges/histograms) and their labels. Replace the Symfony bundle with `spatie/laravel-prometheus` or `prometheus/client_php`, then rewrite configuration to Laravel’s `config/prometheus.php`. Update metric updates to use the new package’s API (e.g., `Prometheus::counter('requests')->inc()`).