diff --git a/composer.json b/composer.json index 52c2573828c..9d1821eff4d 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "squizlabs/php_codesniffer": "2.*", "twig/twig": "~2.0 || ~1.35", "symfony/yaml": "~3.3", + "ruflin/elastica": "6.0.2", "guzzlehttp/guzzle": "~5.3", "guzzlehttp/psr7": "~1.4" }, diff --git a/src/Trace/Integrations/Elastica.php b/src/Trace/Integrations/Elastica.php new file mode 100644 index 00000000000..d00e4b01a9c --- /dev/null +++ b/src/Trace/Integrations/Elastica.php @@ -0,0 +1,88 @@ + $param) { + $attributes[$key] = $param; + } + + return [ + 'attributes' => $attributes, + 'kind' => Span::KIND_CLIENT, + ]; + } + + /** + * @param $elastica + * @param $path + * @param $method + * @param $data + * @param $query + * + * @return array + */ + public static function handleRequest($elastica, $path, $method, $data, $query) + { + return [ + 'attributes' => [ + 'path' => $path, + 'method' => $method, + 'data' => json_encode($data), + 'query' => json_encode($query), + ], + 'kind' => Span::KIND_CLIENT, + ]; + } +} diff --git a/tests/unit/Trace/Integrations/ElasticaTest.php b/tests/unit/Trace/Integrations/ElasticaTest.php new file mode 100644 index 00000000000..4a5d0e5cfbd --- /dev/null +++ b/tests/unit/Trace/Integrations/ElasticaTest.php @@ -0,0 +1,73 @@ + 'http', + 'host' => 'elastic', + 'port' => '9200', + ]; + + $spanOptions = Elastica::handleConstruct($scope, $config); + $expected = [ + 'attributes' => [ + 'transport' => 'http', + 'host' => 'elastic', + 'port' => '9200', + ], + 'kind' => Span::KIND_CLIENT + ]; + + $this->assertEquals($expected, $spanOptions); + } + + public function testHandleRequest() + { + $scope = null; + $path = '/test/path'; + $method = 'GET'; + $data = []; + $query = []; + + $spanOptions = Elastica::handleRequest($scope, $path, $method, $data, $query); + $expected = [ + 'attributes' => [ + 'path' => $path, + 'method' => $method, + 'data' => json_encode($data), + 'query' => json_encode($query), + ], + 'kind' => Span::KIND_CLIENT + ]; + + $this->assertEquals($expected, $spanOptions); + } +} \ No newline at end of file