55use DDTrace \Tag ;
66use DDTrace \Tests \Common \IntegrationTestCase ;
77use DDTrace \Tests \Common \SpanAssertion ;
8+ use function DDTrace \close_span ;
9+ use function DDTrace \start_trace_span ;
810
911final class PDOTest extends IntegrationTestCase
1012{
@@ -52,6 +54,7 @@ protected function envsToCleanUpAtTearDown()
5254 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED ' ,
5355 'DD_SERVICE_MAPPING ' ,
5456 'DD_SERVICE ' ,
57+ 'DD_DBM_PROPAGATION_MODE ' ,
5558 ];
5659 }
5760
@@ -682,8 +685,12 @@ public function testPDOStatementExceptionPeerServiceEnabled()
682685
683686 public function testPreparedStatementUsesServiceModeForDBM ()
684687 {
688+ $ this ->putEnvAndReloadConfig (['DD_DBM_PROPAGATION_MODE=full ' ]);
689+
685690 $ query = "SELECT * FROM tests WHERE id = ? " ;
686691 $ traces = $ this ->isolateTracer (function () use ($ query ) {
692+ start_trace_span ();
693+
687694 $ pdo = $ this ->pdoInstance ();
688695 $ stmt = $ pdo ->prepare ($ query );
689696 $ stmt ->execute ([1 ]);
@@ -692,6 +699,8 @@ public function testPreparedStatementUsesServiceModeForDBM()
692699 $ stmt ->closeCursor ();
693700 $ stmt = null ;
694701 $ pdo = null ;
702+
703+ close_span ();
695704 });
696705
697706 // Get the raw spans
@@ -723,6 +732,9 @@ public function testPreparedStatementUsesServiceModeForDBM()
723732 'PDOStatement.execute should be a sibling of PDO.prepare '
724733 );
725734
735+ $ this ->assertEquals ($ query , $ prepareSpan ['resource ' ]);
736+ $ this ->assertEquals ($ query , $ executeSpan ['resource ' ]);
737+
726738 // Verify that SERVICE mode is used for the prepare span
727739 $ this ->assertArrayNotHasKey (
728740 '_dd.dbm_trace_injected ' ,
@@ -758,12 +770,6 @@ public function testDirectQueryHasNoParentIssues()
758770 $ this ->assertNotNull ($ constructSpan , 'PDO.__construct span should exist ' );
759771 $ this ->assertNotNull ($ querySpan , 'PDO.query span should exist ' );
760772
761- // Verify that query span has a parent (should be root or construct)
762- $ this ->assertTrue (
763- isset ($ querySpan ['parent_id ' ]),
764- 'PDO.query should have a parent_id '
765- );
766-
767773 // Verify spans are created correctly with proper structure
768774 $ this ->assertSpans ($ traces , [
769775 SpanAssertion::exists ('PDO.__construct ' ),
@@ -833,7 +839,7 @@ private function ensureActiveQueriesErrorCanHappen()
833839 {
834840 $ opts = array (
835841 \PDO ::ATTR_ERRMODE => \PDO ::ERRMODE_EXCEPTION ,
836- \PDO ::MYSQL_ATTR_USE_BUFFERED_QUERY => false
842+ PHP_VERSION_ID >= 80400 ? \ Pdo \Mysql:: ATTR_USE_BUFFERED_QUERY : \PDO ::MYSQL_ATTR_USE_BUFFERED_QUERY => false
837843 );
838844
839845 $ pdo = $ this ->pdoInstance ($ opts );
0 commit comments