From 016e10e496f5792bbc37e44dfc88b807d2640759 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 7 Aug 2025 10:32:07 +1000 Subject: [PATCH] update pdo instrumentation to semconv 1.36.0 --- src/Instrumentation/PDO/composer.json | 2 +- .../PDO/src/PDOInstrumentation.php | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Instrumentation/PDO/composer.json b/src/Instrumentation/PDO/composer.json index 7f6c9a682..c1686f57e 100644 --- a/src/Instrumentation/PDO/composer.json +++ b/src/Instrumentation/PDO/composer.json @@ -13,7 +13,7 @@ "ext-pdo": "*", "ext-opentelemetry": "*", "open-telemetry/api": "^1.0", - "open-telemetry/sem-conv": "^1.32", + "open-telemetry/sem-conv": "^1.36", "symfony/polyfill-mbstring": "^1.31" }, "suggest": { diff --git a/src/Instrumentation/PDO/src/PDOInstrumentation.php b/src/Instrumentation/PDO/src/PDOInstrumentation.php index ddf81c91e..a739d9e38 100644 --- a/src/Instrumentation/PDO/src/PDOInstrumentation.php +++ b/src/Instrumentation/PDO/src/PDOInstrumentation.php @@ -12,7 +12,8 @@ use OpenTelemetry\Context\Context; use function OpenTelemetry\Instrumentation\hook; use OpenTelemetry\SDK\Common\Configuration\Configuration; -use OpenTelemetry\SemConv\TraceAttributes; +use OpenTelemetry\SemConv\Attributes\CodeAttributes; +use OpenTelemetry\SemConv\Attributes\DbAttributes; use OpenTelemetry\SemConv\Version; use PDO; use PDOStatement; @@ -27,7 +28,7 @@ public static function register(): void $instrumentation = new CachedInstrumentation( 'io.opentelemetry.contrib.php.pdo', null, - Version::VERSION_1_32_0->url(), + Version::VERSION_1_36_0->url(), ); $pdoTracker = new PDOTracker(); @@ -112,7 +113,7 @@ public static function register(): void $builder = self::makeBuilder($instrumentation, 'PDO::query', $function, $class, $filename, $lineno) ->setSpanKind(SpanKind::KIND_CLIENT); if ($class === PDO::class) { - $builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8')); + $builder->setAttribute(DbAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8')); } $parent = Context::getCurrent(); $span = $builder->startSpan(); @@ -135,7 +136,7 @@ public static function register(): void $builder = self::makeBuilder($instrumentation, 'PDO::exec', $function, $class, $filename, $lineno) ->setSpanKind(SpanKind::KIND_CLIENT); if ($class === PDO::class) { - $builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8')); + $builder->setAttribute(DbAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8')); } $parent = Context::getCurrent(); $span = $builder->startSpan(); @@ -158,7 +159,7 @@ public static function register(): void $builder = self::makeBuilder($instrumentation, 'PDO::prepare', $function, $class, $filename, $lineno) ->setSpanKind(SpanKind::KIND_CLIENT); if ($class === PDO::class) { - $builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8')); + $builder->setAttribute(DbAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8')); } $parent = Context::getCurrent(); $span = $builder->startSpan(); @@ -244,7 +245,7 @@ public static function register(): void $attributes = $pdoTracker->trackedAttributesForStatement($statement); if (self::isDistributeStatementToLinkedSpansEnabled()) { /** @psalm-suppress InvalidArrayAssignment */ - $attributes[TraceAttributes::DB_QUERY_TEXT] = $statement->queryString; + $attributes[DbAttributes::DB_QUERY_TEXT] = $statement->queryString; } /** @psalm-suppress ArgumentTypeCoercion */ $builder = self::makeBuilder($instrumentation, 'PDOStatement::fetchAll', $function, $class, $filename, $lineno) @@ -271,7 +272,7 @@ public static function register(): void if (self::isDistributeStatementToLinkedSpansEnabled()) { /** @psalm-suppress InvalidArrayAssignment */ - $attributes[TraceAttributes::DB_QUERY_TEXT] = $statement->queryString; + $attributes[DbAttributes::DB_QUERY_TEXT] = $statement->queryString; } /** @psalm-suppress ArgumentTypeCoercion */ @@ -301,9 +302,9 @@ private static function makeBuilder( /** @psalm-suppress ArgumentTypeCoercion */ return $instrumentation->tracer() ->spanBuilder($name) - ->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, sprintf('%s::%s', $class, $function)) - ->setAttribute(TraceAttributes::CODE_FILE_PATH, $filename) - ->setAttribute(TraceAttributes::CODE_LINE_NUMBER, $lineno); + ->setAttribute(CodeAttributes::CODE_FUNCTION_NAME, sprintf('%s::%s', $class, $function)) + ->setAttribute(CodeAttributes::CODE_FILE_PATH, $filename) + ->setAttribute(CodeAttributes::CODE_LINE_NUMBER, $lineno); } private static function end(?Throwable $exception): void {