diff --git a/cmd/dagger/cmd/common/track.go b/cmd/dagger/cmd/common/track.go index af1227ad..ed0395eb 100644 --- a/cmd/dagger/cmd/common/track.go +++ b/cmd/dagger/cmd/common/track.go @@ -9,7 +9,6 @@ import ( "github.com/go-git/go-git/v5" "github.com/spf13/cobra" "go.dagger.io/dagger/pkg" - "go.dagger.io/dagger/plan" "go.dagger.io/dagger/telemetry" ) @@ -20,8 +19,21 @@ func TrackCommand(ctx context.Context, cmd *cobra.Command, props ...*telemetry.P Name: "command", Value: commandName(cmd), }, + { + // Hash the repository URL for privacy + Name: "git_repository_hash", + Value: hash(gitRepoURL(".")), + }, }, props...) + projectDir, found := pkg.GetCueModParent() + if found { + props = append(props, &telemetry.Property{ + Name: "project_path_hash", + Value: hash(projectDir), + }) + } + return telemetry.TrackAsync(ctx, "Command Executed", props...) } @@ -33,58 +45,6 @@ func commandName(cmd *cobra.Command) string { return strings.Join(parts, " ") } -// TrackPlanCommand sends telemetry about a plan execution -func TrackPlanCommand(ctx context.Context, cmd *cobra.Command, daggerplan plan.Plan, props ...*telemetry.Property) chan struct{} { - props = append([]*telemetry.Property{ - { - // Hash the repository URL for privacy - Name: "git_repository_hash", - Value: hash(gitRepoURL(pkg.GetCueModParent())), - }, - { - // The project path might contain the username (e.g. /home/user/project), so we hash it for privacy. - Name: "project_path_hash", - Value: hash(pkg.GetCueModParent()), - }, - }, props...) - - if action := daggerplan.Action(); action != nil { - props = append(props, &telemetry.Property{ - Name: "action", - Value: true, - }) - } - return TrackCommand(ctx, cmd, props...) -} - -// TrackProjectCommand is like TrackCommand but includes project and -// optionally environment metadata. -// func TrackProjectCommand(ctx context.Context, cmd *cobra.Command, w *state.Project, env *state.State, props ...*telemetry.Property) chan struct{} { -// props = append([]*telemetry.Property{ -// { -// // Hash the repository URL for privacy -// Name: "git_repository_hash", -// Value: hash(gitRepoURL(w.Path)), -// }, -// { -// // The project path might contain the username (e.g. /home/user/project), so we hash it for privacy. -// Name: "project_path_hash", -// Value: hash(w.Path), -// }, -// }, props...) - -// if env != nil { -// props = append([]*telemetry.Property{ -// { -// Name: "environment_name", -// Value: env.Name, -// }, -// }, props...) -// } - -// return TrackCommand(ctx, cmd, props...) -// } - // hash returns the sha256 digest of the string func hash(s string) string { return fmt.Sprintf("%x", sha256.Sum256([]byte(s))) diff --git a/cmd/dagger/cmd/do.go b/cmd/dagger/cmd/do.go index 8c2a52d5..d3922b66 100644 --- a/cmd/dagger/cmd/do.go +++ b/cmd/dagger/cmd/do.go @@ -15,6 +15,7 @@ import ( "go.dagger.io/dagger/cmd/dagger/logger" "go.dagger.io/dagger/plan" "go.dagger.io/dagger/solver" + "go.dagger.io/dagger/telemetry" "golang.org/x/term" ) @@ -60,15 +61,19 @@ var doCmd = &cobra.Command{ lg.Fatal().Err(err).Msg("failed to load plan") } + doneCh := common.TrackCommand(ctx, cmd, &telemetry.Property{ + Name: "action", + Value: p.Action().Path.String(), + }) + err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error { return p.Do(ctx, getTargetPath(args), s) }) - <-common.TrackPlanCommand(ctx, cmd, *p) - if err != nil { lg.Fatal().Err(err).Msg("failed to execute plan") } + <-doneCh }, } diff --git a/cmd/dagger/cmd/project/init.go b/cmd/dagger/cmd/project/init.go index 8f6bc233..dabae3d4 100644 --- a/cmd/dagger/cmd/project/init.go +++ b/cmd/dagger/cmd/project/init.go @@ -35,12 +35,14 @@ var initCmd = &cobra.Command{ name := viper.GetString("name") + doneCh := common.TrackCommand(ctx, cmd) + err := pkg.CueModInit(ctx, dir, name) if err != nil { lg.Fatal().Err(err).Msg("failed to initialize project") } - <-common.TrackCommand(ctx, cmd) + <-doneCh }, } diff --git a/cmd/dagger/cmd/project/update.go b/cmd/dagger/cmd/project/update.go index 89e37f83..45d40141 100644 --- a/cmd/dagger/cmd/project/update.go +++ b/cmd/dagger/cmd/project/update.go @@ -62,15 +62,16 @@ var updateCmd = &cobra.Command{ } } - if err != nil { - lg.Error().Err(err).Msg("error installing/updating packages") - } - - <-common.TrackCommand(ctx, cmd, &telemetry.Property{ + doneCh := common.TrackCommand(ctx, cmd, &telemetry.Property{ Name: "num_packages", Value: len(processedRequires), }) + if err != nil { + lg.Error().Err(err).Msg("error installing/updating packages") + } + + <-doneCh }, } diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index bff8452a..036182cb 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -51,8 +51,6 @@ var upCmd = &cobra.Command{ ctx := lg.WithContext(cmd.Context()) cl := common.NewClient(ctx) - // err = europaUp(ctx, cl, args...) - p, err := plan.Load(ctx, plan.Config{ Args: args, With: viper.GetStringSlice("with"), @@ -62,18 +60,18 @@ var upCmd = &cobra.Command{ lg.Fatal().Err(err).Msg("failed to load plan") } + doneCh := common.TrackCommand(ctx, cmd) + err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error { err := p.Do(ctx, cue.MakePath(), s) return err }) - // TODO: rework telemetry - <-common.TrackPlanCommand(ctx, cmd, *p) - if err != nil { lg.Fatal().Err(err).Msg("failed to up environment") } + <-doneCh }, }