From 2c8ac406ebef1b1ab0ca5b4f57f92fc19bf07422 Mon Sep 17 00:00:00 2001 From: avzis Date: Mon, 19 Dec 2022 23:57:58 +0200 Subject: [PATCH 1/3] add a test using NoOpTracerProvider --- .../tests/test_sqlalchemy.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py index 099c088f64..cfdfde4e71 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py @@ -253,3 +253,13 @@ def test_uninstrument(self): cnx2.execute("SELECT 2 + 2;").fetchall() spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 0) + + def test_no_op_tracer_provider(self): + engine = create_engine("sqlite:///:memory:") + SQLAlchemyInstrumentor().instrument( + engine=engine, + tracer_provider=trace.NoOpTracerProvider, + ) + engine.connect() + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 0) From 621a507b5841b373867bf68e8d19a2747317af35 Mon Sep 17 00:00:00 2001 From: avzis Date: Wed, 21 Dec 2022 16:43:26 +0200 Subject: [PATCH 2/3] validate execute doesnt create a span --- .../tests/test_sqlalchemy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py index cfdfde4e71..31421b49f3 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py @@ -260,6 +260,7 @@ def test_no_op_tracer_provider(self): engine=engine, tracer_provider=trace.NoOpTracerProvider, ) - engine.connect() + cnx = engine.connect() + cnx.execute("SELECT 1 + 1;").fetchall() spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 0) From c5cb8853535dec3aeacbf267402e119f533c6b53 Mon Sep 17 00:00:00 2001 From: avzis Date: Wed, 21 Dec 2022 16:44:22 +0200 Subject: [PATCH 3/3] refactor --- .../tests/test_sqlalchemy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py index 31421b49f3..7f0e655a9e 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py @@ -261,6 +261,6 @@ def test_no_op_tracer_provider(self): tracer_provider=trace.NoOpTracerProvider, ) cnx = engine.connect() - cnx.execute("SELECT 1 + 1;").fetchall() + cnx.execute("SELECT 1 + 1;").fetchall() spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 0)