Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Instrumentation/PDO/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
21 changes: 11 additions & 10 deletions src/Instrumentation/PDO/src/PDOInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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 */
Expand Down Expand Up @@ -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
{
Expand Down
Loading