@@ -61,7 +61,13 @@ Environment Variables:
61
61
62
62
`
63
63
64
- const jfrogAppName = "jf"
64
+ const (
65
+ jfrogAppName = "jf"
66
+ traceIdLogMsg = "Trace ID for JFrog Platform logs:"
67
+ )
68
+
69
+ // Trace ID that is generated for the Uber Trace ID header.
70
+ var traceID string
65
71
66
72
func main () {
67
73
log .SetDefaultLogger ()
@@ -129,18 +135,20 @@ func execMain() error {
129
135
return nil
130
136
}
131
137
err = app .Run (args )
138
+ logTraceIdOnFailure (err )
132
139
return err
133
140
}
134
141
135
142
// This command generates and sets an Uber Trace ID token which will be attached as a header to every request.
136
143
// This allows users to easily identify which logs on the server side are related to the command executed by the CLI.
137
144
func setUberTraceIdToken () error {
138
- traceID , err := generateTraceIdToken ()
145
+ var err error
146
+ traceID , err = generateTraceIdToken ()
139
147
if err != nil {
140
148
return err
141
149
}
142
150
httpclient .SetUberTraceIdToken (traceID )
143
- clientlog .Debug ("Trace ID for JFrog Platform logs:" , traceID )
151
+ clientlog .Debug (traceIdLogMsg , traceID )
144
152
return nil
145
153
}
146
154
@@ -156,6 +164,13 @@ func generateTraceIdToken() (string, error) {
156
164
return hex .EncodeToString (buf ), nil
157
165
}
158
166
167
+ func logTraceIdOnFailure (err error ) {
168
+ if err == nil || traceID == "" {
169
+ return
170
+ }
171
+ clientlog .Info (traceIdLogMsg , traceID )
172
+ }
173
+
159
174
// Detects typos and can identify one or more valid commands similar to the error command.
160
175
// In Addition, if a subcommand is found with exact match, preferred it over similar commands, for example:
161
176
// "jf bp" -> return "jf rt bp"
0 commit comments