Merge pull request #21 from starkSV/feat/telemetry-error-field
feat(telemetry): capture error message on failed CLI runs
This commit is contained in:
commit
6d55ee573f
2 changed files with 20 additions and 0 deletions
|
|
@ -579,6 +579,7 @@ type telemetryPayload struct {
|
|||
Platform string `json:"platform"`
|
||||
Version string `json:"version"`
|
||||
Success bool `json:"success"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// --- Evalcenter helpers ---
|
||||
|
|
@ -1662,6 +1663,9 @@ func handleTelemetry(w http.ResponseWriter, r *http.Request) {
|
|||
result = "failed"
|
||||
}
|
||||
rdb.HIncrBy(ctx, "msdl:telemetry:results", result, 1)
|
||||
if !p.Success && p.Error != "" && len(p.Error) <= 200 {
|
||||
rdb.HIncrBy(ctx, "msdl:telemetry:errors", p.Error, 1)
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
@ -1695,6 +1699,7 @@ func loadTelemetryFromRedis() map[string]map[string]string {
|
|||
"msdl:telemetry:versions",
|
||||
"msdl:telemetry:products",
|
||||
"msdl:telemetry:results",
|
||||
"msdl:telemetry:errors",
|
||||
}
|
||||
out := make(map[string]map[string]string, len(keys))
|
||||
for _, k := range keys {
|
||||
|
|
|
|||
15
cli/main.go
15
cli/main.go
|
|
@ -87,6 +87,20 @@ type cliTelemetryPayload struct {
|
|||
Platform string `json:"platform"`
|
||||
Version string `json:"version"`
|
||||
Success bool `json:"success"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// truncateError caps an error string for telemetry (avoids leaking huge bodies,
|
||||
// keeps Redis field values small).
|
||||
func truncateError(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
s := err.Error()
|
||||
if len(s) > 150 {
|
||||
s = s[:150]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// sendTelemetry posts a single telemetry event. Fire-and-forget: all errors
|
||||
|
|
@ -243,6 +257,7 @@ More info: https://msdl.tech-latest.com/cli`)
|
|||
Platform: runtime.GOOS,
|
||||
Version: Version,
|
||||
Success: err == nil,
|
||||
Error: truncateError(err),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue