- What is saschahemleb/laravel-grafana and what does it do?
- It is a Laravel bridge package for the saschahemleb/php-grafana-api-client library. Instead of wiring the Grafana HTTP client up by hand, you get a Laravel service provider, configuration file, and container bindings so the client can be resolved through the framework. That makes it convenient to call the Grafana API from your application for observability tasks such as inspecting dashboards, annotations, or datasources.
- How do I install laravel-grafana in a Laravel project?
- Install it with Composer by running composer require saschahemleb/laravel-grafana. The package uses Laravel package auto-discovery, so the service provider and any facade are registered without manual edits to config/app.php. After installation, publish the package configuration with the vendor:publish command so you can add your Grafana connection details.
- How do I configure the connection to my Grafana instance?
- Publish the package config file and set the Grafana base URL plus an API token or basic auth credentials, ideally via environment variables in your .env file. The underlying client needs the host of your Grafana server and a credential with enough permission for the endpoints you call. Keep the published config out of version control changes where secrets are involved, and cache the config in production with php artisan config:cache.
- Which Laravel versions does this package support?
- This is a thin bridge package, so its Laravel support is defined by the illuminate constraints in its composer.json. Check that file or the repository README for the exact version range before upgrading a major Laravel release. Since the package only provides container bindings and configuration, version bumps are usually small, but always run your test suite after a framework upgrade.
- How do I actually use the Grafana client inside my application?
- Resolve the client from Laravel's service container, typically by type-hinting it in a constructor or controller method, or by using the provided facade if one is registered. Because it is bound as a singleton-style service, you can inject it anywhere you would inject any other Laravel dependency. Calls such as fetching dashboards or creating annotations are then made through the underlying php-grafana-api-client methods.
- Does this package collect application metrics for Grafana by itself?
- No. It is an API bridge, not a metrics collector or exporter: it lets Laravel talk to Grafana's HTTP API. Grafana itself visualizes data that lives in a datasource such as Prometheus, InfluxDB, or Loki, so runtime metrics still need to be produced by an exporter or agent of your choosing. Use this package when you want programmatic control of Grafana resources from Laravel code.
- How do I test code that depends on the Grafana client?
- Since the client is resolved from the container, you can swap it for a mock or fake in your tests using the container's instance binding or Laravel's mocking helpers. That keeps your test suite from making real HTTP requests to a Grafana server. If you want end-to-end coverage of the API layer, point the configuration at a disposable Grafana container in CI instead.
- Is it safe to use laravel-grafana in production?
- Yes, provided you treat the Grafana API token as a secret and store it in environment variables rather than in code. Use HTTPS for the Grafana base URL, grant the token the minimum permissions required, and avoid logging request headers that contain credentials. Because the client performs network calls, wrap critical calls in try/catch blocks and consider timeouts so a Grafana outage never blocks a user request.
- What alternatives exist for Laravel and Grafana observability?
- If your goal is exposing application metrics, Prometheus exporter packages such as spatie/laravel-prometheus or the OpenTelemetry PHP SDK are more direct fits than an API bridge. Laravel Telescope and Pulse cover application-level monitoring inside Laravel itself, while this package is specifically about driving the Grafana API. Many teams combine an exporter for metrics with this bridge for managing dashboards and annotations programmatically.
- Is laravel-grafana actively maintained and what happens if the Grafana API changes?
- The package is a bridge, so most behaviour lives upstream in saschahemleb/php-grafana-api-client and fixes usually arrive there first. Pin a version in composer.json and review the changelog before updating, especially across major releases of the underlying client. If the package lags behind a Laravel release, the bindings are simple enough that you can fork or register the client manually in a service provider.