https://github.com/opentelemetry-php/contrib-sqlcommenter
[READONLY] OpenTelemetry SqlCommenter
https://github.com/opentelemetry-php/contrib-sqlcommenter
Last synced: 6 months ago
JSON representation
[READONLY] OpenTelemetry SqlCommenter
- Host: GitHub
- URL: https://github.com/opentelemetry-php/contrib-sqlcommenter
- Owner: opentelemetry-php
- Created: 2025-10-05T09:46:52.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-05T09:47:29.000Z (9 months ago)
- Last Synced: 2025-10-06T01:44:02.797Z (9 months ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/opentelemetry-php/contrib-sqlcommenter/releases)
[](https://github.com/open-telemetry/opentelemetry-php/issues)
[](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/SqlCommenter)
[](https://github.com/opentelemetry-php/contrib-sqlcommenter)
[](https://packagist.org/packages/open-telemetry/opentelemetry-sqlcommenter/)
[](https://packagist.org/packages/open-telemetry/opentelemetry-sqlcommenter/)
> **Note:** This is a read-only subtree split of [open-telemetry/opentelemetry-php-contrib](https://github.com/open-telemetry/opentelemetry-php-contrib).
# OpenTelemetry SQL Commenter
OpenTelemetry SQL Commenter for PHP provides a [SqlCommenter](https://opentelemetry.io/docs/specs/semconv/database/database-spans/#sql-commenter) implementation, enabling you to inject trace and context comments into SQL queries for enhanced observability and distributed tracing.
## Installation
Install via Composer:
```bash
composer require open-telemetry/opentelemetry-sqlcommenter
```
## Usage
Inject comments into your SQL query as follows:
```php
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):
```shell
OTEL_PHP_SQLCOMMENTER_CONTEXT_PROPAGATORS=tracecontext
```
Default: `''`
- **SQL Commenter Attribute**
Add SQL comments to `DbAttributes::DB_QUERY_TEXT` in span attributes:
```shell
otel.sqlcommenter.attribute = true
```
or via environment variable:
```shell
OTEL_PHP_SQLCOMMENTER_ATTRIBUTE=true
```
Default: `false`
- **Prepend Comments**
Prepend comments to the query statement using either a configuration directive:
```shell
otel.sqlcommenter.prepend = true
```
or via environment variable:
```shell
OTEL_PHP_SQLCOMMENTER_PREPEND=true
```
Default: `false`
## Development
Install dependencies and run tests from the `SqlCommenter` subdirectory:
```bash
composer install
./vendor/bin/phpunit tests
```