Skip to content

Commit

Permalink
Fix Predis integration for clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoulMeyer committed Sep 14, 2019
1 parent a315d73 commit d6002bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/DDTrace/Integrations/Predis/PredisIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DDTrace\Type;
use DDTrace\GlobalTracer;
use Predis\Configuration\OptionsInterface;
use Predis\Connection\AbstractConnection;
use Predis\Pipeline\Pipeline;

const VALUE_PLACEHOLDER = "?";
Expand Down Expand Up @@ -221,12 +222,13 @@ public static function storeConnectionParams($predis, $args)
{
$tags = [];

try {
$identifier = (string)$predis->getConnection();
list($host, $port) = explode(':', $identifier);
$tags[Tag::TARGET_HOST] = $host;
$tags[Tag::TARGET_PORT] = $port;
} catch (\Exception $e) {
$connection = $predis->getConnection();

if ($connection instanceof AbstractConnection) {
$connectionParameters = $connection->getParameters();

$tags[Tag::TARGET_HOST] = $connectionParameters->host;
$tags[Tag::TARGET_PORT] = $connectionParameters->port;
}

if (isset($args[1])) {
Expand Down
16 changes: 16 additions & 0 deletions tests/Integrations/Predis/PredisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ public function testPredisConnect()
]);
}

public function testPredisClusterConnect()
{
$connectionString = "tcp://{$this->host}";

$traces = $this->isolateTracer(function () use ($connectionString) {
$client = new \Predis\Client([ $connectionString, $connectionString, $connectionString ]);
$client->connect();
});

$this->assertSpans($traces, [
SpanAssertion::exists('Predis.Client.__construct'),
SpanAssertion::build('Predis.Client.connect', 'redis', 'cache', 'Predis.Client.connect')
->withExactTags([]),
]);
}

public function testPredisSetCommand()
{
$traces = $this->isolateTracer(function () {
Expand Down

0 comments on commit d6002bb

Please sign in to comment.