* wrap sqlalchemy.engine.create.create_engine
sqlalchemy.engine_from_config directly calls create_engine imported from that path; if we don't
wrap that copy of the `create_engine` call then engines created via engine_from_config are not
instrumented.
* add changelog entry
* Update CHANGELOG.md
Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
* Update instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py
Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
* make some monkey-patching conditional on the version of SQLAlchemy
* lint
* fix changelog
Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>
* Update CHANGELOG.md
---------
Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
* 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>
* Use a weak reference to sqlalchemy Engine to avoid memory leak
Closes#1761
By using a weak reference to the `Engine` object, we can avoid the memory leak as disposed `Engines` get properly deallocated. Whenever `SQLAlchemy` is uninstrumented, we only trigger a removal for those event listeners which are listening for objects that haven't been garbage-collected yet.
* Made a mistake in resolving the weak reference
* Fixed formatting issues
* Updated changelog
* Added unit test to check that engine was garbage collected
* Do not save engine in EngineTracer to avoid memory leak
* Add an empty line to satisfy black formatter
* Fix isort complaints
* Fixed the issue when pool name is not set and =None
* Fix formatting issue
* Rebased after changes in a recent commit
* Updated PR number in changelog
---------
Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
* respect provided tracer provider when instrumenting sqlalchemy
This change updates the SQLALchemyInstrumentor to respect the tracer
provider that is passed in through the kwargs when patching the
`create_engine` functionality provided by SQLAlchemy. Previously, it
would default to the global tracer provider.
* feedback: pass in tracer_provider directly rather than kwargs
* feedback: update changelog
* build: lint
Current instrumentation uses the entire SQL query as the operation name
which makes traces very hard to read and understand in addition to
introducing high-cardinality issues. This commit fixes the problem by
using only the SQL operation name and the DB name instead of the entire
query.
SQLAlchemy spans were missing kind field and it was being set to
internal instead of client. This commit changes sqlalchemy spans to have
kind set to "client" instead.