<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
grzegorzdrozd / opentelemetry-metrics-pdo example snippets
$m = Globals::meterProvider();
// meterProvider returns MeterProviderInterface interface but actual implementation has forceFlush method
if ($m instanceof \OpenTelemetry\SDK\Metrics\MeterProvider) {
$m->forceFlush();
}
// Add a single attribute
PDOMetrics::addAttribute('key', 'value'); // globally
PDOMetrics::addAttribute('key', 'value', $pdoInstance); // for specific PDO instance
PDOMetrics::addAttribute('key', 'value', $pdoStmt); // for specific Statement instance
// Add multiple attributes at once
PDOMetrics::addAttributes(['key1' => 'value1', 'key2' => 'value2']); // globally
PDOMetrics::addAttributes(['key1' => 'value1', 'key2' => 'value2'], $pdoInstance); // for specific PDO instance
PDOMetrics::addAttributes(['key1' => 'value1', 'key2' => 'value2'], $pdoStmt); // for specific Statement instance
// Remove an attribute
PDOMetrics::removeAttribute('key'); // globally
PDOMetrics::removeAttribute('key', $pdoInstance); // for specific PDO instance
PDOMetrics::removeAttribute('key', $pdoStmt); // for specific Statement instance
// Get current attributes
$attributes = PDOMetrics::getAttributes(); // get global attributes
$attributes = PDOMetrics::getAttributes($pdoInstance); // get attributes for specific PDO instance
$attributes = PDOMetrics::getAttributes($pdoStmt); // get attributes for specific Statement instance