From 260ee1d51caad8a5018157f7e8c8ac22dd0a5efa Mon Sep 17 00:00:00 2001 From: "Wali, Sunil Shidrayi" Date: Tue, 18 Jun 2024 13:38:28 +0530 Subject: [PATCH 1/3] test_sqlite3.py Added test case for test_no_op_tracer_provider --- .../tests/test_sqlite3.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py index 581920232b..7300a06984 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py @@ -100,3 +100,15 @@ def test_callproc(self): ): self._cursor.callproc("test", ()) self.validate_spans("test") + + def test_no_op_tracer_provider(self): + """Should not create any spans when using NoOpTracerProvider""" + SQLite3Instrumentor().uninstrument() + SQLite3Instrumentor().instrument(tracer_provider=trace_api.NoOpTracerProvider()) + self._create_tables() + stmt = "INSERT INTO test (id) VALUES (?)" + data = [("1",), ("2",), ("3",)] + with self._tracer.start_as_current_span("rootSpan"): + self._cursor.executemany(stmt, data) + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 0) From 8a37f52bf5c9368bc8f5b86dc6bf97d52625908e Mon Sep 17 00:00:00 2001 From: "Wali, Sunil Shidrayi" Date: Wed, 19 Jun 2024 13:52:50 +0530 Subject: [PATCH 2/3] Update test_sqlite3.py updated the len(spans) --- .../opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py index 7300a06984..d0f6c2de44 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py @@ -111,4 +111,4 @@ def test_no_op_tracer_provider(self): with self._tracer.start_as_current_span("rootSpan"): self._cursor.executemany(stmt, data) spans = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans), 0) + self.assertEqual(len(spans), 2) From c78e4a3b153f21daaf9e338cf8aaa2455a5a5385 Mon Sep 17 00:00:00 2001 From: "Wali, Sunil Shidrayi" Date: Fri, 26 Jul 2024 16:37:15 +0530 Subject: [PATCH 3/3] NoOpTracerProvider test case for sqlite instrumentation update Signed-off-by: Wali, Sunil Shidrayi --- .../tests/test_sqlite3.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py index d0f6c2de44..ebea78efd8 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py @@ -101,14 +101,23 @@ def test_callproc(self): self._cursor.callproc("test", ()) self.validate_spans("test") - def test_no_op_tracer_provider(self): + def test_noop_tracer_provider(self): """Should not create any spans when using NoOpTracerProvider""" SQLite3Instrumentor().uninstrument() - SQLite3Instrumentor().instrument(tracer_provider=trace_api.NoOpTracerProvider()) + SQLite3Instrumentor().instrument(tracer_provider=trace_api.get_tracer_provider()) + self._tracer = trace_api.get_tracer(__name__) self._create_tables() + + stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" + with self._tracer.start_as_current_span("rootSpan"): + self._cursor.execute(stmt) + stmt = "INSERT INTO test (id) VALUES (?)" data = [("1",), ("2",), ("3",)] with self._tracer.start_as_current_span("rootSpan"): self._cursor.executemany(stmt, data) - spans = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans), 2) + + with self._tracer.start_as_current_span("rootSpan"), self.assertRaises(Exception): + self._cursor.callproc("test", ()) + +