Add ability to trace SQL transactions with profiler

Closes-Bug: #2082944
Change-Id: I8781359e338ffb44e5f55211bec147000a2097cb
This commit is contained in:
Sylvan Le Deunff
2024-09-27 10:31:25 +02:00
parent dca04e2270
commit 6b796905a5
2 changed files with 14 additions and 0 deletions

View File

@@ -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()

View File

@@ -0,0 +1,5 @@
---
fixes:
- |
Added tracing to SQLAlchemy engine if profiler is enabled and
profiler.trace_sqlalchemy is set to true.