PHP code example of grzegorzdrozd / opentelemetry-metrics-pdo

1. Go to this page and download the library: Download grzegorzdrozd/opentelemetry-metrics-pdo 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/ */

    

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
shell
OTEL_PHP_DISABLED_METRICS=pdo
shell
OTEL_PHP_METRICS_PDO_CONTEXT_TRACKING=false
shell
OTEL_PHP_METRICS_PDO_STATEMENT_TRACKING=false
shell
OTEL_PHP_METRICS_PDO_SEND_ROWS_RETURNED=false