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 trace ID on failure #2556

Merged
merged 3 commits into from
May 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ Environment Variables:

`

const jfrogAppName = "jf"
const (
jfrogAppName = "jf"
traceIdLogMsg = "Trace ID for JFrog Platform logs:"
RobiNino marked this conversation as resolved.
Show resolved Hide resolved
)

// Trace ID that is generated for the Uber Trace ID header.
var traceID string

func main() {
log.SetDefaultLogger()
Expand Down Expand Up @@ -129,18 +135,20 @@ func execMain() error {
return nil
}
err = app.Run(args)
logTraceIdOnFailure(err)
return err
}

// This command generates and sets an Uber Trace ID token which will be attached as a header to every request.
// This allows users to easily identify which logs on the server side are related to the command executed by the CLI.
func setUberTraceIdToken() error {
traceID, err := generateTraceIdToken()
var err error
traceID, err = generateTraceIdToken()
if err != nil {
return err
}
httpclient.SetUberTraceIdToken(traceID)
clientlog.Debug("Trace ID for JFrog Platform logs: ", traceID)
clientlog.Debug(traceIdLogMsg + " " + traceID)
RobiNino marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand All @@ -156,6 +164,13 @@ func generateTraceIdToken() (string, error) {
return hex.EncodeToString(buf), nil
}

func logTraceIdOnFailure(err error) {
if err == nil || traceID == "" {
return
}
clientlog.Error(traceIdLogMsg + " " + traceID)
RobiNino marked this conversation as resolved.
Show resolved Hide resolved
}

// Detects typos and can identify one or more valid commands similar to the error command.
// In Addition, if a subcommand is found with exact match, preferred it over similar commands, for example:
// "jf bp" -> return "jf rt bp"
Expand Down
Loading