Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Improve error logging #629

wants to merge 1 commit into from

Conversation

dobrac
Copy link
Contributor

@dobrac dobrac commented May 8, 2025

Change stderr to zap logs. Add logging for all critical and non-critical telemetry errors

improve logs from stderr to zap
@dobrac dobrac self-assigned this May 8, 2025
@dobrac dobrac added the improvement Improvement for current functionality label May 8, 2025
@@ -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
flows to a logging call.

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.


Suggested changeset 1
packages/api/internal/handlers/apikey.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/api/internal/handlers/apikey.go b/packages/api/internal/handlers/apikey.go
--- a/packages/api/internal/handlers/apikey.go
+++ b/packages/api/internal/handlers/apikey.go
@@ -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")
EOF
@@ -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")
Copilot is powered by AI and may make mistakes. Always verify output.
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
flows to a logging call.

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.


Suggested changeset 1
packages/shared/pkg/telemetry/tracing.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/shared/pkg/telemetry/tracing.go b/packages/shared/pkg/telemetry/tracing.go
--- a/packages/shared/pkg/telemetry/tracing.go
+++ b/packages/shared/pkg/telemetry/tracing.go
@@ -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))
 
EOF
@@ -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))

Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement for current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant