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

Add logs for code evaluation #2880

Merged
merged 8 commits into from
Nov 29, 2024
Merged

Add logs for code evaluation #2880

merged 8 commits into from
Nov 29, 2024

Conversation

jonatanklosko
Copy link
Member

This adds extra logs whenever code is evaluated, showing the code. The metadata includes people connected to the session (or in case of app previews, the person who deployed the app).

When running Livebook with new env vars LIVEBOOK_LOG_LEVEL=info LIVEBOOK_LOG_METADATA=request_id,users, the log looks like this:

18:25:46.105 users=[%{id: "awj6fkaaznjy6ydzhb77id2czn3cmejd", name: "Jonatan Kłosko"}] [info] Evaluating code
  Session mode: default
  Code: "# This is a Code cell - as the name suggests that's where the code goes.\n# To evaluate this cell, you can either press the \"Evaluate\" button above\n# or use `Ctrl + Enter` (or Cmd + Enter on a Mac)!\n\nmessage = \"hey, grab yourself a cup of 🍵\""

The user information includes id, name and email (if available), so it's best combined with an identity provider.

"""
Evaluating code
Session mode: #{state.data.mode}
Code: #{inspect(cell.source, printable_limit: :infinity)}\
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could interpolate it directly, but printing the new lines would make it much more verbose.

Copy link

github-actions bot commented Nov 29, 2024

Uffizzi Preview deployment-58675 was deleted.

Copy link
Contributor

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick!

into: %{}
end

[users: inspect(list)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing the inspection here is problematic because if we have JSON logging in the future, then it will be sent as a string instead of a lists of objects in JSON. Maybe we can cross this bridge later but we may need a custom data structure here, so we can implement both JSON and String.Chars protocols.

jonatanklosko and others added 3 commits November 29, 2024 13:39
@jonatanklosko
Copy link
Member Author

@josevalim I also added metadata for plug and lv :)

@jonatanklosko jonatanklosko merged commit b7d187b into main Nov 29, 2024
6 checks passed
@jonatanklosko jonatanklosko deleted the jk-evaluation-logs branch November 29, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants