Logging in actions

How can I get logs in my convex action functions?
25 Replies
ballingt
ballingt3y ago
Hi @Chad Maycumber! Logs from actions (and errors from actions) should show up both in the browser console and the Convex dashboard.
No description
Chad Maycumber
Chad MaycumberOP3y ago
Thanks for some reason printing objects to the console don't show up on the right side pan for me Maybe it's my browser? They also get truncated in scape underneath the function space*
ballingt
ballingt3y ago
Sounds odd, could you share what this looks like or say more about the truncation? And are these logs showing up in the dashboard but not the browser, or not in either place?
Chad Maycumber
Chad MaycumberOP3y ago
Here's the side pan and the piece of code
No description
No description
Chad Maycumber
Chad MaycumberOP3y ago
I can get it to print with JSON.stringifying the response.data object Thanks for the quick response btw much appreciated
ballingt
ballingt3y ago
Ah ok, likely this has to do with our console.log implementation not doing a good job stringifying What is that response object? I was guessing Axios but when I try to repro an axios response.data object can be logged fine
ballingt
ballingt3y ago
No description
Chad Maycumber
Chad MaycumberOP3y ago
I think it is axios under the hood, but I'm using openai's node library
ballingt
ballingt3y ago
do you know what data is? maybe a simple object, or a string? If it's an array buffer that might be a type we don't do a good job with also I see logs in the logs, but not in that side pane if that's the other thing you were asking about
Chad Maycumber
Chad MaycumberOP3y ago
Let me get that for you Also this is the first time I'm using convex and it's pretty awesome. Does this work in react native?
ballingt
ballingt3y ago
GitHub
convex-demos/react-native at main · get-convex/convex-demos
Demo apps built on Convex. Contribute to get-convex/convex-demos development by creating an account on GitHub.
Chad Maycumber
Chad MaycumberOP3y ago
Also is this best practice for deletes? Sorry for the side track
No description
ballingt
ballingt3y ago
That's great, yeah — when they're expressed in parallel like that we can optimize them
Chad Maycumber
Chad MaycumberOP3y ago
The response type was an object
ballingt
ballingt3y ago
I think we print basically the JSON.stringify(obj) for objects, but if it were an object with a prototype with lots of methods (aka an instance of a class) then that's not very useful If it's easy to check, could you check the response.data.constructor? we have some ideas to do better here in general, but I want to check these ideas would actually fix this for you
Chad Maycumber
Chad MaycumberOP3y ago
For sure. If it helps too here's a stringified response taken from the convex UI:
'Response' '{"id":"cmpl-6TEBLE0YOJxfxU7kKhfXlRiq0uEOX","object":"text_completion","created":1672424047,"model":"text-ada-001","choices":[{"text":" and London are getting a bit too close to each other. The separation of cool spots should help prevent this from happening.\\n\\nAnya is correct that this separation could help prevent this from happening. This is how it works:\\n\\nA cool spot is the area between two other cool spots. When two other cool spots are close together, the area between them becomes smaller and smalle'
'Response' '{"id":"cmpl-6TEBLE0YOJxfxU7kKhfXlRiq0uEOX","object":"text_completion","created":1672424047,"model":"text-ada-001","choices":[{"text":" and London are getting a bit too close to each other. The separation of cool spots should help prevent this from happening.\\n\\nAnya is correct that this separation could help prevent this from happening. This is how it works:\\n\\nA cool spot is the area between two other cool spots. When two other cool spots are close together, the area between them becomes smaller and smalle'
ballingt
ballingt3y ago
This is what the dashboard prints normally, or this is what it prints after you stringify it in your code?
Chad Maycumber
Chad MaycumberOP3y ago
Seems like you may have been correct here's the constructor: 'Response: ' [Function: Object]
ballingt
ballingt3y ago
Got, ok we'll improve this, thanks for reporting! Which openai wrapper are you using, so I can repro? oh you said it's openai's so I assume the official one not one of the unofficial libraries that scrapes it assuming it's this one https://www.npmjs.com/package/openai
Chad Maycumber
Chad MaycumberOP3y ago
Correct
ballingt
ballingt3y ago
Hm I'm having trouble reproing this, when I log response or response.data they look ok
No description
ballingt
ballingt3y ago
No description
ballingt
ballingt3y ago
Would you be willing to share your code? Just the openAI bit may be enough. You can DM me here or email tom@convex.dev
Chad Maycumber
Chad MaycumberOP3y ago
Yeah sure
ballingt
ballingt3y ago
Turns out (we worked through this together) that logs are showing up in the developer console of the webapp where Convex is being used, it's just in the dashboard that logs are being cut off and not appearing at all in the details view. We'll fix this, thanks for reporting!

Did you find this page helpful?