neeckeloo / newrelic
NewRelic模块用于Laminas
Requires
- php: ^7.2
- laminas/laminas-console: ^2.6
- laminas/laminas-eventmanager: ^2.6 || ^3.0
- laminas/laminas-http: ^2.5
- laminas/laminas-mvc: ^2.7 || ^3.0
- laminas/laminas-servicemanager: ^2.7 || ^3.0
- laminas/laminas-stdlib: ^3.2.1
- monolog/monolog: ^1.17 || ^2.0
- psr/container: 1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpspec/prophecy: ^1.9
- phpunit/phpunit: ^8.5.8
Conflicts
README
NewRelic模块为New Relic监控服务提供一个面向对象的PHP包装器。
简介
NewRelic模块提供日志记录器和New Relic PHP API的包装器。
当前路由用于设置每个事务的名称。此外,如果启用,模块允许异常记录。
要求
- PHP ^7.2
- Laminas
安装
NewRelic模块仅通过Composer官方支持安装。有关Composer文档,请参阅 getcomposer.org。
您可以从命令行安装该模块
$ composer require neeckeloo/newrelic
或者,您也可以手动在您的composer.json
文件中添加依赖项
{ "require": { "neeckeloo/newrelic": "^2.5" } }
通过在您的application.config.php
文件中添加NewRelic
键来启用模块。通过将newrelic.global.php.dist
文件复制到您的config/autoload
文件夹中来自定义模块。
默认配置
return [ 'newrelic' => [ // Sets the newrelic app name. Note that this will discard metrics // collected before the name is set. If empty then your php.ini // configuration will take precedence. You can set the value by // environment variable, or by overriding in a local config. 'application_name' => getenv('NEW_RELIC_APP_NAME') ?: null, // May be null and will only be set if application name is also given. // You can set the value by environment variable, or by overriding in // a local config. 'license' => getenv('NEW_RELIC_LICENSE_KEY ') ?: null, // If false then neither change the auto_instrument or manually // instrument the real user monitoring. 'browser_timing_enabled' => false, // When true tell the newrelic extension to insert Real User Monitoring // scripts automatically. 'browser_timing_auto_instrument' => true, // When true, a logger with the newrelic writer will be called for // dispatch error events. 'exceptions_logging_enabled' => false, // Defines ignored transactions 'ignored_transactions' => [], // Defines background job transactions 'background_jobs' => [], ], ];
用法
定义事务名称
该模块使用NewRelic\Listener\RequestListener
通过默认情况下通过匹配路由名称来自动指定事务名称。
事务名称提供者
事务名称从配置中定义的提供者(默认为NewRelic\TransactionNameProvider\RouteNameProvider
)检索。
use NewRelic\TransactionNameProvider\RouteNameProvider; return [ 'newrelic' => [ 'transaction_name_provider' => RouteNameProvider::class, ], ];
该软件包包含一些提供者
- RouteNameProvider
- HttpRequestUrlProvider
- NullProvider
手动指定事务名称
您也可以通过将NullProvider
定义为事务名称提供者并使用客户端的nameTransaction
方法来自定义事务名称。
忽略事务
NewRelic API允许忽略某些事务。此配置定义了一些将被忽略的事务路由和控制器。
忽略路由
return [ 'newrelic' => [ 'ignored_transactions' => [ 'routes' => [ 'admin*', 'user/login', ], ], ], ];
这些规则忽略了所有管理员路由和"user/login"路由。
忽略控制器
return [ 'newrelic' => [ 'ignored_transactions' => [ 'controllers' => [ 'FooController', 'BarController', 'BazController', ], ], ], ];
您也可以忽略指定控制器的某些操作
return [ 'newrelic' => [ 'ignored_transactions' => [ 'controllers' => [ ['FooController', ['foo', 'bar']], ['BarController', ['baz']], ], ], ], ];
手动忽略事务
您可以通过调用NewRelic客户端的ignoreTransaction()
方法手动忽略事务。
$client = $container->get('NewRelic\Client'); $client->ignoreTransaction();
定义后台作业
后台作业的配置与忽略事务相同,但使用以下键background_jobs
。
return [ 'newrelic' => [ 'background_jobs' => [], ], ];
手动定义后台作业
您可以通过调用NewRelic客户端的backgroundJob()
方法手动将事务定义为后台作业。
$client = $container->get('NewRelic\Client'); $client->backgroundJob(true);
忽略apdex指标
您可以使用键ignored_apdex
忽略类似于事务指标的性能指标。
return [ 'newrelic' => [ 'ignored_apdex' => [], ], ];
手动忽略apdex指标
您可以通过调用NewRelic客户端的ignoreApdex()
方法手动忽略apdex指标。
$client = $container->get('NewRelic\Client'); $client->ignoreApdex();
添加自定义指标
$client = $container->get('NewRelic\Client'); $client->addCustomMetric('salesprice', $price);