diff --git a/README.md b/README.md new file mode 100644 index 0000000..a14563e --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Utopia Telemetry + +![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/telemetry.svg) +[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://appwrite.io/discord) + +Utopia Telemetry is a powerful Telemtry library. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io). + +Although this library is part of the [Utopia System](https://github.com/utopia-php) project it is dependency free and can be used as standalone with any other PHP project or framework. + +## Getting Started + +Install using composer: + +```bash +composer require utopia-php/telemetry +``` + +Init in your application: + +```php +createUpDownCounter('http.server.active_requests', '{request}'); + +$counter->add(1); +$counter->add(2); + +// Periodically collect metrics and send them to the configured OpenTelemetry endpoint. +$telemetry->collect(); + +// Example using Swoole +\Swoole\Timer::tick(60_000, fn () => $telemetry->collect()); +``` + +## System Requirements + +Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible. + +## Copyright and license + +The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php) diff --git a/phpstan.neon b/phpstan.neon index a76a832..8886f7f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,4 @@ parameters: level: 5 paths: - - src - - tests \ No newline at end of file + - src \ No newline at end of file diff --git a/src/Telemetry/Adapter/Noop.php b/src/Telemetry/Adapter/None.php similarity index 97% rename from src/Telemetry/Adapter/Noop.php rename to src/Telemetry/Adapter/None.php index e65cd97..9e255fc 100644 --- a/src/Telemetry/Adapter/Noop.php +++ b/src/Telemetry/Adapter/None.php @@ -8,7 +8,7 @@ use Utopia\Telemetry\Histogram; use Utopia\Telemetry\UpDownCounter; -class Noop implements Adapter +class None implements Adapter { public function createCounter(string $name, ?string $unit = null, ?string $description = null, array $advisory = []): Counter { diff --git a/src/Telemetry/Adapter/OpenTelemetry.php b/src/Telemetry/Adapter/OpenTelemetry.php index 9a5ce29..d2e6de9 100644 --- a/src/Telemetry/Adapter/OpenTelemetry.php +++ b/src/Telemetry/Adapter/OpenTelemetry.php @@ -11,6 +11,7 @@ use OpenTelemetry\Contrib\Otlp\MetricExporter; use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory; use OpenTelemetry\SDK\Common\Attribute\Attributes; +use OpenTelemetry\SDK\Common\Attribute\AttributesInterface; use OpenTelemetry\SDK\Metrics\MeterProvider; use OpenTelemetry\SDK\Metrics\MetricExporterInterface; use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader; @@ -40,7 +41,7 @@ public function __construct(string $endpoint, string $serviceNamespace, string $ $this->meter = $this->initMeter($exporter, $attributes); } - protected function initMeter(MetricExporterInterface $exporter, Attributes $attributes): MeterInterface + protected function initMeter(MetricExporterInterface $exporter, AttributesInterface $attributes): MeterInterface { $this->reader = new ExportingReader($exporter); $meterProvider = MeterProvider::builder()