27 Commits

Author SHA1 Message Date
26bcc9347b SQLAlchemy: db.statement inclusion of sqlcomment as opt-in (#3112) 2025-01-09 12:56:14 -08:00
76170313f1 Fix instrumentation of SQLAlchemy when using sqlalchemy.engine_from_config (#2816)
* 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>
2024-12-04 10:13:07 +02:00
b6541f0bad 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>
2024-12-03 09:31:08 +00:00
1d8286c08a Update tests to work with SQLAlchemy 2 (#2976) 2024-11-07 15:18:05 -08:00
79d62b3bcd sqlalchemy wrap_create_engine now accepts sqlcommenter options (#1873)
* sqlalchemy wrap_create_engine accepts sqlcommenter options

* Changelog

* Lint

* Fix default val

* Add sqlalchemy tests

* Change a default in _instrument get

* Lint

* More lint

* Update default

Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>

* Update args doc

* lintttt

---------

Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
2023-06-27 13:43:35 +03:00
2e49ba1af8 Use a weak reference to sqlalchemy Engine to avoid memory leak (#1771)
* 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>
2023-06-27 11:37:27 +03:00
3bcc043e9d Add connection attributes to sqlalchemy connect span (#1608)
* Add connection attributes to sqlalchemy connect span

* Fix formatting

* Move changelog entry to unreleased section

---------

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
2023-02-20 17:17:18 +00:00
bbe7578d17 Fix sqlalchemy uninstrument (#1581) 2023-01-29 09:43:06 +05:30
43d0c6cae3 fix the instantiation of NoOpTracerProvider (#1577) 2023-01-12 17:16:03 +00:00
346160467f add a test using NoOpTracerProvider - sqlalchemy (#1508) 2023-01-01 18:33:34 +00:00
99e0b42635 Add uninstrument test for sqlalchemy (#1471) 2022-12-05 22:28:10 +05:30
be4ceec08c Strip leading comments from SQL queries when generating the span name. (#1434)
Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
2022-11-18 14:01:07 +01:00
7c75b3867b SQLCommenter semicolon bug fix (#1200) 2022-07-22 07:52:40 +05:30
2ce69a668f Add span for connection phase (#1134) 2022-07-17 21:09:15 +05:30
f03bef2579 Add support to instrument multiple sqlalchemy engines (#1132)
* Override __new__ to instrument multiple engines

* add possibility to instrument mutiple engines

* update changelog

* update return type in doc

* fix CHANGELOG

* format

* fix test

* Check if engines isinstance Sequence

Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
2022-06-16 13:44:55 +02:00
80969a06da use sqlalchemy module name not engine. fixes #922 (#1086) 2022-05-11 15:08:19 +05:30
dbb35a2946 Sqlcommenter integration into SQLAlchemy (#924)
* Integrating sqlcommenter into psycopg2

* Integrating sqlcommenter into psycopg2 - Converted public local variable into private

* Added test cases for sqlcommenter & PR Changes

* Code refactoring for generate sqlcommenter

* Added testcase for sqlcommenter integration into sqlalchemy

* updated change log

* updated to accept latest logs

* Updated lint changes

* Fixed errors due to linting

* Fixed linting errors

* Fixed linting errors

* Fixed linting errors

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2022-03-08 23:57:00 -06:00
3137c1fa41 Upgrade black (#802) 2021-11-10 20:57:01 +00:00
e8af7a3339 Respect provided tracer provider when instrumenting SQLAlchemy (#728)
* 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
2021-10-12 17:49:22 +00:00
c8b6de6c1c Add support for SQLAlchemy 1.4 (#568) 2021-08-04 15:00:10 -07:00
f436514554 Replaced Tracer.use_span() with opentelemetry.trace.use_span() (#364) 2021-03-08 09:33:49 -08:00
8c8f2785bd SQLAlchemy: Use SQL operation and DB name as the Span name (#254)
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.
2021-01-20 08:41:19 -08:00
9fea7f7a27 Ensure SQLAlchemy spans have kind set to CLIENT (#278)
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.
2021-01-05 09:05:58 -08:00
d36edda08a Remove service from tests 2020-11-23 22:57:07 +05:30
3786d6d0fa Fix tests 2020-11-21 22:22:57 +05:30
169f62c8ce Use is_recording flag in aiopg, asyncpg, dbapi, psycopg2, pymemcache, pymongo, redis, sqlalchemy instrumentations (#1212) 2020-10-22 15:30:26 -07:00
ede460e7e6 Rename db framework packages from "ext" to "instrumentation" (#966) 2020-10-22 15:30:26 -07:00