cli: send error to telemetry

closes https://github.com/hasura/graphql-engine-mono/issues/2093

Problem:
 - [x] Send errors to telemetry
 - [x] send flags along with the command to telemetry

Solution:
 - Added Error field in the data struct and if there is an error then the error will get copied to the field
 - Use Visit fn in cobra for getting the flag names which are set and append the flag-names to command

https://github.com/hasura/graphql-engine-mono/pull/2298

GitOrigin-RevId: bd28c2e83e039a4eb8d7fe0d2b7646d0c982c91b
This commit is contained in:
Kali Vara Purushotham Santhati 2021-09-08 14:26:00 +05:30 committed by hasura-bot
parent 570f9622f1
commit 58d0a1e29f
2 changed files with 14 additions and 1 deletions

View File

@ -6,12 +6,14 @@ import (
"fmt"
"io"
"os"
"strings"
"github.com/hasura/graphql-engine/cli/v2"
"github.com/hasura/graphql-engine/cli/v2/update"
"github.com/hasura/graphql-engine/cli/v2/version"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
const hasuraASCIIText = `
@ -121,8 +123,16 @@ func Execute() error {
execCmd, err := NewDefaultHasuraCommand().ExecuteC()
if err != nil {
ec.Telemetry.IsError = true
ec.Telemetry.Error = err
}
ec.Telemetry.Command = execCmd.CommandPath()
commandPath := execCmd.CommandPath()
command := []string{commandPath}
getFlagName := func(f *pflag.Flag) {
flagName := fmt.Sprintf("--%s", f.Name)
command = append(command, flagName)
}
execCmd.Flags().Visit(getFlagName)
ec.Telemetry.Command = strings.Join(command, " ")
ec.Telemetry.Beam()
if ec.Spinner != nil {
ec.Spinner.Stop()

View File

@ -51,6 +51,8 @@ type Data struct {
// Indicates whether the execution resulted in an error or not.
IsError bool `json:"is_error"`
Error error `json:"error"`
// Any additional payload information.
Payload map[string]interface{} `json:"payload"`
@ -70,6 +72,7 @@ func BuildEvent() *Data {
OSPlatform: runtime.GOOS,
OSArch: runtime.GOARCH,
CanBeam: true,
Error: nil,
}
}