Skip to content

opentelemetry-php/contrib-sqlcommenter

Repository files navigation

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

About

[READONLY] OpenTelemetry SqlCommenter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages