Note: This is a read-only subtree split of open-telemetry/opentelemetry-php-contrib.
OpenTelemetry SQL Commenter for PHP provides a SqlCommenter implementation, enabling you to inject trace and context comments into SQL queries for enhanced observability and distributed tracing.
Install via Composer:
composer require open-telemetry/opentelemetry-sqlcommenterInject comments into your SQL query as follows:
use OpenTelemetry\SqlCommenter\SqlCommenter;
$comments = [
    'traceparent' => '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00',
    'custom' => 'value',
];
$query = SqlCommenter::inject($query, $comments);- 
Context Propagators Set the propagators to use (comma-separated): OTEL_PHP_SQLCOMMENTER_CONTEXT_PROPAGATORS=tracecontext Default: ''
- 
SQL Commenter Attribute Add SQL comments to DbAttributes::DB_QUERY_TEXTin span attributes:otel.sqlcommenter.attribute = trueor via environment variable: OTEL_PHP_SQLCOMMENTER_ATTRIBUTE=true Default: false
- 
Prepend Comments Prepend comments to the query statement using either a configuration directive: otel.sqlcommenter.prepend = trueor via environment variable: OTEL_PHP_SQLCOMMENTER_PREPEND=true Default: false
Install dependencies and run tests from the SqlCommenter subdirectory:
composer install
./vendor/bin/phpunit tests