Add uninstrument test for sqlalchemy (#1471)

This commit is contained in:
Shalev Roda
2022-12-05 18:58:10 +02:00
committed by GitHub
parent bc57cc029d
commit 99e0b42635
2 changed files with 28 additions and 0 deletions

View File

@ -227,3 +227,29 @@ class TestSqlalchemyInstrumentation(TestBase):
)
asyncio.get_event_loop().run_until_complete(run())
def test_uninstrument(self):
engine = create_engine("sqlite:///:memory:")
SQLAlchemyInstrumentor().instrument(
engine=engine,
tracer_provider=self.tracer_provider,
)
cnx = engine.connect()
cnx.execute("SELECT 1 + 1;").fetchall()
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 2)
# first span - the connection to the db
self.assertEqual(spans[0].name, "connect")
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
# second span - the query itself
self.assertEqual(spans[1].name, "SELECT :memory:")
self.assertEqual(spans[1].kind, trace.SpanKind.CLIENT)
self.memory_exporter.clear()
SQLAlchemyInstrumentor().uninstrument()
engine2 = create_engine("sqlite:///:memory:")
cnx2 = engine2.connect()
cnx2.execute("SELECT 2 + 2;").fetchall()
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 0)