1. Go to this page and download the library: Download waffle-commons/telemetry library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
waffle-commons / telemetry example snippets
use Waffle\Commons\Contracts\Telemetry\Metrics\MetricsCollectorInterface;
use Waffle\Commons\Contracts\Telemetry\Metrics\MetricsRegistryInterface;
use Waffle\Commons\Contracts\Telemetry\Metrics\NullMetricsRegistry;
use Waffle\Commons\Telemetry\Collector\GcCollector;
use Waffle\Commons\Telemetry\Collector\MemoryCollector;
use Waffle\Commons\Telemetry\Collector\PoolUtilizationCollector;
use Waffle\Commons\Telemetry\Exporter\PrometheusExporter;
use Waffle\Commons\Telemetry\Metric\ApcuMetricStore;
use Waffle\Commons\Telemetry\Metric\MetricsRegistry;
use Waffle\Commons\Telemetry\Middleware\MetricsMiddleware;
use Waffle\Commons\Telemetry\Middleware\TracingMiddleware;
// Counters in APCu shared memory (never the worker heap); no-op fallback without APCu.
$metricsRegistry = apcu_enabled() ? new MetricsRegistry(new ApcuMetricStore()) : new NullMetricsRegistry();
$container->set(MetricsRegistryInterface::class, $metricsRegistry);
$collectors = [new MemoryCollector(), new GcCollector(), new PoolUtilizationCollector()];
if ($metricsRegistry instanceof MetricsCollectorInterface) {
$collectors[] = $metricsRegistry; // the registry is itself a collector — export its own counters too
}
// Placed early: /waffle-metrics short-circuits before the application pipeline and applies
// its own fail-closed security — localhost only by default; pass a bearer token to allow a
// remote scrape.
$stack->add(new MetricsMiddleware(
new PrometheusExporter($collectors),
$responseFactory,
$streamFactory,
bearerToken: null,
allowedIps: ['127.0.0.1', '::1'],
));
// Opens the server root span (extracts an inbound `traceparent`) and records request
// count + duration; no-op cost while $tracer is the contract's NullTracer.
$stack->add(new TracingMiddleware($tracer, $metricsRegistry, $tracePropagator));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.