nipwaayoni/elastic-apm-php-agent
Laravel-friendly Elastic APM PHP agent for instrumenting apps and sending performance data, errors, and transactions to an Elastic APM Server. Helps monitor response times, slow queries, and exceptions with simple setup and configurable reporting.
elastic-apm-php-agent integrates seamlessly with Laravel’s event-driven and request-response architecture, providing distributed tracing, performance monitoring, and error tracking. It aligns with modern observability stacks (e.g., Elastic APM, OpenTelemetry) and complements Laravel’s built-in logging (Monolog).Redis, Database) and task scheduling (Artisan commands), enabling end-to-end transaction tracing across services.Kernel.php) to auto-instrument HTTP requests, aligning with APM best practices..env), service names, and disabled modes for non-production environments.HttpException, QueryException) with full stack traces?metrics facade or similar?config/apm.php) or must it be manually set in bootstrap/app.php?curl or http extension may be needed for agent-server communication.Illuminate\Http\Request via middleware.Illuminate\Queue\Worker for async trace propagation.queue:work, migrate).composer require nipwaayoni/elastic-apm-php-agent..env:
APM_SERVER_URL=http://elastic-apm-server:8200
APM_SERVICE_NAME=laravel-app
APM_SERVICE_VERSION=1.0.0
app/Http/Kernel.php:
protected $middleware = [
\Nipwaayoni\ElasticApm\Middleware\ApmMiddleware::class,
];
Illuminate\Queue\Worker or using a service provider.ElasticApm\Transaction to manually start/end traces for critical paths (e.g., payment processing).spatie/laravel-monitoring). Audit for duplicate instrumentation.X-Elastic-Apm-Traceparent) don’t interfere with cache invalidation (e.g., stash driver).VCR or a local Elastic APM instance..env to avoid hardcoding.composer require nipwaayoni/elastic-apm-php-agent:^x.y.z with strict version constraints.laravel-monitor or third-party tools (e.g., PagerDuty).APM_TRANSACTION_SAMPLE_RATE=0.1) for high-traffic APIs to reduce Elasticsearch load.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| APM Server Unavailable | Traces dropped; no observability | Graceful degradation (agent continues logging). |
| Elasticsearch Cluster Down | APM UI inaccessible | Use local buffering or fallback to file logging. |
| High Cardinality Traces | Elasticsearch overload | Implement sampling or trace filtering. |
| PHP Agent Crash | Partial observability loss | Monitor agent logs; set up alerts for crashes. |
| Network Partition | Traces not sent to APM server | Configure retry logic or local buffering. |
$transaction = ElasticApm\Transaction::start('payment_processing');
try {
// Business logic
} finally {
$transaction->end();
}
How can I help you explore Laravel packages today?