speakol-ads/elastic-apm-laravel
Composer 安装命令:
composer require speakol-ads/elastic-apm-laravel
包简介
A package to integrate Elastic APM into Laravel
README 文档
README
Laravel package of the https://github.com/speakol-ads/elastic-apm-php-agent library, automatically handling transactions and errors/exceptions. If using Illuminate\Support\Facades\Auth the user Id added to the context.
Tested with Laravel 5.8.* and the philkra/elastic-apm-php-agent version 7.*.
Install
composer require speakol-ads/elastic-apm-laravel
Middleware
Laravel
Register as (e.g.) global middleware to be called with every request. https://laravel.com/docs/5.8/middleware#global-middleware
Register the middleware in app/Http/Kernel.php
protected $middleware = [ // ... more middleware \PhilKra\ElasticApmLaravel\Middleware\RecordTransaction::class, ];
Lumen
In bootstrap/app.php register PhilKra\ElasticApmLaravel\Middleware\RecordTransaction::class as middleware:
$app->middleware([ PhilKra\ElasticApmLaravel\Middleware\RecordTransaction::class ]);
Spans
Laravel
A Transaction object is made available via the dependency container and can be used to start a new span at any point in the application. The Span will automatically add itself to the Transaction when it is ended.
// Use any normal Laravel method of resolving the dependency $transaction = app(\PhilKra\ElasticApmLaravel\Apm\Transaction::class); $span = $transaction->startNewSpan('My Span', 'app.component_name'); // do some stuff $span->end();
Lumen
pending
Error/Exception Handling
Laravel
In app/Exceptions/Handler, add the following to the report method:
\ElasticApm::captureThrowable($exception, [], request()->__apm__());
Lumen
not tested yet.
Agent Configuration
Laravel
The following environment variables are supported in the default configuration:
| Variable | Description |
|---|---|
| APM_ACTIVE | true or false defaults to true. If false, the agent will collect, but not send, transaction data. |
| APM_APPNAME | Name of the app as it will appear in APM. |
| APM_APPVERSION | Version of the app as it will appear in APM. |
| APM_SERVERURL | URL to the APM intake service. |
| APM_SECRETTOKEN | Secret token, if required. |
| APM_APIVERSION | APM API version, defaults to v1 (only v1 is supported at this time). |
| APM_USEROUTEURI | true or false defaults to false. The default behavior is to record the URL as sent in the request. This can result in excessive unique entries in APM. Set to true to have the agent use the route URL instead. |
| APM_QUERYLOG | true or false defaults to 'true'. Set to false to completely disable query logging, or to auto if you would like to use the threshold feature. |
| APM_THRESHOLD | Query threshold in milliseconds, defaults to 200. If a query takes longer then 200ms, we enable the query log. Make sure you set APM_QUERYLOG=auto. |
| APM_BACKTRACEDEPTH | Defaults to 25. Depth of backtrace in query span. |
| APM_RENDERSOURCE | Defaults to true. Include source code in query span. |
| APM_CONNECTION_TIMEOUT | Defaults to 10000 millisecond. |
You may also publish the elastic-apm.php configuration file to change additional settings:
php artisan vendor:publish --tag=config
Once published, open the config/elastic-apm.php file and review the various settings.
Laravel Test Setup
Laravel provides classes to support running unit and feature tests with PHPUnit. In most cases, you will want to explicitly disable APM during testing since it is enabled by default. Refer to the Laravel documentation for more information (https://laravel.com/docs/5.8/testing).
Because the APM agent checks it's active status using a strict boolean type, you must ensure your APM_ACTIVE value is a boolean false rather than simply a falsy value. The best way to accomplish this is to create an .env.testing file and include APM_ACTIVE=false, along with any other environment settings required for your tests. This file should be safe to include in your SCM.
speakol-ads/elastic-apm-laravel 适用场景与选型建议
speakol-ads/elastic-apm-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.27k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「monitoring」 「laravel」 「elastic」 「apm」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 speakol-ads/elastic-apm-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 speakol-ads/elastic-apm-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 speakol-ads/elastic-apm-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
A Symfony bundle for chameleon-system/sanitycheck
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Analysis module for finding problematical shop data.
统计信息
- 总下载量: 1.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-21