From 92782daf0d857ec0a9a1de66eba86a904ef4f695 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:17:59 +0530 Subject: [PATCH 01/29] Added enable commenter --- .../instrumentation/mysql/__init__.py | 45 +++++++++++++++++++ .../tests/test_mysql_integration.py | 23 ++++++++++ 2 files changed, 68 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index d88dffde2b..7d19808ce0 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -18,6 +18,47 @@ .. _mysql-connector: https://pypi.org/project/mysql-connector/ +SQLCOMMENTER +***************************************** +You can optionally configure Psycopg2 instrumentation to enable sqlcommenter which enriches +the query with contextual information. +Usage +----- +.. code:: python + from opentelemetry.instrumentation.mysql import MySQLInstrumentor() + MySQLInstrumentor().instrument(enable_commenter=True, commenter_options={}) +For example, +:: + Invoking cursor.execute("select * from auth_users") will lead to sql query "select * from auth_users" but when SQLCommenter is enabled + the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;" +SQLCommenter Configurations +*************************** +We can configure the tags to be appended to the sqlquery log by adding configuration inside commenter_options(default:{}) keyword +db_driver = True(Default) or False +For example, +:: +Enabling this flag will add mysql and its version. +dbapi_threadsafety = True(Default) or False +For example, +:: +Enabling this flag will add threadsafety /*dbapi_threadsafety=2*/ +dbapi_level = True(Default) or False +For example, +:: +Enabling this flag will add dbapi_level /*dbapi_level='2.0'*/ +libpq_version = True(Default) or False +For example, +:: +Enabling this flag will add libpq_version /*libpq_version=140001*/ +driver_paramstyle = True(Default) or False +For example, +:: +Enabling this flag will add driver_paramstyle /*driver_paramstyle='pyformat'*/ +opentelemetry_values = True(Default) or False +For example, +:: +Enabling this flag will add traceparent values /*traceparent='00-03afa25236b8cd948fa853d67038ac79-405ff022e8247c46-01'*/ + Usage ----- @@ -66,6 +107,8 @@ def _instrument(self, **kwargs): https://dev.mysql.com/doc/connector-python/en/ """ tracer_provider = kwargs.get("tracer_provider") + enable_sqlcommenter = kwargs.get("enable_commenter", False) + commenter_options = kwargs.get("commenter_options", {}) dbapi.wrap_connect( __name__, @@ -75,6 +118,8 @@ def _instrument(self, **kwargs): self._CONNECTION_ATTRIBUTES, version=__version__, tracer_provider=tracer_provider, + enable_commenter=enable_sqlcommenter, + commenter_options=commenter_options, ) def _uninstrument(self, **kwargs): diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 3614febffd..4346ccd013 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -117,3 +117,26 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) + @patch("mysql.connector.connect", new=mock_connect) + @patch("opentelemetry.instrumentation.dbapi.wrap_connect") + # pylint: disable=unused-argument + def test_sqlcommenter_enabled(self, event_mocked): + cnx = mysql.connector.connect(database="test") + MySQLInstrumentor().instrument(enable_commenter=True) + query = "SELECT * FROM test" + cursor = cnx.cursor() + cursor.execute(query) + kwargs = event_mocked.call_args[1] + self.assertEqual(kwargs["enable_commenter"], True) + + @patch("mysql.connector.connect", new=mock_connect) + @patch("opentelemetry.instrumentation.dbapi.wrap_connect") + # pylint: disable=unused-argument + def test_sqlcommenter_disabled(self, event_mocked): + cnx = mysql.connector.connect(database="test") + MySQLInstrumentor().instrument(enable_commenter=False) + query = "SELECT * FROM test" + cursor = cnx.cursor() + cursor.execute(query) + kwargs = event_mocked.call_args[1] + self.assertEqual(kwargs["enable_commenter"], False) \ No newline at end of file From a9aad624af1ee5a913e4e7b5a5f62b809929ac6c Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:23:26 +0530 Subject: [PATCH 02/29] CHANGELOG.MD updated. --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee92bdab7a..27688e348f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1298,3 +1298,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-ext-wsgi` Initial release - `opentelemetry-ext-http-requests` Initial release + +### Added + +- 'Added Enable_commenter for mysql + ([[#1387](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1387)]) From 36d0c723cb39c0468a4188c9be6e990739e13585 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 11:18:49 +0530 Subject: [PATCH 03/29] lint issue. --- .../tests/test_mysql_integration.py | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 4346ccd013..e18e8238a1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -117,6 +117,7 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) + @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument From 4d4a7d3ed4d90a28f66e38c252d7a4e4342111a6 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 12:28:54 +0530 Subject: [PATCH 04/29] --- .../tests/test_mysql_integration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index e18e8238a1..59b6febff1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -140,4 +140,5 @@ def test_sqlcommenter_disabled(self, event_mocked): cursor = cnx.cursor() cursor.execute(query) kwargs = event_mocked.call_args[1] - self.assertEqual(kwargs["enable_commenter"], False) \ No newline at end of file + self.assertEqual(kwargs["enable_commenter"], False) + \ No newline at end of file From 3c86278ace003100d2088c1d495549b99188db44 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 13:10:57 +0530 Subject: [PATCH 05/29] --- .../tests/test_mysql_integration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 59b6febff1..a14aef96c1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -140,5 +140,4 @@ def test_sqlcommenter_disabled(self, event_mocked): cursor = cnx.cursor() cursor.execute(query) kwargs = event_mocked.call_args[1] - self.assertEqual(kwargs["enable_commenter"], False) - \ No newline at end of file + self.assertEqual(kwargs["enable_commenter"], False) \ No newline at end of file From e0f4556650a6476134d529f6fc01a3e4b58c73bb Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 13:32:46 +0530 Subject: [PATCH 06/29] Remove new line --- .../tests/test_mysql_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index a14aef96c1..e18e8238a1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -140,4 +140,4 @@ def test_sqlcommenter_disabled(self, event_mocked): cursor = cnx.cursor() cursor.execute(query) kwargs = event_mocked.call_args[1] - self.assertEqual(kwargs["enable_commenter"], False) \ No newline at end of file + self.assertEqual(kwargs["enable_commenter"], False) \ No newline at end of file From 927f2c03b33c9cc816795826abb873fb2062f841 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 14:59:46 +0530 Subject: [PATCH 07/29] Lint issue --- .../tests/test_mysql_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index e18e8238a1..cb36b8b737 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -117,7 +117,7 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - + @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument From 9dec864788c65748e1b215cc0bf35ce4b0ef2fda Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 15:05:08 +0530 Subject: [PATCH 08/29] Lint --- .../tests/test_mysql_integration.py | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index cb36b8b737..3e278e67c1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -140,4 +140,5 @@ def test_sqlcommenter_disabled(self, event_mocked): cursor = cnx.cursor() cursor.execute(query) kwargs = event_mocked.call_args[1] + self.assertEqual(kwargs["enable_commenter"], False) \ No newline at end of file From 3af0bbc3696cf7570e05787136fd9ce64badc0cd Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 15:21:00 +0530 Subject: [PATCH 09/29] Update test_mysql_integration.py Lint issue. --- .../tests/test_mysql_integration.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 3e278e67c1..2d614dd89d 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -116,8 +116,8 @@ def test_uninstrument_connection(self, mock_connect): cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans_list), 1) - + self.assertEqual(len(spans_list), 1 + @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument @@ -140,5 +140,4 @@ def test_sqlcommenter_disabled(self, event_mocked): cursor = cnx.cursor() cursor.execute(query) kwargs = event_mocked.call_args[1] - - self.assertEqual(kwargs["enable_commenter"], False) \ No newline at end of file + self.assertEqual(kwargs["enable_commenter"], False) From 1e642a48942fdb1e1db2faac1dd87aa7389c740a Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 15:50:24 +0530 Subject: [PATCH 10/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 2d614dd89d..505a66ab3e 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -116,7 +116,7 @@ def test_uninstrument_connection(self, mock_connect): cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans_list), 1 + self.assertEqual(len(spans_list), 1) @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") From 3b905e2ed7ba72469ef84447b7b2ab467cf2ddfd Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 18:22:25 +0530 Subject: [PATCH 11/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 505a66ab3e..03ff5b09dd 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -117,7 +117,7 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - + @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument From 876b04a8ba4d38042360462353d620889d1ae9b7 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 19:22:33 +0530 Subject: [PATCH 12/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 03ff5b09dd..a231854595 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -116,8 +116,7 @@ def test_uninstrument_connection(self, mock_connect): cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans_list), 1) - + self.assertEqual(len(spans_list), 1) @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument From 06501e091e4266b7e3fa5e9309222fd257e66de5 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 12 Jun 2023 19:41:03 +0530 Subject: [PATCH 13/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index a231854595..2c340c25ea 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -116,7 +116,8 @@ def test_uninstrument_connection(self, mock_connect): cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans_list), 1) + self.assertEqual(len(spans_list), 1) + @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument From e4c96b231012408ace657153c1404b66a0a3ad89 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:02:24 +0530 Subject: [PATCH 14/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 2c340c25ea..03ff5b09dd 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -117,7 +117,7 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - + @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument From 0ee14d2d7b73b07804bee97a5646ed41177c7b0f Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:16:26 +0530 Subject: [PATCH 15/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 03ff5b09dd..f19d63e2cc 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -117,7 +117,7 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - + @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument From fdcf003b4ad56231d3f6fdb6fb51fcf0636565a7 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Wed, 14 Jun 2023 13:22:11 +0530 Subject: [PATCH 16/29] updating changelog.md --- CHANGELOG.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27688e348f..26320c64a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- 'Added Enable_commenter for mysql +([#1387](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1387)) + ## Version 1.18.0/0.39b0 (2023-05-10) - `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735)) @@ -1298,8 +1301,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-ext-wsgi` Initial release - `opentelemetry-ext-http-requests` Initial release - -### Added - -- 'Added Enable_commenter for mysql - ([[#1387](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1387)]) From 557bf73f972eda80868ba89aac2becefa066afb6 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Wed, 14 Jun 2023 17:33:32 +0530 Subject: [PATCH 17/29] Update test_mysql_integration.py From 1fef9650f328426c7fc055897208913a9fe6fee6 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Wed, 14 Jun 2023 18:03:10 +0530 Subject: [PATCH 18/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index f19d63e2cc..3acd8b2708 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -118,7 +118,6 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument def test_sqlcommenter_enabled(self, event_mocked): @@ -130,7 +129,6 @@ def test_sqlcommenter_enabled(self, event_mocked): kwargs = event_mocked.call_args[1] self.assertEqual(kwargs["enable_commenter"], True) - @patch("mysql.connector.connect", new=mock_connect) @patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument def test_sqlcommenter_disabled(self, event_mocked): From da270754d7776febde3ebb34f4a9e2cd64f70603 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Wed, 14 Jun 2023 18:33:11 +0530 Subject: [PATCH 19/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 3acd8b2708..d24f1d7dd7 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -118,7 +118,8 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - @patch("opentelemetry.instrumentation.dbapi.wrap_connect") + @mock.patch("mysql.connector.connect", new=mock_connect) + @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument def test_sqlcommenter_enabled(self, event_mocked): cnx = mysql.connector.connect(database="test") @@ -129,7 +130,8 @@ def test_sqlcommenter_enabled(self, event_mocked): kwargs = event_mocked.call_args[1] self.assertEqual(kwargs["enable_commenter"], True) - @patch("opentelemetry.instrumentation.dbapi.wrap_connect") + @mock.patch("mysql.connector.connect", new=mock_connect) + @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument def test_sqlcommenter_disabled(self, event_mocked): cnx = mysql.connector.connect(database="test") From b00d1b5ced6a27813453a0341f221db47b0a49cd Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Wed, 14 Jun 2023 18:52:24 +0530 Subject: [PATCH 20/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index d24f1d7dd7..0e0787092b 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -118,7 +118,6 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - @mock.patch("mysql.connector.connect", new=mock_connect) @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument def test_sqlcommenter_enabled(self, event_mocked): @@ -130,7 +129,6 @@ def test_sqlcommenter_enabled(self, event_mocked): kwargs = event_mocked.call_args[1] self.assertEqual(kwargs["enable_commenter"], True) - @mock.patch("mysql.connector.connect", new=mock_connect) @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") # pylint: disable=unused-argument def test_sqlcommenter_disabled(self, event_mocked): From 53508eca902989dd50a14f6ada26d32a62fb7e64 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:07:14 +0530 Subject: [PATCH 21/29] Update CHANGELOG.md Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e07bb1e05..c5cb3b0ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - 'Added Enable_commenter for mysql -([#1387](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1387)) +([#1834](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1834)) - Fix falcon instrumentation's usage of Span Status to only set the description if the status code is ERROR. ([#1840](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1840)) - Instrument all httpx versions >= 0.18. ([#1748](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1748)) From e94831a9d12c41572ccce8828e9ca18aa1ef8056 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:09:58 +0530 Subject: [PATCH 22/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 0e0787092b..1f061e1dbc 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -118,7 +118,7 @@ def test_uninstrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") + @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_sqlcommenter_enabled(self, event_mocked): cnx = mysql.connector.connect(database="test") @@ -129,7 +129,7 @@ def test_sqlcommenter_enabled(self, event_mocked): kwargs = event_mocked.call_args[1] self.assertEqual(kwargs["enable_commenter"], True) - @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") + @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_sqlcommenter_disabled(self, event_mocked): cnx = mysql.connector.connect(database="test") From a3b235eec3bae6bb1a7dce201556557ca8d35ec4 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:15:28 +0530 Subject: [PATCH 23/29] Update __init__.py --- .../src/opentelemetry/instrumentation/mysql/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index 7d19808ce0..7e38264426 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -18,7 +18,7 @@ .. _mysql-connector: https://pypi.org/project/mysql-connector/ -SQLCOMMENTER +MYSQLCOMMENTER ***************************************** You can optionally configure Psycopg2 instrumentation to enable sqlcommenter which enriches the query with contextual information. @@ -31,7 +31,7 @@ :: Invoking cursor.execute("select * from auth_users") will lead to sql query "select * from auth_users" but when SQLCommenter is enabled the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;" -SQLCommenter Configurations +MYSQLCommenter Configurations *************************** We can configure the tags to be appended to the sqlquery log by adding configuration inside commenter_options(default:{}) keyword db_driver = True(Default) or False From fdfd96154d60af8ab153a4c9bb484989aba5d0f1 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:17:35 +0530 Subject: [PATCH 24/29] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5cb3b0ebd..d514c3f9d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -- 'Added Enable_commenter for mysql +- Added Enable_commenter for mysql ([#1834](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1834)) - Fix falcon instrumentation's usage of Span Status to only set the description if the status code is ERROR. ([#1840](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1840)) From 905db61a6dff2de02eb5d1705f13114713c5c24f Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:03:49 +0530 Subject: [PATCH 25/29] Update __init__.py --- .../src/opentelemetry/instrumentation/mysql/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index 7e38264426..ad5af2c158 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -20,7 +20,7 @@ MYSQLCOMMENTER ***************************************** -You can optionally configure Psycopg2 instrumentation to enable sqlcommenter which enriches +You can optionally configure Psycopg2 instrumentation to enable mysqlcommenter which enriches the query with contextual information. Usage ----- From 7c153772b1a46c466a4500f1ad22262bbbf8809b Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:14:50 +0530 Subject: [PATCH 26/29] Update instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com> --- .../src/opentelemetry/instrumentation/mysql/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index ad5af2c158..10db5f42df 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -20,7 +20,7 @@ MYSQLCOMMENTER ***************************************** -You can optionally configure Psycopg2 instrumentation to enable mysqlcommenter which enriches +You can optionally configure MySQL instrumentation to enable sqlcommenter which enriches the query with contextual information. Usage ----- From 8c31902521d6803abef8f4e2d93bc92bb69b563c Mon Sep 17 00:00:00 2001 From: Shalev Roda <65566801+shalevr@users.noreply.github.com> Date: Mon, 19 Jun 2023 13:48:04 +0300 Subject: [PATCH 27/29] Update __init__.py --- .../src/opentelemetry/instrumentation/mysql/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index 10db5f42df..a2f0440c7f 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -18,7 +18,7 @@ .. _mysql-connector: https://pypi.org/project/mysql-connector/ -MYSQLCOMMENTER +SQLCOMMENTER ***************************************** You can optionally configure MySQL instrumentation to enable sqlcommenter which enriches the query with contextual information. @@ -31,7 +31,7 @@ :: Invoking cursor.execute("select * from auth_users") will lead to sql query "select * from auth_users" but when SQLCommenter is enabled the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;" -MYSQLCommenter Configurations +SQLCOMMENTER Configurations *************************** We can configure the tags to be appended to the sqlquery log by adding configuration inside commenter_options(default:{}) keyword db_driver = True(Default) or False From 5773c0c10507454e00d22b0919d332d3338dece4 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 3 Jul 2023 12:26:52 +0530 Subject: [PATCH 28/29] Update test_mysql_integration.py --- .../tests/test_mysql_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index 1f061e1dbc..e3f47b8c9a 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -121,8 +121,8 @@ def test_uninstrument_connection(self, mock_connect): @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_sqlcommenter_enabled(self, event_mocked): - cnx = mysql.connector.connect(database="test") MySQLInstrumentor().instrument(enable_commenter=True) + cnx = mysql.connector.connect(database="test") query = "SELECT * FROM test" cursor = cnx.cursor() cursor.execute(query) @@ -132,8 +132,8 @@ def test_sqlcommenter_enabled(self, event_mocked): @mock.patch("mysql.connector.connect") # pylint: disable=unused-argument def test_sqlcommenter_disabled(self, event_mocked): - cnx = mysql.connector.connect(database="test") MySQLInstrumentor().instrument(enable_commenter=False) + cnx = mysql.connector.connect(database="test") query = "SELECT * FROM test" cursor = cnx.cursor() cursor.execute(query) From f448d8ad9fa48b548321db8aacb3ac99f296f0f6 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 30 Aug 2023 17:39:54 +0200 Subject: [PATCH 29/29] Fix docs --- .../src/opentelemetry/instrumentation/mysql/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index a2f0440c7f..8af9e6ed11 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -24,13 +24,19 @@ the query with contextual information. Usage ----- + .. code:: python + from opentelemetry.instrumentation.mysql import MySQLInstrumentor() MySQLInstrumentor().instrument(enable_commenter=True, commenter_options={}) + For example, + :: + Invoking cursor.execute("select * from auth_users") will lead to sql query "select * from auth_users" but when SQLCommenter is enabled the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;" + SQLCOMMENTER Configurations *************************** We can configure the tags to be appended to the sqlquery log by adding configuration inside commenter_options(default:{}) keyword