diff --git a/src/Instrumentation/Doctrine/src/DoctrineInstrumentation.php b/src/Instrumentation/Doctrine/src/DoctrineInstrumentation.php index 82f6eb9b9..17b267515 100644 --- a/src/Instrumentation/Doctrine/src/DoctrineInstrumentation.php +++ b/src/Instrumentation/Doctrine/src/DoctrineInstrumentation.php @@ -180,7 +180,7 @@ public static function register(): void Context::storage()->attach($span->storeInContext($parent)); }, - post: static function (\Doctrine\DBAL\Driver\Statement $statement, array $params, ResultInterface $result, ?Throwable $exception) { + post: static function (\Doctrine\DBAL\Driver\Statement $statement, array $params, ?ResultInterface $result, ?Throwable $exception) { self::end($exception); } ); diff --git a/src/Instrumentation/Doctrine/tests/Integration/DoctrineInstrumentationTest.php b/src/Instrumentation/Doctrine/tests/Integration/DoctrineInstrumentationTest.php index b1e37172b..0e5e40b2c 100644 --- a/src/Instrumentation/Doctrine/tests/Integration/DoctrineInstrumentationTest.php +++ b/src/Instrumentation/Doctrine/tests/Integration/DoctrineInstrumentationTest.php @@ -95,7 +95,7 @@ public function test_connection_exception(): void ]); } - public function test_statement_execution(): void + public function test_connection_execute_statement(): void { $connection = self::createConnection(); $statement = self::fillDB(); @@ -202,4 +202,39 @@ public function test_transaction(): void $sth = $connection->prepare('SELECT * FROM `technology`'); $this->assertSame(2, count($sth->executeQuery()->fetchAllAssociative())); } + + public function test_statement_execute(): void + { + $connection = self::createConnection(); + $statement = self::fillDB(); + $connection->executeStatement($statement); + $stmt = $connection->prepare('SELECT * FROM `technology`'); + $this->storage->exchangeArray([]); + $stmt->executeQuery(); + $this->assertCount(1, $this->storage); + $span = $this->storage->offsetGet(0); + $this->assertSame('Doctrine::execute', $span->getName()); + $this->assertSame('execute', $span->getAttributes()->get(TraceAttributes::DB_OPERATION_NAME)); + } + + public function test_statement_execute_error(): void + { + $connection = self::createConnection(); + $statement = self::fillDB(); + $connection->executeStatement($statement); + $stmt = $connection->prepare('insert into technology(name, date) values (?, ?);'); + $this->storage->exchangeArray([]); + $e = null; + + try { + $stmt->executeQuery(); + } catch (\Throwable $e) { + // do nothing + } + $this->assertNotNull($e); + $this->assertCount(1, $this->storage); + $span = $this->storage->offsetGet(0); + $this->assertSame('Error', $span->getStatus()->getCode()); + $this->assertStringContainsString('Unable to execute', $span->getStatus()->getDescription()); + } }