Skip to content

Commit fe07d22

Browse files
chore(cli): update telemetry implementation and update docs page
1 parent 4d57616 commit fe07d22

File tree

19 files changed

+670
-544
lines changed

19 files changed

+670
-544
lines changed

cmd/root.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66
"os/exec"
7-
"runtime/debug"
87

98
"github.com/loft-sh/devpod/cmd/agent"
109
"github.com/loft-sh/devpod/cmd/context"
@@ -35,8 +34,6 @@ func NewRootCmd() *cobra.Command {
3534
SilenceUsage: true,
3635
SilenceErrors: true,
3736
PersistentPreRunE: func(cobraCmd *cobra.Command, args []string) error {
38-
telemetry.Collector.SetCLIData(cobraCmd, globalFlags)
39-
4037
if globalFlags.LogOutput == "json" {
4138
log2.Default.SetFormat(log2.JSONFormat)
4239
} else if globalFlags.LogOutput == "raw" {
@@ -57,6 +54,11 @@ func NewRootCmd() *cobra.Command {
5754
_ = os.Setenv(config.DEVPOD_HOME, globalFlags.DevPodHome)
5855
}
5956

57+
devPodConfig, err := config.LoadConfig(globalFlags.Context, globalFlags.Provider)
58+
if err == nil {
59+
telemetry.StartCLI(devPodConfig, cobraCmd)
60+
}
61+
6062
return nil
6163
},
6264
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
@@ -72,21 +74,13 @@ func NewRootCmd() *cobra.Command {
7274
// Execute adds all child commands to the root command and sets flags appropriately.
7375
// This is called by main.main(). It only needs to happen once to the rootCmd.
7476
func Execute() {
75-
defer func() {
76-
// recover from panic in order to log it via telemetry
77-
if err := recover(); err != nil {
78-
retErr := fmt.Errorf("panic: %v %s", err, debug.Stack())
79-
telemetry.Collector.RecordEndEvent(retErr)
80-
log2.Default.Fatal(retErr)
81-
}
82-
}()
83-
8477
// build the root command
8578
rootCmd := BuildRoot()
8679

8780
// execute command
8881
err := rootCmd.Execute()
89-
telemetry.Collector.RecordEndEvent(err)
82+
telemetry.CollectorCLI.RecordCLI(err)
83+
telemetry.CollectorCLI.Flush()
9084
if err != nil {
9185
//nolint:all
9286
if sshExitErr, ok := err.(*ssh.ExitError); ok {

cmd/up.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/loft-sh/devpod/pkg/port"
3636
provider2 "github.com/loft-sh/devpod/pkg/provider"
3737
devssh "github.com/loft-sh/devpod/pkg/ssh"
38+
"github.com/loft-sh/devpod/pkg/telemetry"
3839
"github.com/loft-sh/devpod/pkg/tunnel"
3940
"github.com/loft-sh/devpod/pkg/version"
4041
workspace2 "github.com/loft-sh/devpod/pkg/workspace"
@@ -86,6 +87,7 @@ func NewUpCmd(f *flags.GlobalFlags) *cobra.Command {
8687
if err != nil {
8788
return fmt.Errorf("prepare workspace client: %w", err)
8889
}
90+
telemetry.CollectorCLI.SetClient(client)
8991

9092
return cmd.Run(ctx, devPodConfig, client, logger)
9193
},

docs/pages/other-topics/telemetry.mdx

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,25 @@ Below you can find an example of the payload that DevPod CLI would send to our t
2323

2424
```yaml
2525
{
26-
"type":"cmdfinished", # type of event, another type is "cmdstarted"
2726
"event":{
27+
"type":"devpod_cli", # type of event
28+
"machine_id":"3ed2c7...ee308e6", # securely hashed machine ID to de-duplicate information received from the same user
2829
"timestamp":1683878643781772,
29-
"executionID":"23736e5...83b3d656a0", # random ID to de-duplicate information received via different event types
30-
"command":"devpod provider delete", # the CLI command that was executed
31-
"provider":"kubernetes", # the default provider
32-
"processingTime":71980, # how long it took for the command to execute
33-
"errors":"provider 'docker' does not exist"
30+
"properties": {
31+
"command":"devpod provider delete", # the CLI command that was executed
32+
"provider":"kubernetes", # the default provider
33+
"source_type":"git:", # the workspace source type (git, image, local, container, unknown)
34+
"ide":"vscode", # the IDE used to open a workspace
35+
"desktop":"true", # whether this cli command has been executed by DevPod Desktop or is a direct CLI invokation
36+
"version":"v0.5.29", # the CLI version
37+
"error":"provider 'docker' does not exist" # an error that occured during command execution
38+
}
3439
},
35-
"instanceProperties":{
36-
"uid":"3ed2c7...ee308e6", # securely hashed machine ID to de-duplicate information received from the same user
37-
"arch":"amd64", # CPU architecture
38-
"os":"linux", # Operating system
39-
"version":{ # DevPod CLI version
40-
"major":"0",
41-
"minor":"1",
42-
"patch":"0"
43-
},
44-
"flags":{
45-
"setFlags":[ # List of flags(names only) that were set
46-
"debug"
47-
]
48-
},
49-
"ui": false
40+
"user":{
41+
"machine_id":"3ed2c7...ee308e6", # securely hashed machine ID to de-duplicate information received from the same user
42+
"arch":"amd64", # CPU architecture
43+
"os":"linux", # Operating system
5044
},
51-
"token":"eyJhbG...coNz80" # Token generated from the static key included in the CLI binary. It is used to validate payload integrity.
5245
}
5346
```
5447

@@ -58,4 +51,4 @@ To disable the telemetry execute the following command:
5851

5952
```bash
6053
devpod context set-options -o TELEMETRY=false
61-
```
54+
```

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ require (
155155
github.com/kylelemons/godebug v1.1.0 // indirect
156156
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
157157
github.com/loft-sh/admin-apis v0.0.0-20241127134028-9cfb6b23ec44 // indirect
158+
github.com/loft-sh/analytics-client v0.0.0-20240219162240-2f4c64b2494e // indirect
158159
github.com/loft-sh/apiserver v0.0.0-20241008120650-f17d504a4d0d // indirect
159160
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
160161
github.com/mailru/easyjson v0.7.7 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ github.com/loft-sh/admin-apis v0.0.0-20241127134028-9cfb6b23ec44 h1:Sq6qEsKSiZHY
352352
github.com/loft-sh/admin-apis v0.0.0-20241127134028-9cfb6b23ec44/go.mod h1:MWczNwKvWssHo1KaeZKaWDdRLYSNbWqQBGsTLoCNd7U=
353353
github.com/loft-sh/agentapi/v4 v4.2.0-alpha.6 h1:eVIzaW+EvIygxNXl5163c1+WcUr8c95OP6lj8FcJHUc=
354354
github.com/loft-sh/agentapi/v4 v4.2.0-alpha.6/go.mod h1:yqbIMmyXqbzZcK0DlwldRLy0xb3lYnH4NoI3K+iETlM=
355+
github.com/loft-sh/analytics-client v0.0.0-20240219162240-2f4c64b2494e h1:JcPnMaoczikvpasi8OJ47dCkWZjfgFubWa4V2SZo7h0=
356+
github.com/loft-sh/analytics-client v0.0.0-20240219162240-2f4c64b2494e/go.mod h1:FFWcGASyM2QlWTDTCG/WBVM/XYr8btqYt335TFNRCFg=
355357
github.com/loft-sh/api/v4 v4.0.0-alpha.6.0.20241129074910-a24d4104d586 h1:nBLJCtuGQH0Cq4lkaUJsDqSUYueWT874YVuW66BQ9S0=
356358
github.com/loft-sh/api/v4 v4.0.0-alpha.6.0.20241129074910-a24d4104d586/go.mod h1:bPDJ1+vZBBEIoPgykfy+TzOwLHtTvWAbTSHexnj4tJA=
357359
github.com/loft-sh/apiserver v0.0.0-20241008120650-f17d504a4d0d h1:73wE8wtsnJm4bXtFbTDRG1EgN4LonpPdgzF3HFhP7kA=

pkg/config/config.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import (
99
"time"
1010

1111
"github.com/ghodss/yaml"
12-
"github.com/loft-sh/devpod/pkg/telemetry"
1312
"github.com/loft-sh/devpod/pkg/types"
14-
"github.com/loft-sh/devpod/pkg/version"
1513
"github.com/pkg/errors"
1614
)
1715

@@ -271,13 +269,6 @@ func LoadConfig(contextOverride string, providerOverride string) (*Config, error
271269

272270
config.Origin = configOrigin
273271

274-
// make sure to not send telemetry if disabled or in dev mode
275-
if config.ContextOption(ContextOptionTelemetry) != "false" && version.GetVersion() != version.DevVersion {
276-
go func() {
277-
telemetry.Collector.RecordStartEvent(config.Current().DefaultProvider)
278-
}()
279-
}
280-
281272
return config, nil
282273
}
283274

pkg/provider/workspace.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var (
1616
WorkspaceSourceLocal = "local:"
1717
WorkspaceSourceImage = "image:"
1818
WorkspaceSourceContainer = "container:"
19+
WorkspaceSourceUnknown = "unknown:"
1920
)
2021

2122
type Workspace struct {
@@ -262,6 +263,28 @@ func (w WorkspaceSource) String() string {
262263
return ""
263264
}
264265

266+
func (w WorkspaceSource) Type() string {
267+
if w.GitRepository != "" {
268+
if w.GitPRReference != "" {
269+
return WorkspaceSourceGit + "pr"
270+
} else if w.GitBranch != "" {
271+
return WorkspaceSourceGit + "branch"
272+
} else if w.GitCommit != "" {
273+
return WorkspaceSourceGit + "commit"
274+
}
275+
276+
return WorkspaceSourceGit
277+
} else if w.LocalFolder != "" {
278+
return WorkspaceSourceLocal
279+
} else if w.Image != "" {
280+
return WorkspaceSourceImage
281+
} else if w.Container != "" {
282+
return WorkspaceSourceContainer
283+
}
284+
285+
return WorkspaceSourceUnknown
286+
}
287+
265288
func ParseWorkspaceSource(source string) *WorkspaceSource {
266289
if strings.HasPrefix(source, WorkspaceSourceGit) {
267290
gitRepo, gitPRReference, gitBranch, gitCommit, gitSubdir := git.NormalizeRepository(strings.TrimPrefix(source, WorkspaceSourceGit))

0 commit comments

Comments
 (0)