Skip to content

Commit

Permalink
add network to relevant cmd (#140)
Browse files Browse the repository at this point in the history
* add network to relevant cmd

* clean
  • Loading branch information
shrimalmadhur authored Jun 7, 2024
1 parent ff355f4 commit 49e93cb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/operator/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 18 additions & 4 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"os"
"os/user"
"runtime"
"strconv"

"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"

"github.com/posthog/posthog-go"

Expand All @@ -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
}
Expand All @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 49e93cb

Please sign in to comment.