Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

OpenCensus - Redis Integration #236

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Functional Version for Predis-PHP with tests
  • Loading branch information
Angelos Roussakis committed Apr 16, 2019
commit 37b2f13d66b5f258d9551db70237692d4b0b74af
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"twig/twig": "~2.0 || ~1.35",
"symfony/yaml": "~3.3",
"guzzlehttp/guzzle": "~5.3",
"predis/predis": "1.1.0",
"guzzlehttp/psr7": "~1.4"
},
"conflict": {
Expand Down
2 changes: 2 additions & 0 deletions src/Trace/Integrations/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static function load()
/**
* Trace Construct Options
*
* @param $predis
* @param $params
* @return array
*/
Expand All @@ -69,6 +70,7 @@ public static function handleConstruct($predis, $params)
/**
* Trace Set / Get Operations
*
* @param $predis
* @param $key
* @return array
*/
Expand Down
1 change: 1 addition & 0 deletions tests/integration/redis/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"require": {
"php": "^7.2",
"opencensus/opencensus": "dev-master",
"predis/predis": "1.1.0",
"ext-opencensus": "*",
"ext-phpredis": "*"
},
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/redis/tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

namespace OpenCensus\Tests\Integration\Trace\Exporter;

use OpenCensus\Trace\Tracer;
use OpenCensus\Trace\Exporter\ExporterInterface;
use OpenCensus\Trace\Integrations\Redis as RedisIntegration;
use PHPUnit\Framework\TestCase;
use Predis\Client;

class RedisTest extends TestCase
{
Expand All @@ -32,4 +35,37 @@ public static function setUpBeforeClass()
self::$redisHost = getenv('REDIS_HOST') ?: '127.0.0.1';
self::$redisPort = (int) (getenv('REDIS_PORT') ?: 6379);
}

public function setUp()
{
if (!extension_loaded('opencensus')) {
$this->markTestSkipped('Please enable the opencensus extension.');
}
opencensus_trace_clear();
$exporter = $this->prophesize(ExporterInterface::class);
$this->tracer = Tracer::start($exporter->reveal(), [
'skipReporting' => true
]);
}

private function getSpans()
{
$this->tracer->onExit();
return $this->tracer->tracer()->spans();
}

public function testAddGet()
{
$client = new Client([
'host' => self::$redisHost,
'port' => self::$redisPort
]);

$client->set('foo', 'bar');
$value = $client->get('foo');
$this->assertEquals('bar', $value);

$spans = $this->getSpans();
$this->assertCount(4, $spans);
}
}