From 6b796905a595f06df6cf3cece420b164dd8bb429 Mon Sep 17 00:00:00 2001 From: Sylvan Le Deunff Date: Fri, 27 Sep 2024 10:31:25 +0200 Subject: [PATCH] Add ability to trace SQL transactions with profiler Closes-Bug: #2082944 Change-Id: I8781359e338ffb44e5f55211bec147000a2097cb --- manila/db/sqlalchemy/api.py | 9 +++++++++ releasenotes/notes/bug-2082944-sqlalchemy-tracing.yml | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 releasenotes/notes/bug-2082944-sqlalchemy-tracing.yml 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.