From 56399ad50a5b57518c5b4ca5749f449e4838a286 Mon Sep 17 00:00:00 2001 From: pajowu Date: Fri, 15 Dec 2023 16:30:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Calculate=20query=20count=20usin?= =?UTF-8?q?g=20session=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/transcribee_backend/db/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/transcribee_backend/db/__init__.py b/backend/transcribee_backend/db/__init__.py index 2c067fae..31cb6721 100644 --- a/backend/transcribee_backend/db/__init__.py +++ b/backend/transcribee_backend/db/__init__.py @@ -49,14 +49,13 @@ def SessionContextManager(path: str): @contextmanager def query_counter(session: Session, path: Optional[str]): - engine = session.connection().engine count = 0 def callback(*args, **kwargs): nonlocal count count += 1 - event.listen(engine, "before_cursor_execute", callback) + event.listen(session, "do_orm_execute", callback) yield - event.remove(engine, "before_cursor_execute", callback) + event.remove(session, "do_orm_execute", callback) query_histogram.labels(path=path).observe(count)