Skip to content

Commit

Permalink
chore: Improve telemetry handling for config commands
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFaucherre committed Aug 1, 2023
1 parent 4837c99 commit 7f0184b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 3 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func newConfigCommand(globalConfig *settings.Config) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
defer closeTelemetryClient()
err := packConfig(args)
telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true)))
_ = telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err))
return err
},
Args: cobra.ExactArgs(1),
Expand Down Expand Up @@ -89,7 +89,7 @@ func newConfigCommand(globalConfig *settings.Config) *cobra.Command {
IgnoreDeprecatedImages: ignoreDeprecatedImages,
VerboseOutput: verboseOutput,
})
telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true)))
telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err))

return err
},
Expand Down Expand Up @@ -124,15 +124,14 @@ func newConfigCommand(globalConfig *settings.Config) *cobra.Command {
if len(args) == 1 {
path = args[0]
}
telemetryClient.Track(telemetry.CreateConfigEvent(getCommandInformation(cmd, true)))
response, err := compiler.ProcessConfig(config.ProcessConfigOpts{
ConfigPath: path,
OrgID: orgID,
OrgSlug: orgSlug,
PipelineParamsFilePath: pipelineParamsFilePath,
VerboseOutput: verboseOutput,
})
telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true)))
telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("Config", func() {
telemetry.CreateConfigEvent(telemetry.CommandInfo{
Name: "pack",
LocalArgs: map[string]string{"help": "false"},
}),
}, nil),
})
})
})
Expand Down
8 changes: 6 additions & 2 deletions telemetry/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ func CreateCompletionCommand(cmdInfo CommandInfo) Event {
return createEventFromCommandInfo("completion", cmdInfo)
}

func CreateConfigEvent(cmdInfo CommandInfo) Event {
return createEventFromCommandInfo("config", cmdInfo)
func CreateConfigEvent(cmdInfo CommandInfo, err error) Event {
event := createEventFromCommandInfo("config", cmdInfo)
if err != nil {
event.Properties["error"] = err.Error()
}
return event
}

func CreateLocalExecuteEvent(cmdInfo CommandInfo) Event {
Expand Down

0 comments on commit 7f0184b

Please sign in to comment.