diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py index cc5f76a059..f27bf1cf47 100644 --- a/manila/db/sqlalchemy/api.py +++ b/manila/db/sqlalchemy/api.py @@ -41,6 +41,7 @@ from oslo_utils import importutils from oslo_utils import strutils from oslo_utils import timeutils from oslo_utils import uuidutils +import sqlalchemy as sa from sqlalchemy import and_ from sqlalchemy import MetaData from sqlalchemy import or_ @@ -77,6 +78,14 @@ context_manager = enginefacade.transaction_context() context_manager.configure() +if ( + osprofiler_sqlalchemy and + CONF.profiler.enabled and + CONF.profiler.trace_sqlalchemy +): + context_manager.append_on_engine_create( + lambda engine: osprofiler_sqlalchemy.add_tracing(sa, engine, "db")) + def get_engine(): return context_manager.writer.get_engine() diff --git a/releasenotes/notes/bug-2082944-sqlalchemy-tracing.yml b/releasenotes/notes/bug-2082944-sqlalchemy-tracing.yml new file mode 100644 index 0000000000..0763a09eb3 --- /dev/null +++ b/releasenotes/notes/bug-2082944-sqlalchemy-tracing.yml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Added tracing to SQLAlchemy engine if profiler is enabled and + profiler.trace_sqlalchemy is set to true.