Skip to content

Commit

Permalink
NoOpTracerProvider test case for sqlite instrumentation update
Browse files Browse the repository at this point in the history
Signed-off-by: Wali, Sunil Shidrayi <[email protected]>
  • Loading branch information
Sunilwali679 committed Jul 26, 2024
1 parent 8a37f52 commit c78e4a3
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", ())


0 comments on commit c78e4a3

Please sign in to comment.