diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py index 434984ec3..abcbe0d63 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -46,7 +46,6 @@ from opentelemetry.trace import SpanKind, get_tracer from opentelemetry.trace.status import Status, StatusCode DATABASE_TYPE = "mongodb" -COMMAND_ATTRIBUTES = ["filter", "sort", "skip", "limit", "pipeline"] class CommandTracer(monitoring.CommandListener): @@ -60,7 +59,7 @@ class CommandTracer(monitoring.CommandListener): if not self.is_enabled: return command = event.command.get(event.command_name, "") - name = DATABASE_TYPE + "." + event.command_name + name = event.command_name statement = event.command_name if command: name += "." + str(command) @@ -69,23 +68,13 @@ class CommandTracer(monitoring.CommandListener): try: span = self._tracer.start_span(name, kind=SpanKind.CLIENT) if span.is_recording(): - span.set_attribute("component", DATABASE_TYPE) - span.set_attribute("db.type", DATABASE_TYPE) - span.set_attribute("db.instance", event.database_name) + span.set_attribute("db.system", DATABASE_TYPE) + span.set_attribute("db.name", event.database_name) span.set_attribute("db.statement", statement) if event.connection_id is not None: span.set_attribute("net.peer.name", event.connection_id[0]) span.set_attribute("net.peer.port", event.connection_id[1]) - # pymongo specific, not specified by spec - span.set_attribute("db.mongo.operation_id", event.operation_id) - span.set_attribute("db.mongo.request_id", event.request_id) - - for attr in COMMAND_ATTRIBUTES: - _attr = event.command.get(attr) - if _attr is not None: - span.set_attribute("db.mongo." + attr, str(_attr)) - # Add Span to dictionary self._span_dict[_get_span_dict_key(event)] = span except Exception as ex: # noqa pylint: disable=broad-except @@ -101,10 +90,6 @@ class CommandTracer(monitoring.CommandListener): span = self._pop_span(event) if span is None: return - if span.is_recording(): - span.set_attribute( - "db.mongo.duration_micros", event.duration_micros - ) span.end() def failed(self, event: monitoring.CommandFailedEvent): @@ -115,9 +100,6 @@ class CommandTracer(monitoring.CommandListener): if span is None: return if span.is_recording(): - span.set_attribute( - "db.mongo.duration_micros", event.duration_micros - ) span.set_status(Status(StatusCode.ERROR, event.failure)) span.end() diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py index a3bb7b222..bfd3d8f52 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py @@ -39,10 +39,6 @@ class TestPymongo(TestBase): def test_started(self): command_attrs = { - "filter": "filter", - "sort": "sort", - "limit": "limit", - "pipeline": "pipeline", "command_name": "find", } command_tracer = CommandTracer(self.tracer) @@ -55,24 +51,12 @@ class TestPymongo(TestBase): # pylint: disable=protected-access span = command_tracer._pop_span(mock_event) self.assertIs(span.kind, trace_api.SpanKind.CLIENT) - self.assertEqual(span.name, "mongodb.command_name.find") - self.assertEqual(span.attributes["component"], "mongodb") - self.assertEqual(span.attributes["db.type"], "mongodb") - self.assertEqual(span.attributes["db.instance"], "database_name") + self.assertEqual(span.name, "command_name.find") + self.assertEqual(span.attributes["db.system"], "mongodb") + self.assertEqual(span.attributes["db.name"], "database_name") self.assertEqual(span.attributes["db.statement"], "command_name find") self.assertEqual(span.attributes["net.peer.name"], "test.com") self.assertEqual(span.attributes["net.peer.port"], "1234") - self.assertEqual( - span.attributes["db.mongo.operation_id"], "operation_id" - ) - self.assertEqual( - span.attributes["db.mongo.request_id"], "test_request_id" - ) - - self.assertEqual(span.attributes["db.mongo.filter"], "filter") - self.assertEqual(span.attributes["db.mongo.sort"], "sort") - self.assertEqual(span.attributes["db.mongo.limit"], "limit") - self.assertEqual(span.attributes["db.mongo.pipeline"], "pipeline") def test_succeeded(self): mock_event = MockEvent({}) @@ -82,9 +66,6 @@ class TestPymongo(TestBase): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] - self.assertEqual( - span.attributes["db.mongo.duration_micros"], "duration_micros" - ) self.assertIs( span.status.status_code, trace_api.status.StatusCode.UNSET ) @@ -116,9 +97,6 @@ class TestPymongo(TestBase): self.assertEqual(len(spans_list), 1) span = spans_list[0] - self.assertEqual( - span.attributes["db.mongo.duration_micros"], "duration_micros" - ) self.assertIs( span.status.status_code, trace_api.status.StatusCode.ERROR, ) @@ -139,13 +117,9 @@ class TestPymongo(TestBase): first_span = spans_list[0] second_span = spans_list[1] - self.assertEqual(first_span.attributes["db.mongo.request_id"], "first") self.assertIs( first_span.status.status_code, trace_api.status.StatusCode.UNSET, ) - self.assertEqual( - second_span.attributes["db.mongo.request_id"], "second" - ) self.assertIs( second_span.status.status_code, trace_api.status.StatusCode.ERROR, ) @@ -165,7 +139,7 @@ class TestPymongo(TestBase): self.assertEqual(len(spans_list), 1) span = spans_list[0] - self.assertEqual(span.name, "mongodb.command_name.123") + self.assertEqual(span.name, "command_name.123") class MockCommand: diff --git a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py index 577477a2a..149c78905 100644 --- a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py +++ b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py @@ -20,9 +20,9 @@ from opentelemetry import trace as trace_api from opentelemetry.instrumentation.pymongo import PymongoInstrumentor from opentelemetry.test.test_base import TestBase -MONGODB_HOST = os.getenv("MONGODB_HOST ", "localhost") -MONGODB_PORT = int(os.getenv("MONGODB_PORT ", "27017")) -MONGODB_DB_NAME = os.getenv("MONGODB_DB_NAME ", "opentelemetry-tests") +MONGODB_HOST = os.getenv("MONGODB_HOST", "localhost") +MONGODB_PORT = int(os.getenv("MONGODB_PORT", "27017")) +MONGODB_DB_NAME = os.getenv("MONGODB_DB_NAME", "opentelemetry-tests") MONGODB_COLLECTION_NAME = "test" @@ -54,7 +54,7 @@ class TestFunctionalPymongo(TestBase): self.assertIs(pymongo_span.parent, root_span.get_span_context()) self.assertIs(pymongo_span.kind, trace_api.SpanKind.CLIENT) self.assertEqual( - pymongo_span.attributes["db.instance"], MONGODB_DB_NAME + pymongo_span.attributes["db.name"], MONGODB_DB_NAME ) self.assertEqual( pymongo_span.attributes["net.peer.name"], MONGODB_HOST