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

Audit and test opentelemetry-instrumentation-elasticsearch NoOpTracer… #1616

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import opentelemetry.instrumentation.elasticsearch
from opentelemetry import trace
from opentelemetry import trace as trace_api
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace already imported in the upper line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

from opentelemetry.instrumentation.elasticsearch import (
ElasticsearchInstrumentor,
)
Expand Down Expand Up @@ -412,3 +413,20 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest validating es.get response value -> so we'll know for sure that no spans were created due to NoOpTracerProvider


spans_list = self.get_finished_spans()
self.assertEqual(len(spans_list), 0)