From f3e0ee2eaa04b2386c7f11382fd78fcd7eb24811 Mon Sep 17 00:00:00 2001 From: avzis Date: Sun, 30 Oct 2022 14:29:53 +0200 Subject: [PATCH 1/7] add a test for mysql instrumentation using NoOpTracerProvider --- .../tests/test_mysql_integration.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py index e2a0f2057c..de527283e1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -20,6 +20,8 @@ from opentelemetry.instrumentation.mysql import MySQLInstrumentor from opentelemetry.sdk import resources from opentelemetry.test.test_base import TestBase +from opentelemetry import trace as trace_api +from opentelemetry.test.globals_test import reset_trace_globals def mock_connect(*args, **kwargs): @@ -103,6 +105,22 @@ def test_instrument_connection(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) + @patch("mysql.connector.connect", new=mock_connect) + # pylint: disable=unused-argument + def test_instrument_connection_No_Op(self): + reset_trace_globals() + tracer_provider = trace_api.NoOpTracerProvider() + trace_api.set_tracer_provider(tracer_provider) + + MySQLInstrumentor().instrument() + cnx = mysql.connector.connect(database="test") + query = "SELECT * FROM test" + cursor = cnx.cursor() + cursor.execute(query) + + spans_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans_list), 0) + @patch("mysql.connector.connect", new=mock_connect) # pylint: disable=unused-argument def test_uninstrument_connection(self): From 6d5cd3b85b5dcb9d43f3e9b74eaf1af421adc3b7 Mon Sep 17 00:00:00 2001 From: avzis Date: Sun, 30 Oct 2022 14:48:23 +0200 Subject: [PATCH 2/7] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbadf6ae16..cca26d0bb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1413](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1413)) - `opentelemetry-instrumentation-pyramid` Add support for regular expression matching and sanitization of HTTP headers. ([#1414](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1414)) +- Add a test for mysql using NoOpTracerProvider + ([#1423](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1423)) ### Fixed From d2dc5a386f615a63d2de815e68f9054494893a83 Mon Sep 17 00:00:00 2001 From: avzis Date: Sun, 30 Oct 2022 16:46:13 +0200 Subject: [PATCH 3/7] rename function --- .../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 de527283e1..99892082cc 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -107,7 +107,7 @@ def test_instrument_connection(self): @patch("mysql.connector.connect", new=mock_connect) # pylint: disable=unused-argument - def test_instrument_connection_No_Op(self): + def test_instrument_connection_no_op_tracer_provider(self): reset_trace_globals() tracer_provider = trace_api.NoOpTracerProvider() trace_api.set_tracer_provider(tracer_provider) From 729d50186bfd248436f0c05bcdd0b77bce61a7f5 Mon Sep 17 00:00:00 2001 From: avzis Date: Sun, 30 Oct 2022 17:08:00 +0200 Subject: [PATCH 4/7] update import order --- .../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 99892082cc..7c92c574eb 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -17,11 +17,11 @@ import mysql.connector import opentelemetry.instrumentation.mysql +from opentelemetry import trace as trace_api from opentelemetry.instrumentation.mysql import MySQLInstrumentor from opentelemetry.sdk import resources -from opentelemetry.test.test_base import TestBase -from opentelemetry import trace as trace_api from opentelemetry.test.globals_test import reset_trace_globals +from opentelemetry.test.test_base import TestBase def mock_connect(*args, **kwargs): From 7b7699c2e6b34fa96359a24fe0907b2b8668a184 Mon Sep 17 00:00:00 2001 From: avzis Date: Thu, 24 Nov 2022 17:43:43 +0200 Subject: [PATCH 5/7] refactor --- .../tests/test_sqlcommenter.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py index 6261c7df58..6cdc5b2f67 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py @@ -16,14 +16,6 @@ import pytest from sqlalchemy import create_engine -from opentelemetry.instrumentation.sqlalchemy.engine import ( - EngineTracer, - _get_tracer, - _wrap_connect, - _wrap_create_async_engine, - _wrap_create_engine, -) - from opentelemetry import context from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor from opentelemetry.test.test_base import TestBase @@ -64,16 +56,6 @@ def test_sqlcommenter_enabled(self): r"SELECT 1 /\*db_driver='(.*)',traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;", ) - def test_sqlcommenter_disabled_with_external_engine(self): - SQLAlchemyInstrumentor().instrument() - engine = create_engine("sqlite:///:memory:") - EngineTracer( - _get_tracer(self.tracer_provider), engine, enable_commenter=True - ) - cnx = engine.connect() - cnx.execute("SELECT 1;").fetchall() - self.assertEqual(self.caplog.records[-2].getMessage(), "SELECT 1;") - def test_sqlcommenter_flask_integration(self): engine = create_engine("sqlite:///:memory:") SQLAlchemyInstrumentor().instrument( From 4fe7215c41f2f91ca5e1da900162b12be68c9d9c Mon Sep 17 00:00:00 2001 From: avzis Date: Thu, 24 Nov 2022 17:53:42 +0200 Subject: [PATCH 6/7] remove unused import --- .../tests/test_mysql_integration.py | 1 - 1 file changed, 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 3d4c099373..8274851ff1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py @@ -20,7 +20,6 @@ from opentelemetry import trace as trace_api from opentelemetry.instrumentation.mysql import MySQLInstrumentor from opentelemetry.sdk import resources -from opentelemetry.test.globals_test import reset_trace_globals from opentelemetry.test.test_base import TestBase From 20e971491af986229e0b543b4464858c03edd628 Mon Sep 17 00:00:00 2001 From: avzis Date: Mon, 28 Nov 2022 15:08:59 +0200 Subject: [PATCH 7/7] remove changelog update --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d4b65f9f5..f336be0cba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,8 +78,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1413](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1413)) - `opentelemetry-instrumentation-pyramid` Add support for regular expression matching and sanitization of HTTP headers. ([#1414](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1414)) -- Add a test for mysql using NoOpTracerProvider - ([#1423](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1423)) - `opentelemetry-instrumentation-grpc` Add support for grpc.aio Clients and Servers ([#1245](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1245)) - Add metric exporter for Prometheus Remote Write