Skip to content

Commit

Permalink
Add uninstrument test for sqlalchemy (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalevr authored Dec 5, 2022
1 parent bc57cc0 commit 99e0b42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add uninstrument test for sqlalchemy
([#1471](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1471))
- `opentelemetry-instrumentation-tortoiseorm` Initial release
([#685](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/685))
- Add metric instrumentation for tornado
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,29 @@ async def run():
)

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)

0 comments on commit 99e0b42

Please sign in to comment.