Skip to content

Commit

Permalink
add basic telemetry (#134)
Browse files Browse the repository at this point in the history
* add basic telemetry

* add version

* add way to disable telemtry

* add commit

* fix main version ldflag
  • Loading branch information
shrimalmadhur committed May 29, 2024
1 parent dde52bb commit 0c636eb
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ jobs:
workdir: ./eigenlayer-cli/
env:
#https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TELEMETRY_TOKEN: ${{ secrets.TELEMETRY_TOKEN }}
4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ builds:
binary: eigenlayer
flags:
- -v
ldflags:
- -X 'main.version={{.Version}}'
- -X 'github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry.telemetryToken={{ .Env.TELEMETRY_TOKEN }}'
- -X 'github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry.version={{.Version}}'
# windows is ignored by default, as the `goos` field by default only
# contains linux and darwin
goos:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ To download the binary in a custom location, run:
```bash
curl -sSfL https://raw.githubusercontent.com/layr-labs/eigenlayer-cli/master/scripts/install.sh | sh -s -- -b <custom_location>
```
We collect anonymous usage data to improve the CLI. To disable telemetry, set the environment variable `EIGENLAYER_CLI_TELEMETRY_ENABLED` to `false`.

## Install `eigenlayer` CLI using Go

Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ go 1.21

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Layr-Labs/eigensdk-go v0.1.7-0.20240506234104-06805a99d717
github.com/ethereum/go-ethereum v1.14.0
github.com/fatih/color v1.13.0
github.com/Layr-Labs/eigensdk-go v0.1.7
github.com/ethereum/go-ethereum v1.14.3
github.com/fatih/color v1.17.0
github.com/posthog/posthog-go v0.0.0-20240327112532-87b23fe11103
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.2
github.com/wagslane/go-password-validator v0.3.0
Expand Down Expand Up @@ -54,7 +55,7 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lmittmann/tint v1.0.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
24 changes: 10 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Layr-Labs/eigensdk-go v0.1.7-0.20240506234104-06805a99d717 h1:ENsHUr1mrCu+2z15YPlMFbCBNTcYH10ftKIANCgzJ+U=
github.com/Layr-Labs/eigensdk-go v0.1.7-0.20240506234104-06805a99d717/go.mod h1:OF9lmS/57MKxS0xpSpX0qHZl0SKkDRpvJIvsGvMN1y8=
github.com/Layr-Labs/eigensdk-go v0.1.7 h1:2qC3Wl2gKw/mJJfESeXTH7bKoHWqQCFz6qKO3Ny7TDI=
github.com/Layr-Labs/eigensdk-go v0.1.7/go.mod h1:OF9lmS/57MKxS0xpSpX0qHZl0SKkDRpvJIvsGvMN1y8=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
Expand Down Expand Up @@ -109,10 +109,10 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.14.0 h1:xRWC5NlB6g1x7vNy4HDBLuqVNbtLrc7v8S6+Uxim1LU=
github.com/ethereum/go-ethereum v1.14.0/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/ethereum/go-ethereum v1.14.3 h1:5zvnAqLtnCZrU9uod1JCvHWJbPMURzYFHfc2eHz4PHA=
github.com/ethereum/go-ethereum v1.14.3/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA=
Expand Down Expand Up @@ -186,15 +186,12 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
Expand Down Expand Up @@ -226,6 +223,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posthog/posthog-go v0.0.0-20240327112532-87b23fe11103 h1:YEWdfKVtz5Db85b8RLIZ1IY3PLSB1fW49hvK2yIL6JU=
github.com/posthog/posthog-go v0.0.0-20240327112532-87b23fe11103/go.mod h1:QjlpryJtfYLrZF2GUkAhejH4E7WlDbdKkvOi5hLmkdg=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
Expand Down Expand Up @@ -314,11 +313,8 @@ golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"math/big"
"os"

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

"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
eigensdkTypes "github.com/Layr-Labs/eigensdk-go/types"
Expand All @@ -30,6 +32,7 @@ func CreateCmd(p utils.Prompter) *cli.Command {
Flags: []cli.Flag{
&YesFlag,
},
After: telemetry.AfterRunAction(),
Action: func(ctx *cli.Context) error {
skipPrompt := ctx.Bool(YesFlag.Name)

Expand Down
4 changes: 3 additions & 1 deletion pkg/operator/keys/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"regexp"
"strings"

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

"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
sdkEcdsa "github.com/Layr-Labs/eigensdk-go/crypto/ecdsa"
Expand Down Expand Up @@ -53,7 +55,7 @@ This command will create keys in $HOME/.eigenlayer/operator_keys/ location
&KeyTypeFlag,
&InsecureFlag,
},

After: telemetry.AfterRunAction(),
Action: func(ctx *cli.Context) error {
args := ctx.Args()
if args.Len() != 1 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/keys/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"path/filepath"

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

"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/crypto/ecdsa"
Expand Down Expand Up @@ -40,6 +42,7 @@ But if you want it to export from a different location, use --key-path flag`,
&KeyTypeFlag,
&KeyPathFlag,
},
After: telemetry.AfterRunAction(),
Action: func(c *cli.Context) error {
keyType := c.String(KeyTypeFlag.Name)

Expand Down
4 changes: 3 additions & 1 deletion pkg/operator/keys/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"regexp"
"strings"

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

"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -38,7 +40,7 @@ This command will import keys in $HOME/.eigenlayer/operator_keys/ location
&KeyTypeFlag,
&InsecureFlag,
},

After: telemetry.AfterRunAction(),
Action: func(ctx *cli.Context) error {
args := ctx.Args()
if args.Len() != 2 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/keys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"path/filepath"
"strings"

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

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/urfave/cli/v2"
)
Expand All @@ -22,6 +24,7 @@ This command will list both ecdsa and bls key created using create command
It will only list keys created in the default folder (./operator_keys/)
`,
After: telemetry.AfterRunAction(),
Action: func(context *cli.Context) error {
homePath, err := os.UserHomeDir()
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/operator/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/Layr-Labs/eigensdk-go/aws/secretmanager"

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

Expand All @@ -22,7 +23,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
eigensdkLogger "github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/metrics"
eigenMetrics "github.com/Layr-Labs/eigensdk-go/metrics"
"github.com/Layr-Labs/eigensdk-go/signerv2"
eigensdkTypes "github.com/Layr-Labs/eigensdk-go/types"
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"
Expand All @@ -44,6 +45,7 @@ func RegisterCmd(p utils.Prompter) *cli.Command {
This will register operator to DelegationManager
`,
After: telemetry.AfterRunAction(),
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Len() != 1 {
Expand Down Expand Up @@ -80,7 +82,7 @@ func RegisterCmd(p utils.Prompter) *cli.Command {

txMgr := txmgr.NewSimpleTxManager(keyWallet, ethClient, logger, sender)

noopMetrics := metrics.NewNoopMetrics()
noopMetrics := eigenMetrics.NewNoopMetrics()

elWriter, err := elContracts.BuildELChainWriter(
common.HexToAddress(operatorCfg.ELDelegationManagerAddress),
Expand Down
10 changes: 7 additions & 3 deletions pkg/operator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"context"
"fmt"

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

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
eigensdkLogger "github.com/Layr-Labs/eigensdk-go/logging"
eigensdkTypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/ethereum/go-ethereum/common"

"github.com/urfave/cli/v2"
)

Expand All @@ -21,10 +24,11 @@ func StatusCmd(p utils.Prompter) *cli.Command {
Usage: "Check if the operator is registered and get the operator details",
UsageText: "status <configuration-file>",
Description: `
Check the registration status of operator to Eigenlayer.
Check the registration status of operator to EigenLayer.
It expects the same configuration yaml file as argument to register command
`,
After: telemetry.AfterRunAction(),
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Len() != 1 {
Expand Down
6 changes: 4 additions & 2 deletions pkg/operator/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"fmt"

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

elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
eigensdkLogger "github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/metrics"
eigenMetrics "github.com/Layr-Labs/eigensdk-go/metrics"

"github.com/ethereum/go-ethereum/common"

Expand All @@ -31,6 +32,7 @@ func UpdateCmd(p utils.Prompter) *cli.Command {
Requires the same file used for registration as argument
`,
After: telemetry.AfterRunAction(),
Action: func(cCtx *cli.Context) error {
args := cCtx.Args()
if args.Len() != 1 {
Expand Down Expand Up @@ -66,7 +68,7 @@ func UpdateCmd(p utils.Prompter) *cli.Command {

txMgr := txmgr.NewSimpleTxManager(keyWallet, ethClient, logger, sender)

noopMetrics := metrics.NewNoopMetrics()
noopMetrics := eigenMetrics.NewNoopMetrics()

elWriter, err := elContracts.BuildELChainWriter(
common.HexToAddress(operatorCfg.ELDelegationManagerAddress),
Expand Down
63 changes: 63 additions & 0 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package telemetry

import (
"crypto/sha256"
"encoding/base64"
"fmt"
"os"
"os/user"
"runtime"

"github.com/posthog/posthog-go"

"github.com/urfave/cli/v2"
)

const (
cliTelemetryEnabledKey = "EIGENLAYER_CLI_TELEMETRY_ENABLED"
)

// telemetryToken value is set at build and install scripts using ldflags
// version value is set at build scripts using ldflags
var (
telemetryToken = ""
telemetryInstance = "https://us.i.posthog.com"
version = "development"
)

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)
}
return nil
}
}

func IsTelemetryEnabled() bool {
telemetryEnabled := os.Getenv(cliTelemetryEnabledKey)
return len(telemetryEnabled) == 0 || telemetryEnabled == "true"
}

func HandleTacking(commandPath string) {
if telemetryToken == "" {
return
}
client, _ := posthog.NewWithConfig(telemetryToken, posthog.Config{Endpoint: telemetryInstance})
defer client.Close()

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[:])
telemetryProperties := make(map[string]interface{})
telemetryProperties["command"] = commandPath
telemetryProperties["version"] = version
telemetryProperties["os"] = runtime.GOOS
_ = client.Enqueue(posthog.Capture{
DistinctId: userID,
Event: "eigenlayer-cli",
Properties: telemetryProperties,
})
}
1 change: 1 addition & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ execute() {
fi
install "${tmpdir}/${binexe}" "${BINDIR}/"
log_info "installed ${BINDIR}/${binexe}"
log_info "Telemetry is enabled by default. To disable it, set the EIGENLAYER_CLI_TELEMETRY_ENABLED environment variable to false."
done
rm -rf "${tmpdir}"
}
Expand Down

0 comments on commit 0c636eb

Please sign in to comment.