Convex function logging
A request for automatic logging middleware at the Convex platform level with the following capabilities:
Automatic Function Logging
- Log function arguments and return values automatically
- No manual console.log statements required in code
- Especially helpful for functions with multiple return points
Dashboard Controls
- Toggle logging on/off through the Convex dashboard
- Control logging at environment level (dev, staging, prod)
- Enable temporary debugging in non-development environments
Benefits
- Troubleshooting issues in production or staging environments
- Avoid cluttering code with temporary logging statements
- Needing to understand data flow without modifying code
- Quickly enabling/disabling logging as needed (default to off)
9 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Agree that a bunch of this would be useful! I want to point out that you can actually build a lot of this yourself (if you don't want to wait on us).
You can add middleware with
customFunctions
to at least log the arguments (I don't see a super easy way to do it for return values at the moment). And you can get toggle-able logging that's configurable per instance by wrapping console.log
and gating the log on an environment variable (here is something I did for one of my own apps, we've been doing some similar stuff for Convex components we author too example)Thanks. I already do these suggestions. It’s probably my most common logging requirement, to see the inputs and outputs of a functions. Having it at the platform level would just make the dev experience all the more impressive.
is there something specific that a platform-level solution feels like it would do, outside of the current middleware-oriented approach?
It seems being able to easily log the return value would be the main thing. Could this be done using my own middleware?
gotcha. good question for @Ian re: can you log return values
Today with a custom function you could log the arguments, but I'd need to add an intervention point (which I've meant to for a while) for the return value.
I used to be thinking along the lines of allowing the return handler to modify the content, but that doesn't generalize well without per-endpoint wrappers.
However, now I'm thinking of just a
finally
sort of handler that gets the error or result. In there you could log the result, and for success maybe call any "flush" calls on helpers that buffered changes - e.g. scheduling functions with a batch of triggered changes, instead of running them in the same transaction.I cut https://github.com/get-convex/convex-helpers/pull/516 optimistically - always open to contributions too.
GitHub
Add finally callback to customFunction by devin-ai-integration[bot]...
Add the ability for customFunction to have a 'finally' function that will be called with the result/error of calling the handler. Implemented for customQuery, customMutation, and cu...
Some sort of
finally
handler would be useful. I don't understand the concept of "flush" calls though.