Download the PHP package watchlog/laravel-apm without Composer
On this page you can find all versions of the php package watchlog/laravel-apm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download watchlog/laravel-apm
More information about watchlog/laravel-apm
Files in watchlog/laravel-apm
Package laravel-apm
Short Description Lightweight APM integration for Laravel apps using Watchlog
License MIT
Informations about the package laravel-apm
Laravel APM โ Watchlog Integration
๐ฏ Lightweight, production-ready Application Performance Monitoring (APM) middleware for Laravel apps, designed for Watchlog.
Tracks request duration, memory usage, and status codes โ stores metrics in a buffer file, and automatically flushes them to your Watchlog Agent every 10 seconds.
๐ Features
- โ Compatible with Laravel 10 & 12+
- ๐ง Smart file-based metric buffering (no database or queue needed)
- ๐ Aggregates metrics per route (e.g.
/users/{id}) - ๐ Tracks duration, memory, and status codes
- ๐ Safe and non-blocking โ doesn't slow down your requests
- ๐ Sends data automatically every 10 seconds to your Watchlog Agent
- ๐ท๏ธ Auto-detects service name from
.env(WATCHLOG_APM_SERVICEor fallback toAPP_NAME)
๐ฆ Installation
1. Link local package (for development)
Adjust the path to match your local project structure.
โ๏ธ Usage (Laravel 12+)
In your bootstrap/app.php, register the middleware:
๐ ๏ธ Configuration
Service Identification
You can define your service name explicitly in .env:
If not set, it will fallback to:
Agent URL Configuration
The package automatically detects the agent endpoint, but you can override it for Docker:
Option 1: Environment Variable (Recommended for Docker)
Option 2: Config File
Publish the config file (if available) or add to your config/services.php:
Option 3: Direct Usage
If not provided, the package will auto-detect:
- Local / non-K8s:
http://127.0.0.1:3774/apm - Kubernetes:
http://watchlog-node-agent.monitoring.svc.cluster.local:3774/apm
๐ค How it works
During each request:
- The middleware tracks route, status code, duration, and memory.
- The data is written to a file:
storage/logs/apm-buffer.json
After the request ends:
- A shutdown function checks if 10 seconds have passed since the last flush.
- If yes, it:
- Reads all pending metrics from
apm-buffer.json - Aggregates them by route/method
- Sends them to your Watchlog Agent as a JSON payload
- Clears the buffer
- Reads all pending metrics from
๐ฆ What gets sent?
๐ File structure
๐งช Debugging & Testing
You can manually flush metrics via tinker:
๐ Recommended .gitignore
Add the following to your Laravel app's .gitignore:
๐ณ Docker Setup
When running your Laravel app in Docker, configure the agent URL:
Docker Compose Example:
Docker Run Example:
Important Notes:
- When using Docker, use the container name as the hostname (e.g.,
watchlog-agent) - Both containers must be on the same Docker network
- The agent must be running before your app starts
- Set
WATCHLOG_APM_AGENT_URLin your.envfile or as an environment variable - If
WATCHLOG_APM_AGENT_URLis not provided, auto-detection will be used (local or Kubernetes)
โ Notes
- The route path is captured via
$request->route()?->uri()for correct dynamic segment grouping (/users/{id}) - Multiple requests within 10 seconds are buffered, then aggregated and sent in a single payload
- The flush lock uses a simple file timestamp (
watchlog-apm.lock) to prevent oversending - The middleware is safe: flush failures won't crash your app
๐ License
MIT ยฉ Mohammadreza
Built for Watchlog.io