Skip to content

Commit 8ce859c

Browse files
committed
fix: apply insights from test integrations
1 parent fb18a17 commit 8ce859c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Instrumentation/Doctrine/src/AttributesResolver.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenTelemetry\Contrib\Instrumentation\Doctrine;
66

7-
use Doctrine\DBAL\SQL\Parser;
87
use Exception;
98

109
final class AttributesResolver
@@ -72,11 +71,11 @@ private static function getServerPort(array $params): string
7271
/**
7372
* Resolve attribute `db.system`
7473
*/
75-
private static function getDbSystem(array $params): string
74+
private static function getDbSystem(array $params)
7675
{
7776
$dbSystem = $params[1][0]['driver'] ?? null;
7877

79-
if (strpos($dbSystem, 'pdo_') !== false) {
78+
if ($dbSystem && strpos($dbSystem, 'pdo_') !== false) {
8079
// Remove pdo_ word to ignore it while searching well-known db.system
8180
$dbSystem = ltrim($dbSystem, 'pdo_');
8281
}
@@ -89,6 +88,7 @@ private static function getDbSystem(array $params): string
8988
if (isset(self::DB_SYSTEMS_KNOWN[$dbSystem])) {
9089
return self::DB_SYSTEMS_KNOWN[$dbSystem];
9190
}
91+
9292
return 'other_sql';
9393
}
9494

@@ -133,16 +133,17 @@ public static function getDbQuerySummary(array $params): string
133133

134134
// Fetch target name
135135
$matches = [];
136-
preg_match_all('/(from|into|update|join)\s*([a-zA-Z0-9[\]_]+)/i', $query, $matches);
136+
preg_match_all('/(from|into|update|join)\s*([a-zA-Z0-9`"[\]_]+)/i', $query, $matches);
137137

138138
$targetName = null;
139139
if (strtolower($operationName) == 'select') {
140-
if ($matches && isset($matches[2]) && $matches[2]) {
140+
if ($matches[2]) {
141141
$targetName = implode(' ', $matches[2]);
142142
}
143143
} elseif ($matches) {
144144
$targetName = $matches[2][0] ?? '';
145145
}
146+
146147
return $operationName . ($targetName ? ' ' . $targetName : '');
147148
}
148149
}

src/Instrumentation/Doctrine/tests/Integration/DoctrineInstrumentationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ public function test_statement_execution(): void
102102

103103
$connection->executeStatement($statement);
104104
$span = $this->storage->offsetGet(1);
105-
$this->assertSame('Doctrine\DBAL\Driver\Connection::exec', $span->getName());
105+
$this->assertSame('CREATE technology', $span->getName());
106106
$this->assertFalse($connection->isTransactionActive());
107107
$this->assertCount(2, $this->storage);
108108

109109
$connection->prepare('SELECT * FROM `technology`');
110110
$span = $this->storage->offsetGet(2);
111-
$this->assertSame('Doctrine\DBAL\Driver\Connection::prepare', $span->getName());
111+
$this->assertSame('SELECT `technology`', $span->getName());
112112
$this->assertCount(3, $this->storage);
113113

114114
$connection->executeQuery('SELECT * FROM `technology`');
115115
$span = $this->storage->offsetGet(3);
116-
$this->assertSame('Doctrine\DBAL\Driver\Connection::query', $span->getName());
116+
$this->assertSame('SELECT `technology`', $span->getName());
117117
$this->assertCount(4, $this->storage);
118118
}
119119

@@ -128,7 +128,7 @@ public function test_transaction(): void
128128
$statement = self::fillDB();
129129
$connection->executeStatement($statement);
130130
$span = $this->storage->offsetGet(2);
131-
$this->assertSame('Doctrine\DBAL\Driver\Connection::exec', $span->getName());
131+
$this->assertSame('CREATE technology', $span->getName());
132132
$connection->commit();
133133
$span = $this->storage->offsetGet(3);
134134
$this->assertSame('Doctrine\DBAL\Driver\Connection::commit', $span->getName());

0 commit comments

Comments
 (0)