Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace should show queries on the write connection too #1568

Closed
simonw opened this issue Dec 18, 2021 · 2 comments
Closed

Trace should show queries on the write connection too #1568

simonw opened this issue Dec 18, 2021 · 2 comments

Comments

@simonw
Copy link
Owner

simonw commented Dec 18, 2021

Here's why - trace only applies to read, not write SQL operations:

with trace("sql", database=self.name, sql=sql.strip(), params=params):
results = await self.execute_fn(sql_operation_in_thread)
return results

Originally posted by @simonw in #1555 (comment)

@simonw
Copy link
Owner Author

simonw commented Dec 18, 2021

Prototype:

diff --git a/datasette/database.py b/datasette/database.py
index 0a0c104..468e936 100644
--- a/datasette/database.py
+++ b/datasette/database.py
@@ -99,7 +99,9 @@ class Database:
             with conn:
                 return conn.execute(sql, params or [])
 
-        return await self.execute_write_fn(_inner, block=block)
+        with trace("sql", database=self.name, sql=sql.strip(), params=params):
+            results = await self.execute_write_fn(_inner, block=block)
+        return results
 
     async def execute_write_fn(self, fn, block=False):
         task_id = uuid.uuid5(uuid.NAMESPACE_DNS, "datasette.io")

image

@simonw simonw closed this as completed in f81d9d0 Dec 18, 2021
@simonw simonw removed the research label Dec 18, 2021
@simonw
Copy link
Owner Author

simonw commented Dec 18, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant