Skip to content

Commit

Permalink
Add uninstrument test for sqlalchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
shalevr committed Nov 30, 2022
1 parent b6f9b62 commit 49aae01
Show file tree
Hide file tree
Showing 2 changed files with 27 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,28 @@ 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)

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), 2)

0 comments on commit 49aae01

Please sign in to comment.