diff --git a/src/DDTrace/Integrations/Mysqli/MysqliIntegration.php b/src/DDTrace/Integrations/Mysqli/MysqliIntegration.php index e1b374e725..136cc0ff72 100644 --- a/src/DDTrace/Integrations/Mysqli/MysqliIntegration.php +++ b/src/DDTrace/Integrations/Mysqli/MysqliIntegration.php @@ -127,6 +127,24 @@ function (SpanData $span, $args) use ($integration) { } }); + \DDTrace\install_hook('mysqli_real_query', function (HookData $hook) use ($integration) { + list($mysqli, $query) = $hook->args; + + $span = $hook->span(); + $span->peerServiceSources = DatabaseIntegrationHelper::PEER_SERVICE_SOURCES; + $integration->setDefaultAttributes($span, 'mysqli_real_query', $query); + $integration->addTraceAnalyticsIfEnabled($span); + $integration->setConnectionInfo($span, $mysqli); + + DatabaseIntegrationHelper::injectDatabaseIntegrationData($hook, 'mysql', 1); + }, function (HookData $hook) use ($integration) { + list($mysqli, $query) = $hook->args; + $span = $hook->span(); + $integration->setConnectionInfo($span, $mysqli); + + MysqliCommon::storeQuery($mysqli, $query); + }); + \DDTrace\install_hook('mysqli_prepare', function (HookData $hook) use ($integration) { list(, $query) = $hook->args; @@ -174,6 +192,24 @@ function (SpanData $span, $args) use ($integration) { } }); + \DDTrace\install_hook('mysqli::real_query', function (HookData $hook) use ($integration) { + list($query) = $hook->args; + + $span = $hook->span(); + $span->peerServiceSources = DatabaseIntegrationHelper::PEER_SERVICE_SOURCES; + $integration->setDefaultAttributes($span, 'mysqli.real_query', $query); + $integration->addTraceAnalyticsIfEnabled($span); + $integration->setConnectionInfo($span, $this); + + DatabaseIntegrationHelper::injectDatabaseIntegrationData($hook, 'mysql'); + }, function (HookData $hook) use ($integration) { + list($query) = $hook->args; + $span = $hook->span(); + $integration->setConnectionInfo($span, $this); + + MysqliCommon::storeQuery($this, $query); + }); + \DDTrace\install_hook('mysqli::prepare', function (HookData $hook) use ($integration) { list($query) = $hook->args; diff --git a/tests/Integrations/Mysqli/MysqliTest.php b/tests/Integrations/Mysqli/MysqliTest.php index 62be833d17..7ad1d97bd4 100644 --- a/tests/Integrations/Mysqli/MysqliTest.php +++ b/tests/Integrations/Mysqli/MysqliTest.php @@ -126,6 +126,25 @@ public function testProceduralQuery() ]); } + public function testProceduralRealQuery() + { + $traces = $this->isolateTracer(function () { + $mysqli = \mysqli_connect(self::$host, self::$user, self::$password, self::$database); + \mysqli_real_query($mysqli, 'SELECT * from tests'); + $mysqli->close(); + }); + + $this->assertFlameGraph($traces, [ + SpanAssertion::exists('mysqli_connect', 'mysqli_connect'), + SpanAssertion::build('mysqli_real_query', 'mysqli', 'sql', 'SELECT * from tests') + ->withExactTags(self::baseTags(true, false)) + ->withExactMetrics([ + '_dd.agent_psr' => 1.0, + '_sampling_priority_v1' => 1.0, + ]), + ]); + } + public function testProceduralQueryPeerServiceEnabled() { $this->putEnvAndReloadConfig(['DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED=true']); @@ -253,6 +272,25 @@ public function testConstructorQuery() ]); } + public function testConstructorRealQuery() + { + $traces = $this->isolateTracer(function () { + $mysqli = new \mysqli(self::$host, self::$user, self::$password, self::$database); + $mysqli->real_query('SELECT * from tests'); + $mysqli->close(); + }); + + $this->assertFlameGraph($traces, [ + SpanAssertion::exists('mysqli.__construct', 'mysqli.__construct'), + SpanAssertion::build('mysqli.real_query', 'mysqli', 'sql', 'SELECT * from tests') + ->withExactTags(self::baseTags()) + ->withExactMetrics([ + '_dd.agent_psr' => 1.0, + '_sampling_priority_v1' => 1.0, + ]), + ]); + } + public function testConstructorQueryPeerServiceEnabled() { $this->putEnvAndReloadConfig(['DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED=true']);