neeckeloo/newrelic 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

neeckeloo/newrelic

Composer 安装命令:

composer require neeckeloo/newrelic

包简介

NewRelic module for Laminas

README 文档

README

NewRelic module provide an object-oriented PHP wrapper for New Relic monitoring service.

Build Status Latest Stable Version Total Downloads

Introduction

NewRelic module provide a logger and a wrapper for New Relic PHP API.

The current route is used to set the name of each transaction. Moreover, the module allow exceptions logging if enabled.

Requirements

  • PHP ^7.2
  • Laminas

Installation

NewRelic module only officially supports installation through Composer. For Composer documentation, please refer to getcomposer.org.

You can install the module from command line:

$ composer require neeckeloo/newrelic

Alternatively, you can also add manually the dependency in your composer.json file:

{
    "require": {
        "neeckeloo/newrelic": "^2.5"
    }
}

Enable the module by adding NewRelic key to your application.config.php file. Customize the module by copy-pasting the newrelic.global.php.dist file to your config/autoload folder.

Default configuration

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' => [],
    ],
];

Usage

Define transaction name

The module use NewRelic\Listener\RequestListener to specify the transaction name automatically using matched route name by default.

Transaction name providers

The transaction name is retrieved from a provider (NewRelic\TransactionNameProvider\RouteNameProvider by default) defined in the configuration.

use NewRelic\TransactionNameProvider\RouteNameProvider;

return [
    'newrelic' => [
        'transaction_name_provider' => RouteNameProvider::class,
    ],
];

The package contains some providers:

  • RouteNameProvider
  • HttpRequestUrlProvider
  • NullProvider

Specify transaction name manually

You can also defined the transaction name yourself by defining NullProvider as transaction name provider and using nameTransaction method of the client.

Ignore transactions

NewRelic API allows to ignore some transactions. This configuration defines some routes and controllers of transactions that will be ignored.

Ignore routes

return [
    'newrelic' => [
        'ignored_transactions' => [
            'routes' => [
                'admin*',
                'user/login',
            ],
        ],
    ],
];

Those rules ignore all admin routes and the "user/login" route.

Ignore controllers

return [
    'newrelic' => [
        'ignored_transactions' => [
            'controllers' => [
                'FooController',
                'BarController',
                'BazController',
            ],
        ],
    ],
];

You can also ignore some actions of specified controllers :

return [
    'newrelic' => [
        'ignored_transactions' => [
            'controllers' => [
                ['FooController', ['foo', 'bar']],
                ['BarController', ['baz']],
            ],
        ],
    ],
];

Ignore a transaction manually

You can ignore a transaction manually by calling ignoreTransaction() method of NewRelic client.

$client = $container->get('NewRelic\Client');
$client->ignoreTransaction();

Define background jobs

The configuration of background jobs is identical to ignored transactions but use the key background_jobs as below.

return [
    'newrelic' => [
        'background_jobs' => [],
    ],
];

Define a background job manually

You can define a transaction as background job manually by calling backgroundJob() method of NewRelic client.

$client = $container->get('NewRelic\Client');
$client->backgroundJob(true);

Ignore apdex metrics

You can ignore apdex metrics like transaction metrics using the key ignored_apdex.

return [
    'newrelic' => [
        'ignored_apdex' => [],
    ],
];

Ignore apdex metrics manually

You can ignore apdex metrics manually by calling ignoreApdex() method of NewRelic client.

$client = $container->get('NewRelic\Client');
$client->ignoreApdex();

Add custom metric

$client = $container->get('NewRelic\Client');
$client->addCustomMetric('salesprice', $price);

neeckeloo/newrelic 适用场景与选型建议

neeckeloo/newrelic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 209.62k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2013 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「newrelic」 「laminas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 neeckeloo/newrelic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 neeckeloo/newrelic 我们能提供哪些服务?
定制开发 / 二次开发

基于 neeckeloo/newrelic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 209.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 32
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 32
  • Watchers: 3
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-03-07