Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Predis integration for clusters #574

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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