monitaroo / monitaroo-symfony
Official Monitaroo Bundle for Symfony - Logs, Metrics & Monitoring
Package info
github.com/Monitaroo/monitaroo-symfony
Type:symfony-bundle
pkg:composer/monitaroo/monitaroo-symfony
Requires
- php: ^7.2 || ^8.0
- monitaroo/monitaroo-php: ^1.0.2 || ^2.0.2
- symfony/config: ^2.8 || ^3.4 || ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^2.8 || ^3.4 || ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/framework-bundle: ^2.8 || ^3.4 || ^4.4 || ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^8.0 || ^9.0 || ^10.0
- symfony/monolog-bundle: ^3.0 || ^4.0
Suggests
- symfony/monolog-bundle: To use Monitaroo as a Monolog handler
This package is not auto-updated.
Last update: 2026-03-13 20:07:30 UTC
README
Official Symfony Bundle for Monitaroo - Logs, Metrics & Monitoring.
Installation
composer require monitaroo/monitaroo-symfony
Requirements: PHP 7.2+, Symfony 2.8+
Configuration
Symfony 4+ (Flex)
Create config/packages/monitaroo.yaml:
monitaroo: api_key: '%env(MONITAROO_API_KEY)%'
Add to .env:
MONITAROO_API_KEY=mk_your_api_key
Symfony 2.8 / 3.x
Register the bundle in app/AppKernel.php:
public function registerBundles() { $bundles = [ // ... new Monitaroo\Symfony\MonitarooBundle(), ]; }
Add configuration in app/config/config.yml:
monitaroo: api_key: '%env(MONITAROO_API_KEY)%'
Quick Start
use Monitaroo\Client; class MyController { private $monitaroo; public function __construct(Client $monitaroo) { $this->monitaroo = $monitaroo; } public function index() { // Logging $this->monitaroo->info('User logged in', ['user_id' => 123]); $this->monitaroo->error('Payment failed', ['order_id' => 456]); // Metrics $this->monitaroo->increment('orders.completed'); $this->monitaroo->gauge('queue.size', 42); $this->monitaroo->timing('api.response_time', 145.5); // Timer helper $stop = $this->monitaroo->startTimer('db.query'); $users = $this->repository->findAll(); $stop(); // Records the timing } }
Using with Monolog
Add Monitaroo as a Monolog handler in config/packages/monolog.yaml:
monolog: handlers: monitaroo: type: service id: monitaroo.monolog_handler level: debug
Then use the standard logger:
use Psr\Log\LoggerInterface; class MyService { public function __construct(private LoggerInterface $logger) { } public function doSomething() { $this->logger->info('Something happened'); } }
Full Configuration
monitaroo: # Required: Your API key api_key: '%env(MONITAROO_API_KEY)%' # API endpoint (default: https://api.monitaroo.com) endpoint: 'https://api.monitaroo.com' # Service name (default: project directory name) service: 'my-app' # Environment (default: kernel.environment) environment: 'production' # Host name (auto-detected if not set) host: 'server-01' # Batch size before auto-flush (default: 100) batch_size: 100 # Auto-flush on kernel.terminate (default: true) auto_flush: true
Logging
Log Levels
$monitaroo->trace('Detailed trace'); $monitaroo->debug('Debug info'); $monitaroo->info('General info'); $monitaroo->warn('Warning'); $monitaroo->error('Error occurred'); $monitaroo->fatal('Fatal error');
Context & Tags
// Context becomes searchable attributes $monitaroo->info('Order placed', [ 'order_id' => 123, 'amount' => 99.99, ]); // Tags are indexed for fast filtering $monitaroo->info('Order placed', [ 'order_id' => 123, 'tags' => [ 'type' => 'order', 'country' => 'FR', ], ]);
Exception Logging
try { // ... } catch (\Exception $e) { $monitaroo->error('Operation failed', [ 'exception' => $e, ]); }
Metrics
Counter
$monitaroo->increment('api.requests'); $monitaroo->increment('items.sold', 5); $monitaroo->increment('api.requests', 1, ['endpoint' => '/users']);
Gauge
$monitaroo->gauge('queue.size', $queueSize); $monitaroo->gauge('memory.mb', memory_get_usage(true) / 1024 / 1024);
Timer
// Manual $start = microtime(true); $result = $this->doSomething(); $monitaroo->timing('operation.duration', (microtime(true) - $start) * 1000); // Using helper $stop = $monitaroo->startTimer('db.query', ['table' => 'users']); $users = $repository->findAll(); $stop();
Histogram
$monitaroo->histogram('order.amount', $order->getTotal());
Auto-Flush
Logs and metrics are automatically flushed on kernel.terminate event, after the response is sent to the client.
To disable auto-flush:
monitaroo: auto_flush: false
Then manually flush:
$monitaroo->flush();
Console Commands
For console commands, logs are flushed when the command finishes (via shutdown handler).
For long-running commands, call flush() periodically:
while ($processing) { // ... process items $monitaroo->flush(); }
License
MIT License. See LICENSE for details.