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
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.3+
- Laravel 11.x or 12.x
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
Testing
composer test
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.