mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 19:47:17 +08:00
Add uninstrument test for sqlalchemy (#1471)
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user