Jules
Jules3w ago

Adding logging middleware to `ctx.db` to monitor read/write sizes in transactions

Hi, we are running into the too many bytes read in a single function execution error for some of our functions. We would like to better understand what is causing this. However, since some of our queries and mutations are a composition of several smaller queries and mutations it can be difficult to get more finegrained insights. Ideally we would like to create some middleware for our DatabaseReader and DatabaseWriter that logs the (approximate) size of the documents that are queried/modified/inserted. Is it supported to implement something like that?
2 Replies
nipunn
nipunn3w ago
It's all typescript. You can write any code you want in there! Eg you can wrap the db with your own structure that tracks things and periodically console.logs. There is a custom query pattern here that could be reasonable starting point https://stack.convex.dev/custom-functions (blog post from @ian ) If you're able to repro, you can also use good ol console.log debugging to see how far you get before running into an issue. Not fancy, but definitely simple and works.
Customizing serverless functions without middleware
Re-use code and centralize request handler definitions with discoverability and type safety and without the indirection of middleware or nesting of wr...
ian
ian3w ago
One thing you can do without injection is to break up the queries into smaller chunks and run them and look at the log stream to see their bandwidth. For wrapping the reader/writer, maybe the RLS helper would make it easy

Did you find this page helpful?