myschoolmanagement/elastic-apm-symfony-bundle
A Symfony bundle that integrates Elastic APM with your application, providing distributed tracing, transaction and error monitoring, and performance insights. Track requests, identify bottlenecks, and diagnose failures with minimal setup and configuration.
myschoolmanagement/elastic-apm-symfony-bundle), not a Laravel package. Before adding it, inspect the README, composer.json, DependencyInjection/, and EventListener/ to confirm which Symfony/Laravel versions are supported and whether a Laravel adapter is expected. In a stock Laravel app you will usually need a small service provider or middleware bridge.php -m | grep apm (or the agent is configured for your runtime). Without it, instrumentation silently does nothing.composer require myschoolmanagement/elastic-apm-symfony-bundle
ELASTIC_APM_SERVICE_NAME=my-laravel-app
ELASTIC_APM_SERVER_URL=http://apm-server:8200
ELASTIC_APM_ENABLED=true
ELASTIC_APM_ENVIRONMENT=local
Publish or create the package config (config/elastic_apm.php or the bundle's equivalent) and register the bundle service provider in bootstrap/providers.php / config/app.php if you are bridging it manually.EventListener/ directory (especially anything now bound to kernel.finish_request), its DI configuration, and the agent's own log (ELASTIC_APM_LOG_LEVEL=debug).HttpKernel bridge, implement equivalent start/end calls in a Laravel middleware.handle(),terminate() so it runs after the response is sent.
This mirrors the intent of the 1.0.6 FINISH_REQUEST change without depending on Symfony's dispatcher.$span = elastic_apm_begin_span('external-api', 'external.http');
try {
$response = Http::get('https://api.example.com/report');
} finally {
elastic_apm_end_span($span);
}
Use this for outbound HTTP, heavy file operations, and expensive domain logic that is not auto-instrumented.elastic_apm_set_user_context(id: (string) $request->user()?->id);
elastic_apm_set_custom_context([
'tenant' => tenant()->id,
'route' => $request->route()?->getName(),
]);
Keep values low-cardinality and non-sensitive.App\Exceptions\Handler::report() or a dedicated listener. This gives you APM errors even when your Laravel log handler is configured differently.handle() methods and command handle() methods in explicit transactions:
$tx = elastic_apm_begin_transaction('job.process-order', 'job');
try {
// job work
} finally {
elastic_apm_end_transaction($tx);
}
Add labels such as job class, queue name, and attempt count.ELASTIC_APM_ENABLED=false in local test suites unless you are actively debugging traces.ELASTIC_APM_TRANSACTION_SAMPLE_RATE to control overhead in high-traffic apps.php artisan config:cache after changes.kernel.finish_request. This is a reliability fix: transactions and listeners are now closed at the very end of the request lifecycle, which helps when exceptions or early responses previously prevented listeners from running. The practical impact is that transaction data may appear slightly later in APM, and any code that assumes a transaction has already ended before the response is sent may need adjustment.kernel.finish_request is not a Laravel-native lifecycle event. Laravel's Illuminate\Foundation\Http\Kernel does not dispatch Symfony's kernel.finish_request by default. If you are not using a Symfony HttpKernel bridge, the 1.0.6 change will not automatically apply to your app. Use terminable middleware or an explicit shutdown hook to close transactions.finish_request never fires in a long-running worker. Instrument jobs and commands manually; otherwise you will see HTTP traces but no queue or CLI traces.exit, dd, and hard process termination in instrumented paths. These can bypass listener execution and drop the transaction. Let Laravel's response lifecycle complete normally.php -m, ELASTIC_APM_ENABLED, and the agent log. The bundle cannot instrument anything without the underlying agent.transaction_sample_rate is below 1.0, some transactions are intentionally not sampled. Do not debug this as a package failure; set the rate to 1.0 temporarily in a staging environment.php artisan config:cache (or clear it) and restart PHP-FPM/workers. Long-running workers hold old config in memory.How can I help you explore Laravel packages today?