diff --git a/src/DDTrace/Integrations/Predis/PredisIntegration.php b/src/DDTrace/Integrations/Predis/PredisIntegration.php index acf0aa94f8..d692ff23e6 100644 --- a/src/DDTrace/Integrations/Predis/PredisIntegration.php +++ b/src/DDTrace/Integrations/Predis/PredisIntegration.php @@ -130,7 +130,6 @@ public static function storeConnectionMetaAndService($predis, $args) { $tags = []; $connection = $predis->getConnection(); - $service = PredisIntegration::DEFAULT_SERVICE_NAME; if ($connection instanceof NodeConnectionInterface) { $connectionParameters = $connection->getParameters(); @@ -144,6 +143,7 @@ public static function storeConnectionMetaAndService($predis, $args) ? $connectionParameters->path : $connectionParameters->host) ); + ObjectKVStore::put($predis->getConnection(), 'service', $service); } } @@ -161,7 +161,6 @@ public static function storeConnectionMetaAndService($predis, $args) } } - ObjectKVStore::put($predis->getConnection(), 'service', $service); ObjectKVStore::put($predis->getConnection(), 'connection_meta', $tags); } @@ -175,7 +174,12 @@ public static function storeConnectionMetaAndService($predis, $args) */ public static function setMetaAndServiceFromConnection($predis, SpanData $span) { - $span->service = ObjectKVStore::get($predis->getConnection(), 'service', PredisIntegration::DEFAULT_SERVICE_NAME); + $service = ObjectKVStore::get($predis->getConnection(), 'service'); + if ($service) { + $span->meta[Tag::SERVICE_NAME] = $service; + } else { + Integration::handleInternalSpanServiceName($span, PredisIntegration::DEFAULT_SERVICE_NAME); + } $span->meta[Tag::SPAN_KIND] = 'client'; $span->meta[Tag::COMPONENT] = PredisIntegration::NAME; $span->meta[Tag::DB_SYSTEM] = PredisIntegration::SYSTEM; diff --git a/tests/Integrations/Predis/Latest/PredisTest.php b/tests/Integrations/Predis/Latest/PredisTest.php index d6349dd6b3..3c96a35af9 100644 --- a/tests/Integrations/Predis/Latest/PredisTest.php +++ b/tests/Integrations/Predis/Latest/PredisTest.php @@ -21,13 +21,21 @@ public static function ddSetUpBeforeClass() protected function ddSetUp() { - $this->putEnvAndReloadConfig(['DD_TRACE_REDIS_CLIENT_SPLIT_BY_HOST']); + $this->putEnvAndReloadConfig([ + 'DD_TRACE_REDIS_CLIENT_SPLIT_BY_HOST', + 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED', + 'DD_SERVICE', + ]); parent::ddSetUp(); } protected function ddTearDown() { - $this->putEnvAndReloadConfig(['DD_TRACE_REDIS_CLIENT_SPLIT_BY_HOST']); + $this->putEnvAndReloadConfig([ + 'DD_TRACE_REDIS_CLIENT_SPLIT_BY_HOST', + 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED', + 'DD_SERVICE', + ]); parent::ddTearDown(); } @@ -357,6 +365,25 @@ public function testOrphansRemoval64bit() $this->assertEquals(0, $span['metrics']['_sampling_priority_v1']); } + public function testNoFakeServices() + { + $this->putEnvAndReloadConfig([ + 'DD_SERVICE=configured_service', + 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=true', + ]); + + $traces = $this->isolateTracer(function () { + $client = new \Predis\Client(["host" => $this->host]); + $client->connect(); + }); + + $this->assertFlameGraph($traces, [ + SpanAssertion::exists('Predis.Client.__construct'), + SpanAssertion::build('Predis.Client.connect', 'configured_service', 'redis', 'Predis.Client.connect') + ->withExactTags($this->baseTags()), + ]); + } + private function baseTags() { return [