From 4d94febea0b65965e5e73ed7e76e4f8c3fa4e61d Mon Sep 17 00:00:00 2001 From: amitsetty Date: Sat, 27 Aug 2022 13:03:37 +0300 Subject: [PATCH 1/5] Get rid of pymongo command in pymongo instrumentation span name --- .../src/opentelemetry/instrumentation/pymongo/__init__.py | 1 - 1 file changed, 1 deletion(-) 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 ba3afae11f..3ccdc8f7b4 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -124,7 +124,6 @@ def started(self, event: monitoring.CommandStartedEvent): name = event.command_name statement = event.command_name if command: - name += "." + str(command) statement += " " + str(command) try: From 82e7775bd75bb778c63ee7313eeb12bc4ea9bacd Mon Sep 17 00:00:00 2001 From: amitsetty Date: Sat, 27 Aug 2022 13:09:12 +0300 Subject: [PATCH 2/5] Add database name to span name --- .../src/opentelemetry/instrumentation/pymongo/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3ccdc8f7b4..109a9b0bd6 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -121,7 +121,7 @@ def started(self, event: monitoring.CommandStartedEvent): ): return command = event.command.get(event.command_name, "") - name = event.command_name + name = f"{event.database_name}.{event.command_name}" if event.database_name else event.command_name statement = event.command_name if command: statement += " " + str(command) From a20357250f99df87840a70a3c522e10e2c3676da Mon Sep 17 00:00:00 2001 From: amitsetty Date: Sat, 27 Aug 2022 13:26:06 +0300 Subject: [PATCH 3/5] Change syntax to match style of rest of code --- .../src/opentelemetry/instrumentation/pymongo/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 109a9b0bd6..151f0dde5b 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -121,7 +121,8 @@ def started(self, event: monitoring.CommandStartedEvent): ): return command = event.command.get(event.command_name, "") - name = f"{event.database_name}.{event.command_name}" if event.database_name else event.command_name + name = event.database_name + name += "." + event.command_name statement = event.command_name if command: statement += " " + str(command) From 1f2a538f985dd1c75ad7d3feab6fad867ae749c6 Mon Sep 17 00:00:00 2001 From: amitsetty Date: Sat, 27 Aug 2022 13:43:23 +0300 Subject: [PATCH 4/5] Change changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ebb67d73..595da827bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `opentelemetry-instrumentation-boto3sqs` Make propagation compatible with other SQS instrumentations, add 'messaging.url' span attribute, and fix missing package dependencies. - ([#1234](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1234)) + ([#1234](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1234)) +- `opentelemetry-instrumentation-pymongo` Change span names to not contain queries but only database name and command name + ([#1247](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1247)) - restoring metrics in django framework ([#1208](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1208)) - `opentelemetry-instrumentation-aiohttp-client` Fix producing additional spans with each newly created ClientSession From a3d4d4f2e6743f7fba90147d8cc7a37ecbcdfd83 Mon Sep 17 00:00:00 2001 From: amitsetty Date: Fri, 2 Sep 2022 08:32:49 +0300 Subject: [PATCH 5/5] Fix tests --- .../src/opentelemetry/instrumentation/pymongo/__init__.py | 2 +- .../tests/test_pymongo.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) 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 151f0dde5b..91cd81aab3 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -122,7 +122,7 @@ def started(self, event: monitoring.CommandStartedEvent): return command = event.command.get(event.command_name, "") name = event.database_name - name += "." + event.command_name + name += "." + event.command_name statement = event.command_name if command: statement += " " + str(command) diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py index ef3734c596..15a5a0be0b 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py @@ -40,7 +40,6 @@ def test_pymongo_instrumentor(self): ) with patch: PymongoInstrumentor().instrument() - self.assertTrue(mock_register.called) def test_started(self): @@ -59,7 +58,7 @@ def test_started(self): # pylint: disable=protected-access span = command_tracer._pop_span(mock_event) self.assertIs(span.kind, trace_api.SpanKind.CLIENT) - self.assertEqual(span.name, "command_name.find") + self.assertEqual(span.name, "database_name.command_name") self.assertEqual(span.attributes[SpanAttributes.DB_SYSTEM], "mongodb") self.assertEqual( span.attributes[SpanAttributes.DB_NAME], "database_name" @@ -189,8 +188,7 @@ def test_int_command(self): self.assertEqual(len(spans_list), 1) span = spans_list[0] - - self.assertEqual(span.name, "command_name.123") + self.assertEqual(span.name, "database_name.command_name") class MockCommand: