From 49e93cb8110bf0d7a579b8a050ba8b39ddf79756 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Fri, 7 Jun 2024 10:48:26 -0700 Subject: [PATCH] add network to relevant cmd (#140) * add network to relevant cmd * clean --- pkg/operator/register.go | 1 + pkg/operator/status.go | 2 ++ pkg/operator/update.go | 1 + pkg/telemetry/telemetry.go | 22 ++++++++++++++++++---- pkg/utils/utils.go | 13 +++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/pkg/operator/register.go b/pkg/operator/register.go index da70d53..15e5b0e 100644 --- a/pkg/operator/register.go +++ b/pkg/operator/register.go @@ -57,6 +57,7 @@ func RegisterCmd(p utils.Prompter) *cli.Command { if err != nil { return err } + cCtx.App.Metadata["network"] = operatorCfg.ChainId.String() fmt.Printf( "\r%s Operator configuration file validated successfully %s\n", diff --git a/pkg/operator/status.go b/pkg/operator/status.go index a2004aa..0d9b4ac 100644 --- a/pkg/operator/status.go +++ b/pkg/operator/status.go @@ -40,6 +40,8 @@ func StatusCmd(p utils.Prompter) *cli.Command { if err != nil { return err } + cCtx.App.Metadata["network"] = operatorCfg.ChainId.String() + fmt.Printf( "%s Operator configuration file read successfully %s\n", utils.EmojiCheckMark, diff --git a/pkg/operator/update.go b/pkg/operator/update.go index f9ee7fa..b72b8fe 100644 --- a/pkg/operator/update.go +++ b/pkg/operator/update.go @@ -44,6 +44,7 @@ func UpdateCmd(p utils.Prompter) *cli.Command { if err != nil { return err } + cCtx.App.Metadata["network"] = operatorCfg.ChainId.String() fmt.Printf( "\r%s Operator configuration file validated successfully %s\n", diff --git a/pkg/telemetry/telemetry.go b/pkg/telemetry/telemetry.go index 328a57d..4a7f638 100644 --- a/pkg/telemetry/telemetry.go +++ b/pkg/telemetry/telemetry.go @@ -7,6 +7,9 @@ import ( "os" "os/user" "runtime" + "strconv" + + "github.com/Layr-Labs/eigenlayer-cli/pkg/utils" "github.com/posthog/posthog-go" @@ -27,10 +30,8 @@ var ( func AfterRunAction() cli.AfterFunc { return func(c *cli.Context) error { - // In v3, c.Command.FullName() can be used to get the full command name - // TODO(madhur): to update once v3 is released if IsTelemetryEnabled() { - HandleTacking(c.Command.HelpName) + HandleTacking(c) } return nil } @@ -41,20 +42,33 @@ func IsTelemetryEnabled() bool { return len(telemetryEnabled) == 0 || telemetryEnabled == "true" } -func HandleTacking(commandPath string) { +func HandleTacking(cCtx *cli.Context) { if telemetryToken == "" { return } client, _ := posthog.NewWithConfig(telemetryToken, posthog.Config{Endpoint: telemetryInstance}) defer client.Close() + // In v3, c.Command.FullName() can be used to get the full command name + // TODO(madhur): to update once v3 is released + commandPath := cCtx.Command.HelpName usr, _ := user.Current() // use empty string if err hash := sha256.Sum256([]byte(fmt.Sprintf("%s%s", usr.Username, usr.Uid))) userID := base64.StdEncoding.EncodeToString(hash[:]) + network := "unknown" + if chainIdVal, ok := cCtx.App.Metadata["network"]; ok { + chainIdInt, err := strconv.Atoi(chainIdVal.(string)) + // If this is an error just ignore it and continue + if err == nil { + network = utils.ChainIdToNetworkName(int64(chainIdInt)) + } + + } telemetryProperties := make(map[string]interface{}) telemetryProperties["command"] = commandPath telemetryProperties["version"] = version telemetryProperties["os"] = runtime.GOOS + telemetryProperties["network"] = network _ = client.Enqueue(posthog.Capture{ DistinctId: userID, Event: "eigenlayer-cli", diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 44f0524..b4a142b 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -33,6 +33,19 @@ var ChainMetadataMap = map[int64]types.ChainMetadata{ }, } +func ChainIdToNetworkName(chainId int64) string { + switch chainId { + case MainnetChainId: + return "mainnet" + case HoleskyChainId: + return "holesky" + case LocalChainId: + return "local" + default: + return "unknown" + } +} + func ReadYamlConfig(path string, o interface{}) error { if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) { log.Fatal("Path ", path, " does not exist")