-
Notifications
You must be signed in to change notification settings - Fork 42
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
Use custom logger to downgrade canceled context errors to warnings #2936
base: main
Are you sure you want to change the base?
Conversation
This pull request is now in conflicts. Could you fix it? 🙏
|
This pull request does not have a backport label. Could you fix it @orouz? 🙏
|
f6db853
to
d9a4656
Compare
if hasErrorType(context.Canceled, args...) { | ||
l.Warnf(template, args...) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is reason for this PR - downgrading errors to warnings when we see context canceled
func (l *Logger) Named(name string) *Logger { | ||
return &Logger{l.Logger.Named(name)} | ||
} | ||
|
||
func (l *Logger) WithOptions(options ...logp.LogOption) *Logger { | ||
return &Logger{l.Logger.WithOptions(options...)} | ||
} | ||
func (l *Logger) With(args ...any) *Logger { | ||
return &Logger{l.Logger.With(args...)} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're using these methods from logp
and to make types work i had to implement them so their usage returns our custom logger
the implementation just calls the original methods
and the original logger is still available at l.Logger
so i believe it's fine and poses no risk afaik
// Check if the error is of the same type | ||
if err, ok := arg.(error); ok && errors.Is(err, errorType) { | ||
return true | ||
} | ||
|
||
// Check if the error message contains the error type string | ||
if str, ok := arg.(string); ok && strings.Contains(str, errorTypeStr) { | ||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to account for both these cases as we sometimes log Errorf("error: %v", err)
and sometimes we log Errorf("error: ", err.Error())
Summary of your changes
replace
logp
withclog
(custom logger) that wrapsErrorf
in order to downgradecontext.Canceled
to warningsthe errors described in #1154 (table in google doc) are mostly the same ones shown in #2843, but all originate from the same reason - some ongoing request being canceled.