log-engine/logengine-php

此包已被废弃,不再维护。没有推荐替代包。

PHP应用程序的检查器。


README

Total Downloads Latest Stable Version License Contributor Covenant Build Status

在继续之前,请考虑给我们一个 GitHub 星星 ⭐️。谢谢!

为PHP开发者构建的代码执行监控。

要求

  • PHP >= 7.2.0

安装

通过以下方式安装最新版本:

composer require inspector-apm/inspector-php

使用

要开始向Inspector发送数据,您需要一个Ingestion Key来创建Configuration类的实例。您可以在Inspector仪表板上创建一个新项目来获取INSPECTOR_API_KEY

use Inspector\Inspector;
use Inspector\Configuration;

$configuration = new Configuration('YOUR_INGESTION_KEY');
$inspector = new Inspector($configuration);

所有内容都以transaction开始。事务表示一个执行周期,它可以包含一个或多个段。

// Start an execution cycle with a transaction
$inspector->startTransaction($_SERVER['PATH_INFO']);

使用addSegment方法来监视事务中的代码块

$result = $inspector->addSegment(function ($segment) {
    // Do something here...
	return "Hello World!";
}, 'my-process');

echo $result; // this will print "Hello World!"

Inspector将实时监控您的代码执行,并在发生错误时向您发出警报。

自定义传输

您还可以设置自定义传输类,以个性化的方式将监控数据从您的服务器传输到Inspector。

传输类需要实现\Inspector\Transports\TransportInterface

class CustomTransport implements \Inspector\Transports\TransportInterface
{
    protected $configuration;

    protected $queue = [];

    public function __constructor($configuration)
    {
        $this->configuration = $configuration;
    }

    public function addEntry(\Inspector\Models\Arrayable $entry)
    {
        // Add an \Inspector\Models\Arrayable entry in the queue.
        $this->queue[] = $entry;
    }

    public function flush()
    {
        // Performs data transfer.
        $handle = curl_init('https://ingest.inspector.dev');
        curl_setopt($handle, CURLOPT_POST, 1);
        curl_setopt($handle, CURLOPT_HTTPHEADER, [
            'X-Inspector-Key: xxxxxxxxxxxx',
            'Content-Type: application/json',
            'Accept: application/json',
        ]);
        curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($this->queue));
        curl_exec($handle);
        curl_close($handle);
    }
}

然后您可以使用回调设置Inspector实例的新传输,该回调将接收当前配置状态作为参数。

$inspector->setTransport(function ($configuration) {
    return new CustomTransport($configuration);
});

查看官方文档

贡献

我们鼓励您为Inspector做出贡献!请查看有关如何进行的贡献指南。加入我们!

授权协议

此包根据MIT授权协议授权。