定制 check24-cp/newrelic-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

check24-cp/newrelic-bundle

Composer 安装命令:

composer require check24-cp/newrelic-bundle

包简介

Enhanced interaction with NewRelic from within a Symfony environment, ensuring optimal monitoring and logging for your applications

README 文档

README

Introduction

This bundle provides an enhanced interaction with NewRelic from within a Symfony environment, ensuring optimal monitoring and logging for your applications.

Features

  • Transactions: Automatically push transactions to New Relic.
  • Transaction Naming Strategies: Configurable strategies for both HTTP requests and CLI (eg: messenger).
  • Logs: Push logs to NewRelic, linking them together using traceId. The bundle also provides batching for optimal performance, configurable via the logging.buffer_size.
  • Transaction Exclusion: Exclude specific transactions based on Symfony route name, path, or even commands.
  • Exception Exclusion: Exclude specific exceptions to prevent them from appearing in NewRelic Error inbox, e.g., HttpExceptions.

Installation

To install the CHECK24 New Relic bundle, use composer:

composer require check24-cp/newrelic-bundle

Configuration

After installing the bundle, you need to configure it to suit your application's needs. Here's a detailed explanation of each configuration option based on the provided extension:

Basic Configuration

  • appname: The application name. If not set, it defaults to ini_get('newrelic.appname').
  • license: Your NewRelic license. If not set, defaults to ini_get('newrelic.license').
  • xmit: A boolean indicating if data should be transmitted to NewRelic immediately, defaults to false.
  • interactor: The service ID of the NewRelic interactor used to communicate with the agent. Defaults to check24.new_relic.interactor.
  • logging.buffer_size: Determines the number of log entries to buffer before sending them to NewRelic in bulk. The range is from 1 to 1000, with a default of 100.

Transaction Naming

  • transaction_naming.messenger: Service ID for the strategy used to name messenger transactions. Defaults to check24.new_relic.transaction_name.messenger.message_name.
  • transaction_naming.request: Service ID for the strategy used to name HTTP request transactions. Defaults to check24.new_relic.transaction_name.request.route_name.

Exclusions

  • excluded_transactions.commands: An array of CLI commands to exclude from NewRelic.
  • excluded_transactions.routes: An array of Symfony route names to exclude from NewRelic.
  • excluded_transactions.paths: An array of HTTP paths to exclude from NewRelic.
  • excluded_exceptions: An array of exception classes to exclude from NewRelic's error inbox.

Trace ID

  • trace_id_factory: Service ID for the factory responsible for creating a unique trace ID for each request or message. Defaults to check24.new_relic.trace_id.uuid_factory.

Example Configuration using Symfony Yaml

Here's a basic example of how you might configure the bundle using Symfony's yaml:

check24_new_relic:
    appname: "My Symfony App"
    license: "YOUR_NEWRELIC_LICENSE_KEY"
    xmit: false
    interactor: 'custom.new_relic.interactor'
    logging:
        buffer_size: 200
    transaction_naming:
        messenger: 'custom.transaction_name.messenger'
        request: 'custom.transaction_name.request'
    excluded_transactions:
        commands:
            - 'app:exclude-this-command'
        routes:
            - 'exclude_route_name'
        paths:
            - '/exclude-this-path'
    excluded_exceptions:
        - 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'
    trace_id_factory: 'custom.trace_id.factory'

when@dev:
    check24_new_relic:
      # This is useful to be able to get logs about different NewRelic events in Symfony's profiler
      interactor: 'check24.new_relic.logging_interactor'

Adjust the values as per your requirements. Ensure you replace placeholders like YOUR_NEWRELIC_LICENSE_KEY with actual values.

Integration with Monolog

One of the standout features of this bundle is the ability to seamlessly integrate logging with NewRelic, linking them via a trace.id. This ensures you have all the necessary context when diagnosing issues, as you can see related logs in NewRelic that correspond to a particular request or process. It eliminates the disconnect often seen when logs and monitoring are handled separately. In times of issues or outages, having this cohesive view can be invaluable, allowing for rapid diagnosis and resolution.

To harness this logging integration, you need to configure your monolog settings specifically to support the NewRelicHandler provided by this bundle.

Update your config/packages/monolog.yaml with the following configuration:

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: error
            handler: nested
            excluded_http_codes:
                - 404
                - 405
            channels: ['!event']
        nested:
            type: service
            id: 'check24.new_relic.monolog_handler'

Integration with Messenger

To be able to track messages received with Messenger, you need to update config/packages/messenger with the following configuration:

framework:
    messenger:
        buses:
            default:
                middleware:
                    - check24.new_relic.messenger_middleware

Now the bundle should be able to report each consumed message as a separate transaction, using the message name (see Configuration/Transaction Naming section) as the transaction name.

check24-cp/newrelic-bundle 适用场景与选型建议

check24-cp/newrelic-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.28k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 22.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-24