databricks-cli/cmd/telemetry/upload.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
909 B
Go
Raw Permalink Normal View History

2025-03-05 12:43:46 +00:00
package telemetry
import (
"encoding/json"
"os"
2025-03-05 12:56:16 +00:00
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/log"
2025-03-05 12:43:46 +00:00
"github.com/databricks/cli/libs/telemetry"
"github.com/spf13/cobra"
)
func newTelemetryUpload() *cobra.Command {
return &cobra.Command{
Use: "upload",
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
// We exit the process explicitly at the end of Run to avoid the possibility
// of the worker being spawned recursively. This could otherwise happen if
// say telemetry was logged as part of this command.
defer os.Exit(0)
resp, err := telemetry.Upload(ctx)
if err != nil {
2025-03-05 12:56:16 +00:00
log.Error(ctx, err.Error())
2025-03-05 12:43:46 +00:00
os.Exit(1)
}
2025-03-05 12:56:16 +00:00
cmdio.LogString(ctx, "Telemetry logs uploaded successfully")
cmdio.LogString(ctx, "Response:")
2025-03-05 12:43:46 +00:00
b, err := json.Marshal(resp)
if err == nil {
2025-03-05 12:56:16 +00:00
cmdio.LogString(ctx, string(b))
2025-03-05 12:43:46 +00:00
}
},
}
}