minhyung / laravel-openobserve
Laravel package for OpenObserve integration - centralized log management and monitoring
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^11.0|^12.0
- minhyung/openobserve: ^0.1
- monolog/monolog: ^3.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^4.0
- php-http/mock-client: ^1.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel adapter for minhyung/openobserve, the PHP client for OpenObserve.
This package provides:
- A configured
Minhyung\OpenObserve\Clientinstance bound in the container - A custom Laravel log channel driver that ships logs through OpenObserve's Monolog handler
- An
openobserve:testArtisan command for connection checks
Requirements
- PHP 8.4.1+
- Laravel 13.x
Upgrading from 0.1
The upcoming 0.2 release drops support for PHP 8.3 and Laravel 11/12. Upgrade PHP and Laravel before updating this package. Existing configuration, Facade access, container bindings, and logging channel setup remain compatible.
The openobserve:test command now requires confirmation that its test record was ingested. An HTTP 200 response alone is no longer sufficient; see Connection Test.
Installation
composer require minhyung/laravel-openobserve
Publish the configuration file:
php artisan vendor:publish --tag=openobserve-config
Configuration
Add OpenObserve connection details to your .env file:
OPENOBSERVE_URL=http://localhost:5080 OPENOBSERVE_ORGANIZATION=default OPENOBSERVE_STREAM=laravel-logs OPENOBSERVE_EMAIL=your-email@example.com OPENOBSERVE_PASSWORD=your-password
Configuration Options
| Option | Env Variable | Default |
|---|---|---|
url |
OPENOBSERVE_URL |
http://localhost:5080 |
organization |
OPENOBSERVE_ORGANIZATION |
default |
stream |
OPENOBSERVE_STREAM |
default |
auth.email |
OPENOBSERVE_EMAIL |
- |
auth.password |
OPENOBSERVE_PASSWORD |
- |
timeout |
OPENOBSERVE_TIMEOUT |
5 |
ssl_verify |
OPENOBSERVE_SSL_VERIFY |
true |
timeout and ssl_verify are applied to the Guzzle HTTP client that the service provider builds and injects into the OpenObserve client.
Laravel Logging Channel Setup
Add the OpenObserve channel to your config/logging.php:
'channels' => [ // ... existing channels 'openobserve' => [ 'driver' => 'custom', 'via' => \Minhyung\LaravelOpenObserve\Logging\OpenObserveLogger::class, 'level' => env('LOG_LEVEL', 'debug'), 'name' => 'openobserve', ], // Optionally include openobserve in a stack channel 'stack' => [ 'driver' => 'stack', 'channels' => ['single', 'openobserve'], 'ignore_exceptions' => false, ], ],
Set the default log channel in your .env file:
LOG_CHANNEL=stack # or 'openobserve'
Usage
Laravel Logging
Use it just like standard Laravel logging:
use Illuminate\Support\Facades\Log; Log::info('User logged in', ['user_id' => 123]); Log::error('An error occurred', ['error' => $exception->getMessage()]);
Direct Client Access
The container resolves a configured Minhyung\OpenObserve\Client. Use the Facade or dependency injection to access it.
use Minhyung\LaravelOpenObserve\Facades\OpenObserve; OpenObserve::logs()->json('laravel-logs', [ ['level' => 'info', 'message' => 'User action', 'user_id' => 123], ]);
use Minhyung\OpenObserve\Client; class SomeController extends Controller { public function __construct(private Client $openObserve) { } public function index() { $this->openObserve->logs()->json('laravel-logs', [ ['level' => 'info', 'message' => 'Controller executed'], ]); } }
See minhyung/openobserve for the full client API (search, streams, alerts, dashboards, OTLP, etc.).
Connection Test
php artisan openobserve:test
This command sends one test log to the configured stream. It exits with code 0 only when the response has code: 200 and exactly one result for that stream with successful >= 1 and failed: 0, using integer counts. This follows the OpenObserve JSON ingestion response.
Missing connection settings, authentication or transport errors, rejected records, and missing or unrecognized ingestion results return exit code 1 with a diagnostic message. Legacy or custom response formats without per-stream counts cannot confirm ingestion and also fail. Exception details and raw response bodies are not printed.
Testing
Install development dependencies, then run the tests. The standard PHPUnit configuration is discovered automatically; no configuration file needs to be copied. Tests use fixed configuration and mock HTTP clients, so no OpenObserve server or credentials are required.
composer install
composer test
Code quality commands:
composer lint # Check formatting with Pint composer format # Apply formatting composer analyse # Analyse src with Larastan / PHPStan level 6 composer check # Validate Composer metadata, lint, analyse, and test
CI tests Laravel 13 on the latest PHP 8.4 and 8.5 patches, plus PHP 8.4.1 with the lowest installable stable dependencies.
Security Vulnerabilities
If you discover a security vulnerability, please email urlinee@gmail.com.
License
The MIT License (MIT). Please see License File for more information.