This commit is contained in:
Shreyas Goenka 2025-02-27 13:36:34 +01:00
parent 5da92e94e3
commit 8b3d942b48
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 4 additions and 6 deletions

View File

@ -106,7 +106,7 @@ func Execute(ctx context.Context, cmd *cobra.Command) error {
// TODO: deferred panic recovery
ctx = telemetry.WithNewLogger(ctx)
ctx = dbr.DetectRuntime(ctx)
start := time.Now()
startTime := time.Now()
// Run the command
cmd, err := cmd.ExecuteContextC(ctx)
@ -134,14 +134,12 @@ func Execute(ctx context.Context, cmd *cobra.Command) error {
)
}
}
end := time.Now()
exitCode := 0
if err != nil {
exitCode = 1
}
uploadTelemetry(cmd.Context(), commandString(cmd), start, end, exitCode)
uploadTelemetry(cmd.Context(), commandString(cmd), startTime, exitCode)
return err
}
@ -176,7 +174,7 @@ func inheritEnvVars() []string {
return out
}
func uploadTelemetry(ctx context.Context, cmdStr string, start, end time.Time, exitCode int) {
func uploadTelemetry(ctx context.Context, cmdStr string, startTime time.Time, exitCode int) {
// Nothing to upload.
if !telemetry.HasLogs(ctx) {
return
@ -193,7 +191,7 @@ func uploadTelemetry(ctx context.Context, cmdStr string, start, end time.Time, e
Command: cmdStr,
OperatingSystem: runtime.GOOS,
DbrVersion: env.Get(ctx, dbr.EnvVarName),
ExecutionTimeMs: end.Sub(start).Milliseconds(),
ExecutionTimeMs: time.Since(startTime).Milliseconds(),
ExitCode: int64(exitCode),
})