Skip to content

Commit ee41b2a

Browse files
committed
Fixed
1 parent 7aee9ec commit ee41b2a

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

src/Instrumentation/PDO/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ or environment variable:
4545
OTEL_PHP_INSTRUMENTATION_PDO_CONTEXT_PROPAGATION=true
4646
```
4747

48-
The modified query statement by default will not update `TraceAttributes::DB_QUERY_TEXT` due to high cardinality risk, but it can be configured using the following configuration directive:
48+
The modified query statement by default will not update `DbAttributes::DB_QUERY_TEXT` due to high cardinality risk, but it can be configured using the following configuration directive:
4949
```
5050
otel.instrumentation.pdo.context_propagation.attribute = true
5151
```

src/Instrumentation/PDO/src/PDOInstrumentation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public static function register(): void
129129

130130
Context::storage()->attach($span->storeInContext($parent));
131131
if (ContextPropagation::isEnabled() && $sqlStatement !== self::UNDEFINED) {
132-
if (array_key_exists(TraceAttributes::DB_SYSTEM_NAME, $attributes)) {
132+
if (array_key_exists(DbAttributes::DB_SYSTEM_NAME, $attributes)) {
133133
/** @psalm-suppress PossiblyInvalidCast */
134-
switch ((string) $attributes[TraceAttributes::DB_SYSTEM_NAME]) {
134+
switch ((string) $attributes[DbAttributes::DB_SYSTEM_NAME]) {
135135
case 'postgresql':
136136
case 'mysql':
137137
$comments = [];
@@ -182,9 +182,9 @@ public static function register(): void
182182

183183
Context::storage()->attach($span->storeInContext($parent));
184184
if (ContextPropagation::isEnabled() && $sqlStatement !== self::UNDEFINED) {
185-
if (array_key_exists(TraceAttributes::DB_SYSTEM_NAME, $attributes)) {
185+
if (array_key_exists(DbAttributes::DB_SYSTEM_NAME, $attributes)) {
186186
/** @psalm-suppress PossiblyInvalidCast */
187-
switch ((string) $attributes[TraceAttributes::DB_SYSTEM_NAME]) {
187+
switch ((string) $attributes[DbAttributes::DB_SYSTEM_NAME]) {
188188
case 'postgresql':
189189
case 'mysql':
190190
$comments = [];

src/Instrumentation/PDO/tests/Integration/PDOInstrumentationTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use OpenTelemetry\SDK\Trace\SpanExporter\InMemoryExporter;
1515
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
1616
use OpenTelemetry\SDK\Trace\TracerProvider;
17-
use OpenTelemetry\SemConv\TraceAttributes;
17+
use OpenTelemetry\SemConv\Attributes\DbAttributes;
1818
use OpenTelemetry\TestUtils\TraceStructureAssertionTrait;
1919
use PDO;
2020
use PHPUnit\Framework\TestCase;
@@ -85,7 +85,7 @@ public function test_pdo_construct(): void
8585
$this->assertCount(1, $this->storage);
8686
$span = $this->storage->offsetGet(0);
8787
$this->assertSame('PDO::__construct', $span->getName());
88-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
88+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
8989
}
9090

9191
/**
@@ -112,7 +112,7 @@ public function test_pdo_sqlite_subclass(): void
112112
$this->assertCount(1, $this->storage);
113113
$span = $this->storage->offsetGet(0);
114114
$this->assertSame('PDO::connect', $span->getName());
115-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
115+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
116116

117117
// Test that the subclass-specific methods work
118118
$db->createFunction('test_function', static fn ($value) => strtoupper($value));
@@ -121,15 +121,15 @@ public function test_pdo_sqlite_subclass(): void
121121
$db->exec($this->fillDB());
122122
$span = $this->storage->offsetGet(1);
123123
$this->assertSame('PDO::exec', $span->getName());
124-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
124+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
125125
$this->assertCount(2, $this->storage);
126126

127127
// Test that the custom function works
128128
$result = $db->query("SELECT test_function('hello')")->fetchColumn();
129129
$this->assertEquals('HELLO', $result);
130130
$span = $this->storage->offsetGet(2);
131131
$this->assertSame('PDO::query', $span->getName());
132-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
132+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
133133
$this->assertCount(3, $this->storage);
134134
}
135135

@@ -148,32 +148,32 @@ public function test_statement_execution(): void
148148
$db->exec($statement);
149149
$span = $this->storage->offsetGet(1);
150150
$this->assertSame('PDO::exec', $span->getName());
151-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
151+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
152152
$this->assertFalse($db->inTransaction());
153153
$this->assertCount(2, $this->storage);
154154

155155
$sth = $db->prepare('SELECT * FROM `technology`');
156156
$span = $this->storage->offsetGet(2);
157157
$this->assertSame('PDO::prepare', $span->getName());
158-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
158+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
159159
$this->assertCount(3, $this->storage);
160160

161161
$sth->execute();
162162
$span = $this->storage->offsetGet(3);
163163
$this->assertSame('PDOStatement::execute', $span->getName());
164-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
164+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
165165
$this->assertCount(4, $this->storage);
166166

167167
$sth->fetchAll();
168168
$span = $this->storage->offsetGet(4);
169169
$this->assertSame('PDOStatement::fetchAll', $span->getName());
170-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
170+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
171171
$this->assertCount(5, $this->storage);
172172

173173
$db->query('SELECT * FROM `technology`');
174174
$span = $this->storage->offsetGet(5);
175175
$this->assertSame('PDO::query', $span->getName());
176-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
176+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
177177
$this->assertCount(6, $this->storage);
178178
}
179179

@@ -183,7 +183,7 @@ public function test_transaction(): void
183183
$result = $db->beginTransaction();
184184
$span = $this->storage->offsetGet(1);
185185
$this->assertSame('PDO::beginTransaction', $span->getName());
186-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
186+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
187187
$this->assertCount(2, $this->storage);
188188
$this->assertSame($result, true);
189189

@@ -192,7 +192,7 @@ public function test_transaction(): void
192192
$result = $db->commit();
193193
$span = $this->storage->offsetGet(3);
194194
$this->assertSame('PDO::commit', $span->getName());
195-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
195+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
196196
$this->assertCount(4, $this->storage);
197197
$this->assertTrue($result);
198198

@@ -204,7 +204,7 @@ public function test_transaction(): void
204204
$result = $db->rollback();
205205
$span = $this->storage->offsetGet(6);
206206
$this->assertSame('PDO::rollBack', $span->getName());
207-
$this->assertEquals('sqlite', $span->getAttributes()->get(TraceAttributes::DB_SYSTEM_NAME));
207+
$this->assertEquals('sqlite', $span->getAttributes()->get(DbAttributes::DB_SYSTEM_NAME));
208208
$this->assertCount(7, $this->storage);
209209
$this->assertTrue($result);
210210
$this->assertFalse($db->inTransaction());
@@ -262,17 +262,17 @@ public function test_encode_db_statement_as_utf8(): void
262262

263263
$db->prepare("SELECT id FROM technology WHERE id = '{$non_utf8_id}'");
264264
$span_db_prepare = $this->storage->offsetGet(2);
265-
$this->assertTrue(mb_check_encoding($span_db_prepare->getAttributes()->get(TraceAttributes::DB_QUERY_TEXT), 'UTF-8'));
265+
$this->assertTrue(mb_check_encoding($span_db_prepare->getAttributes()->get(DbAttributes::DB_QUERY_TEXT), 'UTF-8'));
266266
$this->assertCount(3, $this->storage);
267267

268268
$db->query("SELECT id FROM technology WHERE id = '{$non_utf8_id}'");
269269
$span_db_query = $this->storage->offsetGet(3);
270-
$this->assertTrue(mb_check_encoding($span_db_query->getAttributes()->get(TraceAttributes::DB_QUERY_TEXT), 'UTF-8'));
270+
$this->assertTrue(mb_check_encoding($span_db_query->getAttributes()->get(DbAttributes::DB_QUERY_TEXT), 'UTF-8'));
271271
$this->assertCount(4, $this->storage);
272272

273273
$db->exec("SELECT id FROM technology WHERE id = '{$non_utf8_id}'");
274274
$span_db_exec = $this->storage->offsetGet(4);
275-
$this->assertTrue(mb_check_encoding($span_db_exec->getAttributes()->get(TraceAttributes::DB_QUERY_TEXT), 'UTF-8'));
275+
$this->assertTrue(mb_check_encoding($span_db_exec->getAttributes()->get(DbAttributes::DB_QUERY_TEXT), 'UTF-8'));
276276
$this->assertCount(5, $this->storage);
277277
}
278278

@@ -364,35 +364,35 @@ public function test_span_hierarchy_with_pdo_operations(): void
364364
'name' => 'PDO::__construct',
365365
'kind' => SpanKind::KIND_CLIENT,
366366
'attributes' => [
367-
TraceAttributes::DB_SYSTEM_NAME => 'sqlite',
367+
DbAttributes::DB_SYSTEM_NAME => 'sqlite',
368368
],
369369
],
370370
[
371371
'name' => 'PDO::exec',
372372
'kind' => SpanKind::KIND_CLIENT,
373373
'attributes' => [
374-
TraceAttributes::DB_SYSTEM_NAME => 'sqlite',
374+
DbAttributes::DB_SYSTEM_NAME => 'sqlite',
375375
],
376376
],
377377
[
378378
'name' => 'PDO::prepare',
379379
'kind' => SpanKind::KIND_CLIENT,
380380
'attributes' => [
381-
TraceAttributes::DB_SYSTEM_NAME => 'sqlite',
381+
DbAttributes::DB_SYSTEM_NAME => 'sqlite',
382382
],
383383
],
384384
[
385385
'name' => 'PDOStatement::execute',
386386
'kind' => SpanKind::KIND_CLIENT,
387387
'attributes' => [
388-
TraceAttributes::DB_SYSTEM_NAME => 'sqlite',
388+
DbAttributes::DB_SYSTEM_NAME => 'sqlite',
389389
],
390390
],
391391
[
392392
'name' => 'PDOStatement::fetchAll',
393393
'kind' => SpanKind::KIND_CLIENT,
394394
'attributes' => [
395-
TraceAttributes::DB_SYSTEM_NAME => 'sqlite',
395+
DbAttributes::DB_SYSTEM_NAME => 'sqlite',
396396
],
397397
],
398398
],

src/Instrumentation/PDO/tests/Unit/PDOAttributeTrackerTest.php

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

77
use OpenTelemetry\API\Trace\Span;
88
use OpenTelemetry\Contrib\Instrumentation\PDO\PDOTracker;
9-
use OpenTelemetry\SemConv\TraceAttributes;
9+
use OpenTelemetry\SemConv\Attributes\DbAttributes;
1010
use PHPUnit\Framework\TestCase;
1111

1212
class PDOAttributeTrackerTest extends TestCase
@@ -22,20 +22,20 @@ public function testPdoCanBeTracked(): void
2222
$span = Span::getInvalid();
2323

2424
/** @psalm-suppress InvalidArgument */
25-
$this->assertContains(TraceAttributes::DB_SYSTEM_NAME, array_keys($attributes));
25+
$this->assertContains(DbAttributes::DB_SYSTEM_NAME, array_keys($attributes));
2626
/** @psalm-suppress InvalidArgument */
27-
$this->assertContains(TraceAttributes::DB_NAMESPACE, array_keys($attributes));
27+
$this->assertContains(DbAttributes::DB_NAMESPACE, array_keys($attributes));
2828
/** @psalm-suppress InvalidArrayAccess */
29-
$this->assertSame('memory', $attributes[TraceAttributes::DB_NAMESPACE]);
29+
$this->assertSame('memory', $attributes[DbAttributes::DB_NAMESPACE]);
3030

3131
$stmt = $pdo->prepare('SELECT NULL LIMIT 0;');
3232
$objectMap->trackStatement($stmt, $pdo, $span->getContext());
3333
$attributes = $objectMap->trackedAttributesForStatement($stmt);
3434

3535
/** @psalm-suppress InvalidArgument */
36-
$this->assertContains(TraceAttributes::DB_SYSTEM_NAME, array_keys($attributes));
36+
$this->assertContains(DbAttributes::DB_SYSTEM_NAME, array_keys($attributes));
3737
/** @psalm-suppress InvalidArrayAccess */
38-
$this->assertEquals('sqlite', $attributes[TraceAttributes::DB_SYSTEM_NAME]);
38+
$this->assertEquals('sqlite', $attributes[DbAttributes::DB_SYSTEM_NAME]);
3939
$this->assertSame($span->getContext(), $objectMap->getSpanForPreparedStatement($stmt));
4040
}
4141
}

0 commit comments

Comments
 (0)