Merge pull request #102 from NathanielRN/move-instrumentation-elasticsearch

Move instrumentation elasticsearch
This commit is contained in:
alrex 2020-11-02 13:08:47 -08:00 committed by GitHub
commit e45f1d1231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 14 deletions

View File

@ -39,14 +39,14 @@ package_dir=
=src =src
packages=find_namespace: packages=find_namespace:
install_requires = install_requires =
opentelemetry-api == 0.15.dev0 opentelemetry-api == 0.15b0
opentelemetry-instrumentation == 0.15.dev0 opentelemetry-instrumentation == 0.15b0
wrapt >= 1.0.0, < 2.0.0 wrapt >= 1.0.0, < 2.0.0
elasticsearch >= 2.0 elasticsearch >= 2.0
[options.extras_require] [options.extras_require]
test = test =
opentelemetry-test == 0.15.dev0 opentelemetry-test == 0.15b0
elasticsearch-dsl >= 2.0 elasticsearch-dsl >= 2.0
[options.packages.find] [options.packages.find]

View File

@ -64,7 +64,7 @@ from opentelemetry.instrumentation.elasticsearch.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import unwrap from opentelemetry.instrumentation.utils import unwrap
from opentelemetry.trace import SpanKind, get_tracer from opentelemetry.trace import SpanKind, get_tracer
from opentelemetry.trace.status import Status, StatusCanonicalCode from opentelemetry.trace.status import Status, StatusCode
logger = getLogger(__name__) logger = getLogger(__name__)
@ -156,11 +156,7 @@ def _wrap_perform_request(tracer, span_name_prefix):
return rv return rv
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
if span.is_recording(): if span.is_recording():
if isinstance(ex, elasticsearch.exceptions.NotFoundError): span.set_status(Status(StatusCode.ERROR, str(ex)))
status = StatusCanonicalCode.NOT_FOUND
else:
status = StatusCanonicalCode.UNKNOWN
span.set_status(Status(status, str(ex)))
raise ex raise ex
return wrapper return wrapper

View File

@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
__version__ = "0.15.dev0" __version__ = "0.15b0"

View File

@ -27,7 +27,7 @@ from opentelemetry.instrumentation.elasticsearch import (
ElasticsearchInstrumentor, ElasticsearchInstrumentor,
) )
from opentelemetry.test.test_base import TestBase from opentelemetry.test.test_base import TestBase
from opentelemetry.trace.status import StatusCanonicalCode from opentelemetry.trace.status import StatusCode
major_version = elasticsearch.VERSION[0] major_version = elasticsearch.VERSION[0]
@ -153,14 +153,14 @@ class TestElasticsearchIntegration(TestBase):
def test_trace_error_unknown(self, request_mock): def test_trace_error_unknown(self, request_mock):
exc = RuntimeError("custom error") exc = RuntimeError("custom error")
request_mock.side_effect = exc request_mock.side_effect = exc
self._test_trace_error(StatusCanonicalCode.UNKNOWN, exc) self._test_trace_error(StatusCode.ERROR, exc)
def test_trace_error_not_found(self, request_mock): def test_trace_error_not_found(self, request_mock):
msg = "record not found" msg = "record not found"
exc = elasticsearch.exceptions.NotFoundError(404, msg) exc = elasticsearch.exceptions.NotFoundError(404, msg)
request_mock.return_value = (1, {}, {}) request_mock.return_value = (1, {}, {})
request_mock.side_effect = exc request_mock.side_effect = exc
self._test_trace_error(StatusCanonicalCode.NOT_FOUND, exc) self._test_trace_error(StatusCode.ERROR, exc)
def _test_trace_error(self, code, exc): def _test_trace_error(self, code, exc):
es = Elasticsearch() es = Elasticsearch()
@ -173,7 +173,7 @@ class TestElasticsearchIntegration(TestBase):
self.assertEqual(1, len(spans)) self.assertEqual(1, len(spans))
span = spans[0] span = spans[0]
self.assertFalse(span.status.is_ok) self.assertFalse(span.status.is_ok)
self.assertEqual(span.status.canonical_code, code) self.assertEqual(span.status.status_code, code)
self.assertEqual(span.status.description, str(exc)) self.assertEqual(span.status.description, str(exc))
def test_parent(self, request_mock): def test_parent(self, request_mock):