diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 4a512b107..e2acf8bbd 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -13,6 +13,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/afero" "github.com/spf13/cobra" + "github.com/spf13/pflag" "github.com/spf13/viper" "github.com/stripe/stripe-cli/pkg/cmd/resource" @@ -60,6 +61,13 @@ var rootCmd = &cobra.Command{ telemetryMetadata.SetCobraCommandContext(cmd) telemetryMetadata.SetMerchant(merchant) telemetryMetadata.SetUserAgent(useragent.GetEncodedUserAgent()) + + flags := []string{} + cmd.Flags().Visit(func(flag *pflag.Flag) { + flags = append(flags, flag.Name) + }) + flagsStr := strings.Join(flags, ",") + telemetryMetadata.SetCommandFlags(flagsStr) } // plugins send their own telemetry due to having richer context than the CLI does diff --git a/pkg/stripe/analytics_telemetry.go b/pkg/stripe/analytics_telemetry.go index fb2197efa..ba4c22a61 100644 --- a/pkg/stripe/analytics_telemetry.go +++ b/pkg/stripe/analytics_telemetry.go @@ -38,6 +38,7 @@ type CLIAnalyticsEventMetadata struct { InvocationID string `url:"invocation_id"` // The invocation id is unique to each context object and represents all events coming from one command / gRPC method call UserAgent string `url:"user_agent"` // the application that is used to create this request CommandPath string `url:"command_path"` // the command or gRPC method that initiated this request + CommandFlags string `url:"command_flags"` // Comma-separated list of flags that were passed to the command (only includes flag names, not their values) Merchant string `url:"merchant"` // the merchant ID: ex. acct_xxxx CLIVersion string `url:"cli_version"` // the version of the CLI OS string `url:"os"` // the OS of the system @@ -133,6 +134,11 @@ func (e *CLIAnalyticsEventMetadata) SetCommandPath(commandPath string) { e.CommandPath = commandPath } +// SetCommandFlags sets the flags on the CLIAnalyticsEventContext object +func (e *CLIAnalyticsEventMetadata) SetCommandFlags(commandFlags string) { + e.CommandFlags = commandFlags +} + // SendAPIRequestEvent is a special function for API requests func (a *AnalyticsTelemetryClient) SendAPIRequestEvent(ctx context.Context, requestID string, livemode bool) (*http.Response, error) { a.wg.Add(1)