-
Notifications
You must be signed in to change notification settings - Fork 89
Improve error logging #629
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
base: main
Are you sure you want to change the base?
Conversation
improve logs from stderr to zap
@@ -66,7 +63,7 @@ | |||
WithCreator(). | |||
All(ctx) | |||
if err != nil { | |||
log.Println("Error when getting team API keys: ", err) | |||
zap.L().Warn("error when getting team API keys", zap.Error(err)) |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Sensitive data returned by an access to TeamAPIKey
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 7 days ago
To fix the issue, we should ensure that sensitive information is not logged in plaintext. Instead of logging the raw error object, we can log a generic error message that does not include sensitive details. If additional context is needed for debugging, we can log a sanitized or obfuscated version of the error message. This approach ensures that sensitive data is not exposed while still providing useful information for troubleshooting.
-
Copy modified line R66
@@ -65,3 +65,3 @@ | ||
if err != nil { | ||
zap.L().Warn("error when getting team API keys", zap.Error(err)) | ||
zap.L().Warn("error when getting team API keys", zap.String("error", "an error occurred while querying team API keys")) | ||
c.String(http.StatusInternalServerError, "Error when getting team API keys") |
if OTELTracingPrint { | ||
var msg string | ||
debugID := getDebugID(ctx) | ||
zap.L().Error(message, zap.Stringp("debug_id", debugID), zap.Error(err), zap.Any("attrs", attrs)) |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Sensitive data returned by an access to apiKeyIDParsed
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 7 days ago
To fix the issue, we need to ensure that sensitive information is not logged in plaintext. This can be achieved by sanitizing the err
object before logging it. Specifically, we can replace sensitive details in the error message with a generic placeholder or remove them entirely. Additionally, we can implement a utility function to sanitize error messages consistently across the codebase.
In this case, we will modify the ReportCriticalError
and ReportError
functions in packages/shared/pkg/telemetry/tracing.go
to sanitize the err
object before passing it to the logging call. This ensures that sensitive data is not exposed in the logs.
-
Copy modified lines R80-R81 -
Copy modified lines R99-R100
@@ -79,3 +79,4 @@ | ||
debugID := getDebugID(ctx) | ||
zap.L().Error(message, zap.Stringp("debug_id", debugID), zap.Error(err), zap.Any("attrs", attrs)) | ||
sanitizedErr := sanitizeError(err) | ||
zap.L().Error(message, zap.Stringp("debug_id", debugID), zap.Error(sanitizedErr), zap.Any("attrs", attrs)) | ||
|
||
@@ -97,3 +98,4 @@ | ||
debugID := getDebugID(ctx) | ||
zap.L().Warn(message, zap.Stringp("debug_id", debugID), zap.Error(err), zap.Any("attrs", attrs)) | ||
sanitizedErr := sanitizeError(err) | ||
zap.L().Warn(message, zap.Stringp("debug_id", debugID), zap.Error(sanitizedErr), zap.Any("attrs", attrs)) | ||
|
Change stderr to zap logs. Add logging for all critical and non-critical telemetry errors