noccylabs/react-telemetry (0.1.0.1)
Installation
{
"repositories": [{
"type": "composer",
"url": "https://dev.noccylabs.info/api/packages/noccy/composer"
}
]
}composer require noccylabs/react-telemetry:0.1.0.1About this package
ReactPHP Telemetry Core
This library implements the "three pillars of observability", namely metrics, logs and traces. All components are built to function asynchronously, to be resilient to internal faults, and to be as zero-configuration as possible.
Note
This library is under development and is currently to be considered alpha quality software. Anything may change at any time, and nothing may be as it seems. You have been warned.
Installing
$ composer repository add noccylabs composer \
https://dev.noccylabs.info/api/packages/noccylabs/composer
$ composer require noccylabs/react-telemetry
Configuring
$ TELEMETRY_APP=app.vendor.component \
./component
| EnvVar | Description |
|---|---|
| TELEMETRY_APP | App identifier |
| TELEMETRY_SERVER | Telemetry server IP and protocol |
The default configuration is to use the directory name of the script as the
app identifier if TELEMETRY_APP is not explicitly set. Additionally the
server will be configured to be udp:127.0.0.1:19000.
Server
To achieve the goal of a lightweight telemetry library with zero configuration the heavy lifting had to be delegated somewhere. You therefore need to run a telemetryd server somewhere reachable by your service.
Telemetry
All signals make use of a singleton instance of the Telemetry class, so you can simply create the base signal classes and go from there.
Metrics
Metrics
$metrics = new NoccyLabs\React\Telemetry\Metrics\Metrics();
// Increase counter by 1
$metrics->counter("http_request_count");
// Submit the request time to be parsed as a histogram
$metrics->histogram("http_request_time", $time);
Logs
Logs can be ingested using the following methods:
- Using the
TelemetryLoggerPSR-compatible logger - Using the
TelemetryLogHandlerMonolog handler
PSR-compatible approach
$logger = new NoccyLabs\React\Telemetry\Logging\TelemetryLogger(level:'debug');
$logger->info("Ready for action");
$myApp->setLogger($logger);
Note
If your application does a lot of logging, for example during the hanling of a request, there will be a lot of messages sent to the telemetry daemon unless you provide an appropriate level to the constructor.
Monolog-compatible approach
$logger = new Monolog\Logger("main");
$handler = new NoccyLabs\React\Telemetry\Logging\TelemetryLogHandler();
$logger->pushHandler($handler);
$logger->info("Ready for action");
Traces
Traces allow you to follow a request through a system, which can be of particular importance when diagnosing applications consisting of multiple servers, proxies and/or handlers.
Dependencies
Dependencies
| ID | Version |
|---|---|
| noccylabs/pson | ^0.1.0 |
| psr/log | ^3.0 |
| react/datagram | ^1.10 |
| react/event-loop | ^1.6 |
| react/socket | ^1.17 |