From 6aee8632912dc155671cce4cc5322d03f932342e Mon Sep 17 00:00:00 2001 From: Adi Kochavi Date: Wed, 1 Feb 2023 13:06:44 +0200 Subject: [PATCH 1/6] Audit and test opentelemetry-instrumentation-elasticsearch NoOpTracerProvider --- .../tests/test_elasticsearch.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 1a2cf30738..50184960db 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -22,6 +22,7 @@ from elasticsearch import Elasticsearch from elasticsearch_dsl import Search +from opentelemetry import trace as trace_api import opentelemetry.instrumentation.elasticsearch from opentelemetry import trace from opentelemetry.instrumentation.elasticsearch import ( @@ -413,3 +414,18 @@ def response_hook(span, response): json.dumps(response_payload), spans[0].attributes[response_attribute_name], ) + + def test_no_op_tracer_provider(self, request_mock): + ElasticsearchInstrumentor().uninstrument() + ElasticsearchInstrumentor().instrument(tracer_provider=trace_api.NoOpTracerProvider()) + + request_mock.return_value = ( + 1, + {}, + '{"found": false, "timed_out": true, "took": 7}', + ) + es = Elasticsearch() + es.get(index="test-index", doc_type="_doc", id=1) + + spans_list = self.get_finished_spans() + self.assertEqual(len(spans_list), 0) From 0a0abe92d940a89d5c80711cb6e8ac4f92a7a797 Mon Sep 17 00:00:00 2001 From: Adi Kochavi Date: Sun, 5 Feb 2023 09:06:48 +0200 Subject: [PATCH 2/6] wip --- .../tests/test_elasticsearch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 2d72d7c44c..8d4c037c97 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -416,7 +416,9 @@ def response_hook(span, response): def test_no_op_tracer_provider(self, request_mock): ElasticsearchInstrumentor().uninstrument() - ElasticsearchInstrumentor().instrument(tracer_provider=trace_api.NoOpTracerProvider()) + ElasticsearchInstrumentor().instrument( + tracer_provider=trace_api.NoOpTracerProvider() + ) request_mock.return_value = ( 1, From 0723c69e5669be96f768bec4ba6c9b51257334b5 Mon Sep 17 00:00:00 2001 From: Adi Kochavi Date: Sun, 5 Feb 2023 10:11:28 +0200 Subject: [PATCH 3/6] wip --- .../tests/test_elasticsearch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 8d4c037c97..30eb47d511 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -22,9 +22,9 @@ from elasticsearch import Elasticsearch from elasticsearch_dsl import Search -from opentelemetry import trace as trace_api import opentelemetry.instrumentation.elasticsearch from opentelemetry import trace +from opentelemetry import trace as trace_api from opentelemetry.instrumentation.elasticsearch import ( ElasticsearchInstrumentor, ) From 37578e9531cfd05512cce16f7ab9fc2259c6bed6 Mon Sep 17 00:00:00 2001 From: Adi Kochavi Date: Sun, 5 Feb 2023 12:25:59 +0200 Subject: [PATCH 4/6] wip --- .../tests/test_elasticsearch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 30eb47d511..0999437060 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -24,7 +24,6 @@ import opentelemetry.instrumentation.elasticsearch from opentelemetry import trace -from opentelemetry import trace as trace_api from opentelemetry.instrumentation.elasticsearch import ( ElasticsearchInstrumentor, ) @@ -417,7 +416,7 @@ def response_hook(span, response): def test_no_op_tracer_provider(self, request_mock): ElasticsearchInstrumentor().uninstrument() ElasticsearchInstrumentor().instrument( - tracer_provider=trace_api.NoOpTracerProvider() + tracer_provider=trace.NoOpTracerProvider() ) request_mock.return_value = ( From c0d98dc8a1d589a93db61e21d2513b874ade137a Mon Sep 17 00:00:00 2001 From: Adi Kochavi Date: Sun, 5 Feb 2023 19:16:13 +0200 Subject: [PATCH 5/6] wip --- .../tests/test_elasticsearch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 0999437060..b9cda47f8f 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -418,14 +418,15 @@ def test_no_op_tracer_provider(self, request_mock): ElasticsearchInstrumentor().instrument( tracer_provider=trace.NoOpTracerProvider() ) - + response_payload = '{"found": false, "timed_out": true, "took": 7}' request_mock.return_value = ( 1, {}, - '{"found": false, "timed_out": true, "took": 7}', + response_payload, ) es = Elasticsearch() - es.get(index="test-index", doc_type="_doc", id=1) + res = es.get(index="test-index", doc_type="_doc", id=1) + self.assertEqual(res.get('found'), json.loads(response_payload).get('found')) spans_list = self.get_finished_spans() self.assertEqual(len(spans_list), 0) From c0e3774c6d4148eb4d700f0e6fe48d080602e0e6 Mon Sep 17 00:00:00 2001 From: Adi Kochavi Date: Mon, 6 Feb 2023 11:03:34 +0200 Subject: [PATCH 6/6] wip --- .../tests/test_elasticsearch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index b9cda47f8f..a12e462e0f 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -426,7 +426,9 @@ def test_no_op_tracer_provider(self, request_mock): ) es = Elasticsearch() res = es.get(index="test-index", doc_type="_doc", id=1) - self.assertEqual(res.get('found'), json.loads(response_payload).get('found')) + self.assertEqual( + res.get("found"), json.loads(response_payload).get("found") + ) spans_list = self.get_finished_spans() self.assertEqual(len(spans_list), 0)