diff --git a/.circleci/config.yml b/.circleci/config.yml index bc3473969..0ee5b37b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,16 +107,6 @@ jobs: docker: - image: circleci/php:7.3-zts-node - php71-32bit: - <<: *unit-config - docker: - - image: gcr.io/php-stackdriver/php71-32bit - environment: - TEST_PHP_ARGS: -q - REPORT_EXIT_STATUS: 1 - RUN_EXTENSION_TESTS: 1 - SUDO_CMD: "" - php71-debug: <<: *unit-config docker: @@ -141,6 +131,10 @@ jobs: environment: POSTGRES_PASSWORD: pgsql POSTGRES_USER: postgres + - image: redis:3.2 + environment: + REDIS_HOST: 127.0.0.1 + REDIS_PORT: 6379 steps: - checkout - run: @@ -175,6 +169,11 @@ jobs: - run: name: Install pdo_mysql extension command: sudo docker-php-ext-install pdo_mysql + - run: + name: Install redis extension + command: | + sudo pecl install redis + sudo docker-php-ext-enable redis - run: name: Install mysqli extension command: sudo docker-php-ext-install mysqli @@ -199,6 +198,9 @@ jobs: - run: name: Memcached test command: tests/integration/memcached/test.sh + - run: + name: Redis test + command: tests/integration/redis/test.sh - run: name: Pgsql test command: tests/integration/pgsql/test.sh @@ -226,6 +228,5 @@ workflows: - php72-zts - php73 - php73-zts - - php71-32bit - php71-debug - integration \ No newline at end of file diff --git a/composer.json b/composer.json index 52c257382..c0b673bc4 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Trace/Integrations/Redis.php b/src/Trace/Integrations/Redis.php new file mode 100644 index 000000000..4e695e6c0 --- /dev/null +++ b/src/Trace/Integrations/Redis.php @@ -0,0 +1,84 @@ + [ + 'host' => $params['host'], + 'port' => $params['port'] + ], + 'kind' => Span::KIND_CLIENT + ]; + } + + /** + * Trace Set / Get Operations + * + * @param $predis + * @param $key + * @return array + */ + public static function handleCall($predis, $key) + { + return [ + 'attributes' => ['key' => $key], + 'kind' => Span::KIND_CLIENT + ]; + } +} diff --git a/tests/integration/redis/composer.json b/tests/integration/redis/composer.json new file mode 100644 index 000000000..b80ad7341 --- /dev/null +++ b/tests/integration/redis/composer.json @@ -0,0 +1,18 @@ +{ + "require": { + "php": "^7.2", + "opencensus/opencensus": "dev-master", + "predis/predis": "1.1.0", + "ext-opencensus": "*", + "ext-redis": "*" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/census-instrumentation/opencensus-php" + } + ] +} diff --git a/tests/integration/redis/phpunit.xml.dist b/tests/integration/redis/phpunit.xml.dist new file mode 100644 index 000000000..a73902918 --- /dev/null +++ b/tests/integration/redis/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + tests + + + + + src + + src/*/V[!a-zA-Z]* + src/*/*/V[!a-zA-Z]* + src/*/*/*/V[!a-zA-Z]* + + + + + + + diff --git a/tests/integration/redis/test.sh b/tests/integration/redis/test.sh new file mode 100755 index 000000000..a7beaf91b --- /dev/null +++ b/tests/integration/redis/test.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Copyright 2018 OpenCensus Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +pushd $(dirname ${BASH_SOURCE[0]}) +source ../setup_test_repo.sh + +sed -i "s|dev-master|dev-${BRANCH}|" composer.json +sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json +composer install -n --prefer-dist + +vendor/bin/phpunit + +popd diff --git a/tests/integration/redis/tests/RedisTest.php b/tests/integration/redis/tests/RedisTest.php new file mode 100644 index 000000000..4e53b49e5 --- /dev/null +++ b/tests/integration/redis/tests/RedisTest.php @@ -0,0 +1,71 @@ +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); + } +}