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

log: Auto wrap baseplate.Error in logs #608

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

fishy
Copy link
Member

@fishy fishy commented Mar 3, 2023

A pain point currently is that thrift generated baseplate.Error doesn't provide human readable message automatically since we are using optional fields, logging it will not produce human readable/meaningful info.

Although we provided WrapBaseplateError helper function, it has its own limitations, for example it's usually only safe to be used unconditionally on the client side, which limited its usefulness on the server side.

Add a wrapper to zapcore to auto wrap baseplate.Errors, so whenever they are logged via kv pairs they are always auto wrapped.

@fishy fishy requested a review from a team as a code owner March 3, 2023 21:59
@fishy fishy requested review from kylelemons, pacejackson and ghirsch-reddit and removed request for a team March 3, 2023 21:59
if actual != expectedOrigin {
t.Errorf("Expected log line %s, got %s", expectedOrigin, actual)
if !strings.HasPrefix(actual, expectedOriginPrefix) {
t.Errorf("Expected log line to start with `%s`, got %s", expectedOriginPrefix, actual)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Expected log line to start with `%s`, got %s", expectedOriginPrefix, actual)
t.Errorf("Expected log line to start with %q, got %q", expectedOriginPrefix, actual)

Copy link
Contributor

@ghirsch-reddit ghirsch-reddit left a comment

Choose a reason for hiding this comment

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

LGTM

Also a suggestion for future PRs like this where you move code, it can be convenient to make multiple commits where the first is literally just copy-pasting. That way it's quick for reviewers to first see that change, and to then look at the "actual changes" by filtering to just the other commits.

A pain point currently is that thrift generated baseplate.Error doesn't
provide human readable message automatically since we are using optional
fields, logging it will not produce human readable/meaningful info.

Although we provided WrapBaseplateError helper function, it has its own
limitations, for example it's usually only safe to be used
unconditionally on the client side, which limited its usefulness on the
server side.

Add a wrapper to zapcore to auto wrap baseplate.Errors, so whenever they
are logged via kv pairs they are always auto wrapped.
@fishy fishy merged commit 364b717 into reddit:master Mar 7, 2023
@fishy fishy deleted the zap-wrap-baseplate-error branch March 7, 2023 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants