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

Improved error logging #49566

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hugoShaka
Copy link
Contributor

@hugoShaka hugoShaka commented Nov 29, 2024

Depends on gravitational/trace#110

Demo code:

err := trace.Errorf("oh no, it's broken")
log.Info("hello", "error", trace.Wrap(err, "callsite info"))

JSON log output:

# without stacktrace
{"timestamp":"2024-11-28T18:00:06-05:00","level":"info","caller":"log/slog_handler_test.go:50","message":"hello","error":"callsite info: oh no, it's broken"}

# with stacktrace
{"timestamp":"2024-11-28T19:45:00-05:00","level":"info","caller":"log/slog_handler_test.go:50","message":"hello","error":"callsite info: oh no, it's broken","error_trace":["github.com/gravitational/teleport/lib/utils/log.TestHugo","testing.tRunner","runtime.goexit"]}

Text output

# without stacktrace
time:2024-11-28 19:53:19.250706 -0500 EST INFO  hello error:callsite info: oh no, it's broken log/slog_handler_test.go:50

# with stacktrace
time:2024-11-28 19:50:04.904607 -0500 EST INFO  hello error:callsite info: oh no, it's broken error_trace:[github.com/gravitational/teleport/lib/utils/log.TestHugo testing.tRunner runtime.goexit] log/slog_handler_test.go:50

I'm not satisfied with the text output but I don't think a text-specific ReplaceAttr would make sense. Sny string containing whitespace currently leads to confusing logs and we might want to fix this issue more generally.

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.

1 participant