irfankurniawan/yii2-elastic-apm 问题修复 & 功能扩展

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

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

irfankurniawan/yii2-elastic-apm

最新稳定版本:1.0.4

Composer 安装命令:

composer require irfankurniawan/yii2-elastic-apm

包简介

Elastic Agent for Yii2 Framework

README 文档

README

Elastic Agent for Yii2 Framework

Installation

Let install this module via composer

composer require irfankurniawan/yii2-elastic-apm

Configuration

'apm' => [
    'class' => 'ivoglent\yii2\apm\Module',
    'configs' => [
        'agent' => [
            'serverUrl' => env('APM_SERVER_URL'), // 'localhost:8200', // Host and port of APM server
            'name' => env('APM_SERVICE_NAME'), //'Service name', // Service name
            'token' => env('APM_TOKEN'), // Token
        ],
        'skipExceptions' => [
            // List of exceptions which you want to ignore
            // \yii\web\NotFoundHttpException::class,
            // \yii\web\UnauthorizedHttpException::class,
        ],
        'skipCommands' => [
            // List of command you dont want to track
            // 'rabbitmq/consume',
        ],
    ],
    'enabled' => env('APM_ENABLED') // true // or false,
],

To enable database monitoring, let config the DB command like :

'components' => [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => '',
        'username' => '',
        'password' => '',
        'charset' => 'utf8mb4',
        'commandClass' => APM_ENABLED ? 'ivoglent\yii2\apm\components\db\mysql\Command' : '\yii\db\Command',
    ]
]

NOTE Rememeber add apm module to bootstrap section:

'bootstrap' => ['log', 'apm'],

Transaction

This module will auto start new transaction after BEFORE_REQUEDT event. But you can manual start new transaction on Console application like consumer, etc. Below is the example to see apm transaction

try {
    $transactionId = Uuid::uuid4()->toString();
    $test1 = Yii::$app->getModule('apm')->getAgent()->startTransaction('testet nihhh abwueaue', 'consumer', 222222);
    $test2 = Yii::$app->getModule('apm')->getAgent()->setTransactionId($transactionId);
    $test3 = Yii::$app->getModule('apm')->getAgent()->stopTransaction();
    dd($test1,  $test3);

} catch (\Exception $throwable) {
    $test = Yii::$app->getModule('apm')->getAgent()->notifyException($throwable);
    dd($test);
}

Trace

Start new span

$span = Yii::$app->getModule('apm')->getAgent()->startTrace('Process::'.$reflect->getShortName(), 'process');

and stop :

Yii::$app->getModule('apm')->getAgent()->stopTrace($span->getId());

Error / exception notify

try {

} catch (\Exception $throwable) {
    Yii::$app->getModule('apm')->getAgent()->notifyException($throwable);
}

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2023-11-20