From 99e7fb1d52204a7b7cae9f2d9e0a51e1febf8e01 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 7 Jan 2022 11:53:28 +0000 Subject: Wrap connection.commit with OpenTracing This is an attempt to diagnose poor apdex levels, per https://github.com/matrix-org/internal-config/issues/1181 --- synapse/storage/database.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'synapse/storage/database.py') diff --git a/synapse/storage/database.py b/synapse/storage/database.py index 2cacc7dd6c..3f848ca86f 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -50,6 +50,7 @@ from synapse.logging.context import ( current_context, make_deferred_yieldable, ) +from synapse.logging.opentracing import trace from synapse.metrics import register_threadpool from synapse.metrics.background_process_metrics import run_as_background_process from synapse.storage.background_updates import BackgroundUpdater @@ -104,8 +105,20 @@ def make_pool( # Ensure we have a logging context so we can correctly track queries, # etc. with LoggingContext("db.on_new_connection"): + # HACK Patch the connection's commit function so that we can see + # how long it's taking from Jaeger. + class NastyConnectionWrapper: + def __init__(self, connection): + self._connection = connection + self.commit = trace(connection.commit, "db.conn.commit") + + def __getattr__(self, item): + return getattr(self._connection, item) + engine.on_new_connection( - LoggingDatabaseConnection(conn, engine, "on_new_connection") + LoggingDatabaseConnection( + NastyConnectionWrapper(conn), engine, "on_new_connection" + ) ) connection_pool = adbapi.ConnectionPool( -- cgit 1.5.1