open-telemetry/opentelemetry-sqlcommenter

OpenTelemetry sqlcommenter.

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/open-telemetry/opentelemetry-sqlcommenter

dev-main 2025-10-05 09:47 UTC

This package is auto-updated.

Last update: 2025-10-06 16:27:09 UTC


README

Releases Issues Source Mirror Latest Version Stable

Note: This is a read-only subtree split of open-telemetry/opentelemetry-php-contrib.

OpenTelemetry SQL Commenter

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.

Installation

Install via Composer:

composer require open-telemetry/opentelemetry-sqlcommenter

Usage

Inject comments into your SQL query as follows:

use OpenTelemetry\SqlCommenter\SqlCommenter;

$comments = [
    'traceparent' => '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00',
    'custom' => 'value',
];
$query = SqlCommenter::inject($query, $comments);

Configuration

  • 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_TEXT in span attributes:

    otel.sqlcommenter.attribute = true

    or 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 = true

    or via environment variable:

    OTEL_PHP_SQLCOMMENTER_PREPEND=true

    Default: false

Development

Install dependencies and run tests from the SqlCommenter subdirectory:

composer install
./vendor/bin/phpunit tests