Skip to content

Commit a1af823

Browse files
authored
Add packages info in telemetry to get better understanding (#333)
## Summary Add packages info in telemetry to get better understanding. Note that different command behaves differently: - for devbox shell, run, and add command, path can be set via --config - for devbox init. path is set via args ## How was it tested? go build devbox shell
1 parent 3ead8cd commit a1af823

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

boxcli/args.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
package boxcli
55

66
import (
7-
"fmt"
87
"path/filepath"
98

10-
"github.com/fatih/color"
119
"github.com/pkg/errors"
1210
"go.jetpack.io/devbox/boxcli/usererr"
1311
)
@@ -30,12 +28,13 @@ func configPathFromUser(args []string, flags *configFlags) (string, error) {
3028
}
3129

3230
if len(args) > 0 {
33-
fmt.Printf(
34-
"%s devbox <command> <path> is deprecated, use devbox <command> --config <path> instead\n",
35-
color.HiYellowString("Warning:"),
31+
return "", usererr.New(
32+
"devbox <command> <path> is deprecated, use devbox <command> --config <path> instead.",
3633
)
3734
}
38-
return pathArg(args), nil
35+
36+
// current directory is ""
37+
return "", nil
3938
}
4039

4140
func pathArg(args []string) string {

boxcli/midcobra/telemetry.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/denisbrodbeck/machineid"
1616
segment "github.com/segmentio/analytics-go"
1717
"github.com/spf13/cobra"
18+
"go.jetpack.io/devbox"
1819
)
1920

2021
// We collect some light telemetry to be able to improve devbox over time.
@@ -85,6 +86,7 @@ func (m *telemetryMiddleware) postRun(cmd *cobra.Command, args []string, runErr
8586
DeviceID: deviceID(),
8687
Duration: time.Since(m.startTime),
8788
Failed: runErr != nil,
89+
Packages: getPackages(cmd),
8890
})
8991
}
9092

@@ -103,6 +105,26 @@ func getSubcommand(c *cobra.Command, args []string) (subcmd *cobra.Command, suba
103105
return subcmd, subargs, err
104106
}
105107

108+
func getPackages(c *cobra.Command) []string {
109+
configFlag := c.Flag("config")
110+
// for shell, run, and add command, path can be set via --config
111+
// if --config is not set, default to current directory which is ""
112+
// the only exception is the init command, for the path can be set with args
113+
// since after running init there will be no packages set in devbox.json
114+
// we can safely ignore this case.
115+
var path string
116+
if configFlag != nil {
117+
path = configFlag.Value.String()
118+
}
119+
120+
box, err := devbox.Open(path, os.Stdout)
121+
if err != nil {
122+
return []string{}
123+
}
124+
125+
return box.Config().Packages
126+
}
127+
106128
type event struct {
107129
AppName string
108130
AppVersion string
@@ -111,6 +133,7 @@ type event struct {
111133
DeviceID string
112134
Duration time.Duration
113135
Failed bool
136+
Packages []string
114137
}
115138

116139
func trackEvent(client segment.Client, evt *event) {
@@ -133,6 +156,7 @@ func trackEvent(client segment.Client, evt *event) {
133156
Set("command", evt.Command).
134157
Set("command_args", evt.CommandArgs).
135158
Set("failed", evt.Failed).
136-
Set("duration", evt.Duration.Milliseconds()),
159+
Set("duration", evt.Duration.Milliseconds()).
160+
Set("packages", evt.Packages),
137161
})
138162
}

devbox.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func (d *Devbox) ConfigDir() string {
8888
return d.configDir
8989
}
9090

91+
func (d *Devbox) Config() *Config {
92+
return d.cfg
93+
}
94+
9195
// Add adds a Nix package to the config so that it's available in the devbox
9296
// environment. It validates that the Nix package exists, but doesn't install
9397
// it. Adding a duplicate package is a no-op.

0 commit comments

Comments
 (0)