Skip to content

Commit 99e0b42

Browse files
authored
Add uninstrument test for sqlalchemy (#1471)
1 parent bc57cc0 commit 99e0b42

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Add uninstrument test for sqlalchemy
11+
([#1471](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1471))
1012
- `opentelemetry-instrumentation-tortoiseorm` Initial release
1113
([#685](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/685))
1214
- Add metric instrumentation for tornado

instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py

+26
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,29 @@ async def run():
227227
)
228228

229229
asyncio.get_event_loop().run_until_complete(run())
230+
231+
def test_uninstrument(self):
232+
engine = create_engine("sqlite:///:memory:")
233+
SQLAlchemyInstrumentor().instrument(
234+
engine=engine,
235+
tracer_provider=self.tracer_provider,
236+
)
237+
cnx = engine.connect()
238+
cnx.execute("SELECT 1 + 1;").fetchall()
239+
spans = self.memory_exporter.get_finished_spans()
240+
241+
self.assertEqual(len(spans), 2)
242+
# first span - the connection to the db
243+
self.assertEqual(spans[0].name, "connect")
244+
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
245+
# second span - the query itself
246+
self.assertEqual(spans[1].name, "SELECT :memory:")
247+
self.assertEqual(spans[1].kind, trace.SpanKind.CLIENT)
248+
249+
self.memory_exporter.clear()
250+
SQLAlchemyInstrumentor().uninstrument()
251+
engine2 = create_engine("sqlite:///:memory:")
252+
cnx2 = engine2.connect()
253+
cnx2.execute("SELECT 2 + 2;").fetchall()
254+
spans = self.memory_exporter.get_finished_spans()
255+
self.assertEqual(len(spans), 0)

0 commit comments

Comments
 (0)