Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Prometheus Metrics Bundle Laravel Package

artprima/prometheus-metrics-bundle

Symfony bundle integrating promphp/prometheus_client_php to expose Prometheus metrics for your app. Supports Symfony 5.4–8.x and PHP 8.2–8.5, with configurable metric namespace, ignored routes, and custom labels for HTTP/request metrics.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony Alignment: The bundle is natively designed for Symfony 5.4–8.x, making it a seamless fit for Laravel applications only if integrated via a Symfony microkernel or bridge (e.g., Symfony’s HttpKernel in a Laravel app). For pure Laravel, this requires a custom adapter layer to translate Symfony events (kernel.request, kernel.response) into Laravel’s middleware/container system.
  • Prometheus Ecosystem: Leverages promphp/prometheus_client_php, a mature PHP Prometheus client, ensuring compatibility with existing Prometheus/Grafana stacks.
  • Extensibility: Supports custom metrics collectors, storage backends (Redis/APCu), and label enrichment, aligning with Laravel’s modularity needs (e.g., custom middleware for metrics).

Integration Feasibility

  • Symfony Dependency: High risk for Laravel due to Symfony-specific event system (EventDispatcher). Requires:
    • Middleware translation: Map Symfony’s RequestEvent/ResponseEvent to Laravel’s middleware pipeline.
    • Service container bridging: Use Laravel’s ServiceProvider to register Symfony’s CollectorRegistry and bundle services.
  • Prometheus Client: The underlying promphp/prometheus_client_php is PHP-agnostic, so integration is feasible but requires manual wiring of collectors to Laravel’s event system (e.g., Illuminate\Http\Kernel events).
  • Storage Backends: Redis/APCu support is directly usable in Laravel, but configuration must account for Laravel’s caching system (e.g., Redis via predis or php-redis).

Technical Risk

Risk Area Severity Mitigation Strategy
Symfony Event System High Build a Laravel-Symfony event bridge (e.g., middleware to dispatch Symfony events).
Metrics Collector Gaps Medium Implement Laravel-specific collectors (e.g., for Illuminate\Queue jobs, Illuminate\Database queries).
Storage Backend Conflicts Low Use Redis (shared between Laravel and Prometheus) or APCu (if enabled).
Performance Overhead Medium Benchmark metric collection latency (e.g., Redis vs. in-memory).
Grafana Dashboard Gaps Low Adapt existing dashboards or build Laravel-specific ones (e.g., queue metrics).

Key Questions

  1. Symfony vs. Laravel Tradeoffs:
    • Is the team willing to adopt a Symfony microkernel for metrics, or must integration be pure Laravel?
    • Can we use Laravel’s Event system to replicate Symfony’s kernel.* events?
  2. Storage Backend:
    • Should we use Redis (shared with Laravel’s cache/queue) or APCu (simpler but less scalable)?
    • How will metrics persist across Laravel’s request lifecycle (e.g., during queue jobs)?
  3. Custom Metrics:
    • What Laravel-specific metrics are critical (e.g., Eloquent queries, queue jobs, API rate limits)?
    • Can we extend the bundle’s MetricsCollectorInterface to support Laravel’s ServiceContainer?
  4. Observability Stack:
    • Will Prometheus metrics replace or complement existing monitoring (e.g., Laravel Telescope, Sentry)?
    • How will we visualize Laravel-specific metrics in Grafana (e.g., queue depth, cache hits)?

Integration Approach

Stack Fit

  • Core Compatibility:
    • Laravel 10.x/11.x: PHP 8.2+ aligns with the bundle’s PHP support.
    • Symfony Bridge: Requires Symfony HttpKernel (e.g., symfony/http-kernel) or a custom event dispatcher to translate Laravel events to Symfony’s kernel.*.
    • Prometheus Client: promphp/prometheus_client_php is Laravel-agnostic; integration depends on event wiring.
  • Storage Backends:
    • Redis: Native support in Laravel (predis/php-redis); ideal for shared metrics storage.
    • APCu: Requires APCu extension (less common in Laravel deployments).
    • In-Memory: Suitable for single-process apps (e.g., local dev).

Migration Path

  1. Phase 1: Proof of Concept (PoC)
    • Install the bundle in a Symfony microkernel alongside Laravel (e.g., via Laravel\SymfonyBridge).
    • Test basic metrics collection (HTTP requests, responses).
    • Validate Grafana dashboard compatibility.
  2. Phase 2: Laravel Integration
    • Option A (Symfony Bridge):
      • Use symfony/http-kernel to wrap Laravel’s Application in a Symfony kernel.
      • Register the bundle in Symfony’s AppKernel.
    • Option B (Custom Middleware):
      • Build middleware to dispatch Symfony events (e.g., kernel.request → Laravel’s booted event).
      • Manually wire CollectorRegistry to Laravel’s container.
  3. Phase 3: Customization
    • Implement Laravel-specific collectors (e.g., for Illuminate\Queue, Illuminate\Database).
    • Extend storage backends (e.g., Laravel’s Redis cache as Prometheus storage).
    • Adapt Grafana dashboards for Laravel metrics (e.g., queue depth, job duration).

Compatibility

Component Laravel Compatibility Notes
Symfony Event System ❌ (Low) Requires custom bridge or middleware.
Prometheus Client ✅ (High) PHP-agnostic; works with any event system.
Redis Storage ✅ (High) Laravel’s Redis cache can double as Prometheus storage.
APCu Storage ⚠️ (Medium) Requires APCu extension (not always enabled in Laravel).
Custom Metrics ✅ (High) Can extend MetricsCollectorInterface for Laravel-specific data.
Grafana Dashboards ⚠️ (Medium) May need adaptation for Laravel metrics (e.g., queue jobs).

Sequencing

  1. Step 1: Infrastructure Setup
    • Add artprima/prometheus-metrics-bundle and promphp/prometheus_client_php to composer.json.
    • Configure Redis or APCu as storage backend.
  2. Step 2: Event System Bridge
    • Implement middleware to translate Laravel events to Symfony’s kernel.* (or vice versa).
    • Example: Dispatch kernel.request when Laravel’s Illuminate\Http\Request is processed.
  3. Step 3: Metrics Collection
    • Enable default metrics (disable_default_metrics: false).
    • Test /metrics/prometheus endpoint.
  4. Step 4: Custom Metrics
    • Create Laravel-specific collectors (e.g., for queue jobs, database queries).
    • Register collectors in services.yaml (via Laravel’s ServiceProvider).
  5. Step 5: Visualization
    • Import Grafana dashboards and adapt for Laravel metrics.
    • Set up Prometheus scrape config (prometheus.yml).

Operational Impact

Maintenance

  • Bundle Updates:
    • Monitor artprima/prometheus-metrics-bundle for Symfony version drops (e.g., Symfony 5.4 EOL).
    • Risk: Laravel integration may break if Symfony dependencies change.
  • Custom Code:
    • Event bridge middleware and custom collectors require maintenance as Laravel/Symfony evolve.
    • Storage backend (Redis/APCu) may need tuning for performance.
  • Dependency Management:
    • promphp/prometheus_client_php is stable, but Laravel’s event system may drift from Symfony’s.

Support

  • Debugging:
    • Symfony-specific issues (e.g., event dispatching) may require Symfony expertise.
    • Laravel integration gaps (e.g., missing collectors) need custom fixes.
  • Community:
    • Limited Laravel-specific support; rely on Symfony/Prometheus communities.
  • Tooling:
    • Use Laravel Telescope for debugging metrics collection.
    • Prometheus alerts for critical metrics (e.g., 5xx errors, queue backlog).

Scaling

  • Horizontal Scaling:
    • Redis storage scales well across Laravel instances.
    • In-memory storage requires shared storage (e.g., Redis) for multi-process setups.
  • Performance:
    • Metric collection overhead: Benchmark with 10k RPS to validate latency impact.
    • Storage bottlenecks: Redis memory usage may grow with high-cardinality labels.
  • Resource Usage:
    • APCu: Limited by server memory.
    • Redis: Monitor memory
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor