mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-11 10:46:25 +03:00
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:
parent
570f9622f1
commit
58d0a1e29f
@ -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()
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user