Remove references to disposed SQLAlchemy engines from instrumentation singleton (#3053)

* Remove references to SQLAlchemy engines which are disposed of

EngineTracer in SQLAlchemy keeps weak references to a traced engine forever which
can cause a noticeable memory leak if engines are constantly getting creating.

* Updated changelog

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
This commit is contained in:
Rytis Bagdziunas
2024-12-03 10:31:08 +01:00
committed by GitHub
parent 668cb75f24
commit b6541f0bad
3 changed files with 20 additions and 0 deletions

View File

@ -417,6 +417,10 @@ class TestSqlalchemyInstrumentation(TestBase):
from sqlalchemy import create_engine
from opentelemetry.instrumentation.sqlalchemy.engine import (
EngineTracer,
)
callback = mock.Mock()
def make_shortlived_engine():
@ -432,3 +436,4 @@ class TestSqlalchemyInstrumentation(TestBase):
gc.collect()
assert callback.call_count == 5
assert len(EngineTracer._remove_event_listener_params) == 0