Skip to content

Commit 3384cd0

Browse files
authored
update pdo instrumentation to semconv 1.36.0 (#425)
1 parent be6ffdf commit 3384cd0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Instrumentation/PDO/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"ext-pdo": "*",
1414
"ext-opentelemetry": "*",
1515
"open-telemetry/api": "^1.0",
16-
"open-telemetry/sem-conv": "^1.32",
16+
"open-telemetry/sem-conv": "^1.36",
1717
"symfony/polyfill-mbstring": "^1.31"
1818
},
1919
"suggest": {

src/Instrumentation/PDO/src/PDOInstrumentation.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use OpenTelemetry\Context\Context;
1313
use function OpenTelemetry\Instrumentation\hook;
1414
use OpenTelemetry\SDK\Common\Configuration\Configuration;
15-
use OpenTelemetry\SemConv\TraceAttributes;
15+
use OpenTelemetry\SemConv\Attributes\CodeAttributes;
16+
use OpenTelemetry\SemConv\Attributes\DbAttributes;
1617
use OpenTelemetry\SemConv\Version;
1718
use PDO;
1819
use PDOStatement;
@@ -27,7 +28,7 @@ public static function register(): void
2728
$instrumentation = new CachedInstrumentation(
2829
'io.opentelemetry.contrib.php.pdo',
2930
null,
30-
Version::VERSION_1_32_0->url(),
31+
Version::VERSION_1_36_0->url(),
3132
);
3233
$pdoTracker = new PDOTracker();
3334

@@ -112,7 +113,7 @@ public static function register(): void
112113
$builder = self::makeBuilder($instrumentation, 'PDO::query', $function, $class, $filename, $lineno)
113114
->setSpanKind(SpanKind::KIND_CLIENT);
114115
if ($class === PDO::class) {
115-
$builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8'));
116+
$builder->setAttribute(DbAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8'));
116117
}
117118
$parent = Context::getCurrent();
118119
$span = $builder->startSpan();
@@ -135,7 +136,7 @@ public static function register(): void
135136
$builder = self::makeBuilder($instrumentation, 'PDO::exec', $function, $class, $filename, $lineno)
136137
->setSpanKind(SpanKind::KIND_CLIENT);
137138
if ($class === PDO::class) {
138-
$builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8'));
139+
$builder->setAttribute(DbAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8'));
139140
}
140141
$parent = Context::getCurrent();
141142
$span = $builder->startSpan();
@@ -158,7 +159,7 @@ public static function register(): void
158159
$builder = self::makeBuilder($instrumentation, 'PDO::prepare', $function, $class, $filename, $lineno)
159160
->setSpanKind(SpanKind::KIND_CLIENT);
160161
if ($class === PDO::class) {
161-
$builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8'));
162+
$builder->setAttribute(DbAttributes::DB_QUERY_TEXT, mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8'));
162163
}
163164
$parent = Context::getCurrent();
164165
$span = $builder->startSpan();
@@ -244,7 +245,7 @@ public static function register(): void
244245
$attributes = $pdoTracker->trackedAttributesForStatement($statement);
245246
if (self::isDistributeStatementToLinkedSpansEnabled()) {
246247
/** @psalm-suppress InvalidArrayAssignment */
247-
$attributes[TraceAttributes::DB_QUERY_TEXT] = $statement->queryString;
248+
$attributes[DbAttributes::DB_QUERY_TEXT] = $statement->queryString;
248249
}
249250
/** @psalm-suppress ArgumentTypeCoercion */
250251
$builder = self::makeBuilder($instrumentation, 'PDOStatement::fetchAll', $function, $class, $filename, $lineno)
@@ -271,7 +272,7 @@ public static function register(): void
271272

272273
if (self::isDistributeStatementToLinkedSpansEnabled()) {
273274
/** @psalm-suppress InvalidArrayAssignment */
274-
$attributes[TraceAttributes::DB_QUERY_TEXT] = $statement->queryString;
275+
$attributes[DbAttributes::DB_QUERY_TEXT] = $statement->queryString;
275276
}
276277

277278
/** @psalm-suppress ArgumentTypeCoercion */
@@ -301,9 +302,9 @@ private static function makeBuilder(
301302
/** @psalm-suppress ArgumentTypeCoercion */
302303
return $instrumentation->tracer()
303304
->spanBuilder($name)
304-
->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, sprintf('%s::%s', $class, $function))
305-
->setAttribute(TraceAttributes::CODE_FILE_PATH, $filename)
306-
->setAttribute(TraceAttributes::CODE_LINE_NUMBER, $lineno);
305+
->setAttribute(CodeAttributes::CODE_FUNCTION_NAME, sprintf('%s::%s', $class, $function))
306+
->setAttribute(CodeAttributes::CODE_FILE_PATH, $filename)
307+
->setAttribute(CodeAttributes::CODE_LINE_NUMBER, $lineno);
307308
}
308309
private static function end(?Throwable $exception): void
309310
{

0 commit comments

Comments
 (0)