Wrap connection.commit with OpenTracing
This is an attempt to diagnose poor apdex levels, per
https://github.com/matrix-org/internal-config/issues/1181
1 files changed, 14 insertions, 1 deletions
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(
|