diff --git a/chainio/clients/avsregistry/reader.go b/chainio/clients/avsregistry/reader.go index f4ba2156..980c16a0 100644 --- a/chainio/clients/avsregistry/reader.go +++ b/chainio/clients/avsregistry/reader.go @@ -17,6 +17,7 @@ import ( stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry" "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/telemetry" "github.com/Layr-Labs/eigensdk-go/types" "github.com/Layr-Labs/eigensdk-go/utils" ) @@ -50,6 +51,7 @@ func NewChainReader( ethClient eth.HttpBackend, ) *ChainReader { logger = logger.With(logging.ComponentKey, "avsregistry/ChainReader") + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.newchainreader") return &ChainReader{ blsApkRegistryAddr: blsApkRegistryAddr, @@ -68,6 +70,8 @@ func NewReaderFromConfig( client eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.newreaderfromconfig") + bindings, err := NewBindingsFromConfig(cfg, client, logger) if err != nil { return nil, err @@ -92,6 +96,8 @@ func BuildAvsRegistryChainReader( ethClient eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.buildavsregistrychainreader") + contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient) if err != nil { return nil, utils.WrapError("Failed to create contractRegistryCoordinator", err) @@ -127,6 +133,8 @@ func BuildAvsRegistryChainReader( } func (r *ChainReader) GetQuorumCount(opts *bind.CallOpts) (uint8, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getquorumcount") + if r.registryCoordinator == nil { return 0, errors.New("RegistryCoordinator contract not provided") } @@ -137,6 +145,8 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsAtCurrentBlock( opts *bind.CallOpts, quorumNumbers types.QuorumNums, ) ([][]opstateretriever.OperatorStateRetrieverOperator, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsatcurrentblock") + if opts.Context == nil { opts.Context = context.Background() } @@ -157,6 +167,8 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsAtBlock( quorumNumbers types.QuorumNums, blockNumber uint32, ) ([][]opstateretriever.OperatorStateRetrieverOperator, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsatblock") + if r.operatorStateRetriever == nil { return nil, errors.New("OperatorStateRetriever contract not provided") } @@ -176,6 +188,8 @@ func (r *ChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock( opts *bind.CallOpts, quorumNumbers types.QuorumNums, ) ([][]common.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatoraddrsinquorumsatcurrentblock") + if r.operatorStateRetriever == nil { return nil, errors.New("OperatorStateRetriever contract not provided") } @@ -216,6 +230,8 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsOfOperatorAtBlock( operatorId types.OperatorId, blockNumber uint32, ) (types.QuorumNums, [][]opstateretriever.OperatorStateRetrieverOperator, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsofoperatoratblock") + if r.operatorStateRetriever == nil { return nil, nil, errors.New("OperatorStateRetriever contract not provided") } @@ -238,6 +254,9 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsOfOperatorAtCurrentBlock( opts *bind.CallOpts, operatorId types.OperatorId, ) (types.QuorumNums, [][]opstateretriever.OperatorStateRetrieverOperator, error) { + _ = telemetry.GetTelemetry(). + CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsofoperatoratcurrentblock") + if opts.Context == nil { opts.Context = context.Background() } @@ -261,6 +280,9 @@ func (r *ChainReader) GetOperatorStakeInQuorumsOfOperatorAtCurrentBlock( opts *bind.CallOpts, operatorId types.OperatorId, ) (map[types.QuorumNum]types.StakeAmount, error) { + _ = telemetry.GetTelemetry(). + CaptureEvent("avsregistry.chainreader.getoperatorstakeinquorumsofoperatoratcurrentblock") + if r.registryCoordinator == nil { return nil, errors.New("RegistryCoordinator contract not provided") } @@ -309,6 +331,8 @@ func (r *ChainReader) GetCheckSignaturesIndices( quorumNumbers types.QuorumNums, nonSignerOperatorIds []types.OperatorId, ) (opstateretriever.OperatorStateRetrieverCheckSignaturesIndices, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getchecksignaturesindices") + if r.operatorStateRetriever == nil { return opstateretriever.OperatorStateRetrieverCheckSignaturesIndices{}, errors.New( "OperatorStateRetriever contract not provided", @@ -339,6 +363,8 @@ func (r *ChainReader) GetOperatorId( opts *bind.CallOpts, operatorAddress common.Address, ) ([32]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorid") + if r.registryCoordinator == nil { return [32]byte{}, errors.New("RegistryCoordinator contract not provided") } @@ -357,6 +383,8 @@ func (r *ChainReader) GetOperatorFromId( opts *bind.CallOpts, operatorId types.OperatorId, ) (common.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorfromid") + if r.registryCoordinator == nil { return common.Address{}, errors.New("RegistryCoordinator contract not provided") } @@ -375,6 +403,8 @@ func (r *ChainReader) QueryRegistrationDetail( opts *bind.CallOpts, operatorAddress common.Address, ) ([]bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.queryregistrationdetail") + operatorId, err := r.GetOperatorId(opts, operatorAddress) if err != nil { return nil, utils.WrapError("Failed to get operator id", err) @@ -404,6 +434,8 @@ func (r *ChainReader) IsOperatorRegistered( opts *bind.CallOpts, operatorAddress common.Address, ) (bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.isoperatorregistered") + if r.registryCoordinator == nil { return false, errors.New("RegistryCoordinator contract not provided") } @@ -424,6 +456,8 @@ func (r *ChainReader) QueryExistingRegisteredOperatorPubKeys( stopBlock *big.Int, blockRange *big.Int, ) ([]types.OperatorAddr, []types.OperatorPubkeys, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.queryexistingregisteredoperatorpubkeys") + blsApkRegistryAbi, err := apkreg.ContractBLSApkRegistryMetaData.GetAbi() if err != nil { return nil, nil, utils.WrapError("Cannot get Abi", err) @@ -523,6 +557,8 @@ func (r *ChainReader) QueryExistingRegisteredOperatorSockets( stopBlock *big.Int, blockRange *big.Int, ) (map[types.OperatorId]types.Socket, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.queryexistingregisteredoperatorpubkeys") + if r.registryCoordinator == nil { return nil, errors.New("RegistryCoordinator contract not provided") } diff --git a/chainio/clients/avsregistry/subscriber.go b/chainio/clients/avsregistry/subscriber.go index 70d188b7..5b477244 100644 --- a/chainio/clients/avsregistry/subscriber.go +++ b/chainio/clients/avsregistry/subscriber.go @@ -9,6 +9,7 @@ import ( blsapkreg "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSApkRegistry" regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/telemetry" "github.com/Layr-Labs/eigensdk-go/utils" ) @@ -25,6 +26,8 @@ func NewChainSubscriber( blsApkRegistry blsapkreg.ContractBLSApkRegistryFilters, logger logging.Logger, ) *ChainSubscriber { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.newchainsubscriber") + logger = logger.With(logging.ComponentKey, "avsregistry/ChainSubscriber") return &ChainSubscriber{ @@ -41,6 +44,8 @@ func BuildAvsRegistryChainSubscriber( ethWsClient eth.WsBackend, logger logging.Logger, ) (*ChainSubscriber, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.newchainsubscriber") + regCoord, err := regcoord.NewContractRegistryCoordinator(regCoordAddr, ethWsClient) if err != nil { return nil, utils.WrapError("Failed to create RegistryCoordinator contract", err) @@ -63,6 +68,8 @@ func NewSubscriberFromConfig( wsClient eth.WsBackend, logger logging.Logger, ) (*ChainSubscriber, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.newsubscriberFromConfig") + bindings, err := NewBindingsFromConfig(cfg, wsClient, logger) if err != nil { return nil, err @@ -72,6 +79,8 @@ func NewSubscriberFromConfig( } func (s *ChainSubscriber) SubscribeToNewPubkeyRegistrations() (chan *blsapkreg.ContractBLSApkRegistryNewPubkeyRegistration, event.Subscription, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.subscribetonewpubkeyregistrations") + newPubkeyRegistrationChan := make(chan *blsapkreg.ContractBLSApkRegistryNewPubkeyRegistration) sub, err := s.blsApkRegistry.WatchNewPubkeyRegistration( &bind.WatchOpts{}, newPubkeyRegistrationChan, nil, @@ -83,6 +92,8 @@ func (s *ChainSubscriber) SubscribeToNewPubkeyRegistrations() (chan *blsapkreg.C } func (s *ChainSubscriber) SubscribeToOperatorSocketUpdates() (chan *regcoord.ContractRegistryCoordinatorOperatorSocketUpdate, event.Subscription, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.subscribetooperatorsocketupdates") + operatorSocketUpdateChan := make(chan *regcoord.ContractRegistryCoordinatorOperatorSocketUpdate) sub, err := s.regCoord.WatchOperatorSocketUpdate( &bind.WatchOpts{}, operatorSocketUpdateChan, nil, diff --git a/chainio/clients/avsregistry/writer.go b/chainio/clients/avsregistry/writer.go index 8f54834e..472b77b8 100644 --- a/chainio/clients/avsregistry/writer.go +++ b/chainio/clients/avsregistry/writer.go @@ -23,6 +23,7 @@ import ( stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry" "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/telemetry" "github.com/Layr-Labs/eigensdk-go/types" "github.com/Layr-Labs/eigensdk-go/utils" ) @@ -60,6 +61,8 @@ func NewChainWriter( ethClient eth.HttpBackend, txMgr txmgr.TxManager, ) *ChainWriter { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.newchainwriter") + logger = logger.With(logging.ComponentKey, "avsregistry/ChainWriter") return &ChainWriter{ @@ -84,6 +87,8 @@ func BuildAvsRegistryChainWriter( ethClient eth.HttpBackend, txMgr txmgr.TxManager, ) (*ChainWriter, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.buildavsregistrychainwriter") + registryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient) if err != nil { return nil, utils.WrapError("Failed to create RegistryCoordinator contract", err) @@ -151,6 +156,8 @@ func NewWriterFromConfig( txMgr txmgr.TxManager, logger logging.Logger, ) (*ChainWriter, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.newwriterfromconfig") + bindings, err := NewBindingsFromConfig(cfg, client, logger) if err != nil { return nil, err @@ -203,6 +210,9 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator( socket string, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry(). + CaptureEvent("avsregistry.chainwriter.registeroperatorinquorumwithavsregistrycoordinator") + operatorAddr := crypto.PubkeyToAddress(operatorEcdsaPrivateKey.PublicKey) w.logger.Info( "registering operator with the AVS's registry coordinator", @@ -305,6 +315,8 @@ func (w *ChainWriter) RegisterOperator( socket string, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.registeroperator") + operatorAddr := crypto.PubkeyToAddress(operatorEcdsaPrivateKey.PublicKey) w.logger.Info( "registering operator with the AVS's registry coordinator", @@ -423,6 +435,8 @@ func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums( quorumNumbers types.QuorumNums, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.updatestakesofentireoperatorsetforquorums") + w.logger.Info("updating stakes for entire operator set", "quorumNumbers", quorumNumbers) noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { @@ -456,6 +470,8 @@ func (w *ChainWriter) UpdateStakesOfOperatorSubsetForAllQuorums( operators []gethcommon.Address, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.updatestakesofoperatorsubsetforallquorums") + w.logger.Info("updating stakes of operator subset for all quorums", "operators", operators) noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { @@ -485,6 +501,8 @@ func (w *ChainWriter) DeregisterOperator( pubkey regcoord.BN254G1Point, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.deregisteroperator") + w.logger.Info("deregistering operator with the AVS's registry coordinator") noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { @@ -541,6 +559,8 @@ func (w *ChainWriter) UpdateSocket( socket types.Socket, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.updatesocket") + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, err diff --git a/chainio/clients/elcontracts/builder.go b/chainio/clients/elcontracts/builder.go index fb88b20c..d4ca706e 100644 --- a/chainio/clients/elcontracts/builder.go +++ b/chainio/clients/elcontracts/builder.go @@ -5,6 +5,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/metrics" + "github.com/Layr-Labs/eigensdk-go/telemetry" ) // Returns a tuple of reader clients with the given: @@ -15,6 +16,8 @@ func BuildReadClients( logger logging.Logger, eigenMetrics *metrics.EigenMetrics, ) (*ChainReader, *ContractBindings, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.builder.buildreadclients") + elContractBindings, err := NewBindingsFromConfig( config, client, @@ -45,6 +48,8 @@ func BuildClients( logger logging.Logger, eigenMetrics *metrics.EigenMetrics, ) (*ChainReader, *ChainWriter, *ContractBindings, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.builder.buildclients") + elContractBindings, err := NewBindingsFromConfig( config, client, diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index fdc608e3..f6e2d7e7 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -18,6 +18,7 @@ import ( permissioncontroller "github.com/Layr-Labs/eigensdk-go/contracts/bindings/PermissionController" strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/telemetry" "github.com/Layr-Labs/eigensdk-go/types" "github.com/Layr-Labs/eigensdk-go/utils" ) @@ -53,6 +54,7 @@ func NewChainReader( ethClient eth.HttpBackend, ) *ChainReader { logger = logger.With(logging.ComponentKey, "elcontracts/reader") + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.newchainreader") return &ChainReader{ delegationManager: delegationManager, @@ -74,6 +76,8 @@ func BuildELChainReader( ethClient eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.buildelchainreader") + elContractBindings, err := NewEigenlayerContractBindings( delegationManagerAddr, avsDirectoryAddr, @@ -100,6 +104,8 @@ func NewReaderFromConfig( ethClient eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.newreaderfromconfig") + elContractBindings, err := NewBindingsFromConfig( cfg, ethClient, @@ -124,6 +130,8 @@ func (r *ChainReader) IsOperatorRegistered( ctx context.Context, operator types.Operator, ) (bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.isoperatorregistered") + if r.delegationManager == nil { return false, errors.New("DelegationManager contract not provided") } @@ -145,6 +153,7 @@ func (r *ChainReader) GetStakerShares( ctx context.Context, stakerAddress gethcommon.Address, ) ([]gethcommon.Address, []*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getstakershares") return r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress) } @@ -154,6 +163,7 @@ func (r *ChainReader) GetDelegatedOperator( stakerAddress gethcommon.Address, blockNumber *big.Int, ) (gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getdelegatedoperator") return r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress) } @@ -161,6 +171,8 @@ func (r *ChainReader) GetOperatorDetails( ctx context.Context, operator types.Operator, ) (types.Operator, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatordetails") + if r.delegationManager == nil { return types.Operator{}, errors.New("DelegationManager contract not provided") } @@ -202,6 +214,8 @@ func (r *ChainReader) GetStrategyAndUnderlyingToken( ctx context.Context, strategyAddr gethcommon.Address, ) (*strategy.ContractIStrategy, gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getstrategyandunderlyingtoken") + contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) if err != nil { return nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err) @@ -219,6 +233,8 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( ctx context.Context, strategyAddr gethcommon.Address, ) (*strategy.ContractIStrategy, erc20.ContractIERC20Methods, gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getstrategyandunderlyingerc20token") + contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) if err != nil { return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err) @@ -239,6 +255,8 @@ func (r *ChainReader) GetOperatorSharesInStrategy( operatorAddr gethcommon.Address, strategyAddr gethcommon.Address, ) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatorsharesinstrategy") + if r.delegationManager == nil { return &big.Int{}, errors.New("DelegationManager contract not provided") } @@ -258,6 +276,8 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( approverSalt [32]byte, expiry *big.Int, ) ([32]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.calculatedelegationapprovaldigesthash") + if r.delegationManager == nil { return [32]byte{}, errors.New("DelegationManager contract not provided") } @@ -279,6 +299,8 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( salt [32]byte, expiry *big.Int, ) ([32]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.calculateoperatoravsregistrationdigesthash") + if r.avsDirectory == nil { return [32]byte{}, errors.New("AVSDirectory contract not provided") } @@ -293,6 +315,8 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( } func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getdistributionrootslength") + if r.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } @@ -301,6 +325,8 @@ func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, } func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.currrewardscalculationendtimestamp") + if r.rewardsCoordinator == nil { return 0, errors.New("RewardsCoordinator contract not provided") } @@ -311,6 +337,7 @@ func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (u func (r *ChainReader) GetCurrentClaimableDistributionRoot( ctx context.Context, ) (rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getcurrentclaimabledistributionroot") if r.rewardsCoordinator == nil { return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, errors.New( "RewardsCoordinator contract not provided", @@ -324,6 +351,8 @@ func (r *ChainReader) GetRootIndexFromHash( ctx context.Context, rootHash [32]byte, ) (uint32, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getrootindexfromhash") + if r.rewardsCoordinator == nil { return 0, errors.New("RewardsCoordinator contract not provided") } @@ -336,6 +365,8 @@ func (r *ChainReader) GetCumulativeClaimed( earner gethcommon.Address, token gethcommon.Address, ) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getcumulativeclaimed") + if r.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } @@ -347,6 +378,8 @@ func (r *ChainReader) CheckClaim( ctx context.Context, claim rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim, ) (bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.checkclaim") + if r.rewardsCoordinator == nil { return false, errors.New("RewardsCoordinator contract not provided") } @@ -359,6 +392,8 @@ func (r *ChainReader) GetOperatorAVSSplit( operator gethcommon.Address, avs gethcommon.Address, ) (uint16, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatoravssplit") + if r.rewardsCoordinator == nil { return 0, errors.New("RewardsCoordinator contract not provided") } @@ -376,6 +411,8 @@ func (r *ChainReader) GetOperatorPISplit( ctx context.Context, operator gethcommon.Address, ) (uint16, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatorpisplit") + if r.rewardsCoordinator == nil { return 0, errors.New("RewardsCoordinator contract not provided") } @@ -394,6 +431,8 @@ func (r *ChainReader) GetAllocatableMagnitude( operatorAddress gethcommon.Address, strategyAddress gethcommon.Address, ) (uint64, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getallocatablemagnitude") + if r.allocationManager == nil { return 0, errors.New("AllocationManager contract not provided") } @@ -406,6 +445,8 @@ func (r *ChainReader) GetMaxMagnitudes( operatorAddress gethcommon.Address, strategyAddresses []gethcommon.Address, ) ([]uint64, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getmaxmagnitudes") + if r.allocationManager == nil { return []uint64{}, errors.New("AllocationManager contract not provided") } @@ -418,6 +459,8 @@ func (r *ChainReader) GetAllocationInfo( operatorAddress gethcommon.Address, strategyAddress gethcommon.Address, ) ([]AllocationInfo, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getallocationinfo") + if r.allocationManager == nil { return nil, errors.New("AllocationManager contract not provided") } @@ -450,6 +493,8 @@ func (r *ChainReader) GetOperatorShares( operatorAddress gethcommon.Address, strategyAddresses []gethcommon.Address, ) ([]*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatorshares") + if r.delegationManager == nil { return nil, errors.New("DelegationManager contract not provided") } @@ -464,6 +509,8 @@ func (r *ChainReader) GetOperatorsShares( operatorAddress []gethcommon.Address, strategyAddresses []gethcommon.Address, ) ([][]*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatorsshares") + if r.delegationManager == nil { return nil, errors.New("DelegationManager contract not provided") } @@ -476,6 +523,8 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( ctx context.Context, operatorAddress gethcommon.Address, ) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getnumoperatorsetsforoperator") + opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { return nil, err @@ -489,6 +538,8 @@ func (r *ChainReader) GetOperatorSetsForOperator( ctx context.Context, operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatorsetsforoperator") + // TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to // paginate? return r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) @@ -500,6 +551,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( operatorAddress gethcommon.Address, operatorSet allocationmanager.OperatorSet, ) (bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.isoperatorregisteredwithoperatorset") if operatorSet.Id == 0 { // this is an M2 AVS status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress) @@ -529,6 +581,8 @@ func (r *ChainReader) GetOperatorsForOperatorSet( ctx context.Context, operatorSet allocationmanager.OperatorSet, ) ([]gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getoperatorsforoperatorset") + if operatorSet.Id == 0 { return nil, errLegacyAVSsNotSupported } else { @@ -541,6 +595,8 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet( ctx context.Context, operatorSet allocationmanager.OperatorSet, ) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getnumoperatorsforoperatorset") + if operatorSet.Id == 0 { return nil, errLegacyAVSsNotSupported } else { @@ -554,6 +610,8 @@ func (r *ChainReader) GetStrategiesForOperatorSet( ctx context.Context, operatorSet allocationmanager.OperatorSet, ) ([]gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getstrategiesforoperatorset") + if operatorSet.Id == 0 { return nil, errLegacyAVSsNotSupported } else { @@ -567,6 +625,8 @@ func (r *ChainReader) GetSlashableShares( operatorSet allocationmanager.OperatorSet, strategies []gethcommon.Address, ) (map[gethcommon.Address]*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getslashableshares") + if r.allocationManager == nil { return nil, errors.New("AllocationManager contract not provided") } @@ -606,6 +666,8 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( ctx context.Context, operatorSets []allocationmanager.OperatorSet, ) ([]OperatorSetStakes, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getslashablesharesforoperatorsets") + currentBlock, err := r.ethClient.BlockNumber(ctx) if err != nil { return nil, err @@ -623,6 +685,8 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( operatorSets []allocationmanager.OperatorSet, futureBlock uint32, ) ([]OperatorSetStakes, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getslashablesharesforoperatorsetsbefore") + operatorSetStakes := make([]OperatorSetStakes, len(operatorSets)) for i, operatorSet := range operatorSets { operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet) @@ -664,6 +728,8 @@ func (r *ChainReader) GetAllocationDelay( ctx context.Context, operatorAddress gethcommon.Address, ) (uint32, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getallocationdelay") + if r.allocationManager == nil { return 0, errors.New("AllocationManager contract not provided") } @@ -681,6 +747,8 @@ func (r *ChainReader) GetRegisteredSets( ctx context.Context, operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.getregisteredsets") + if r.allocationManager == nil { return nil, errors.New("AllocationManager contract not provided") } @@ -694,6 +762,8 @@ func (r *ChainReader) CanCall( target gethcommon.Address, selector [4]byte, ) (bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.cancall") + canCall, err := r.permissionController.CanCall( &bind.CallOpts{Context: ctx}, accountAddress, @@ -713,6 +783,8 @@ func (r *ChainReader) ListAppointees( target gethcommon.Address, selector [4]byte, ) ([]gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.listappointees") + appointees, err := r.permissionController.GetAppointees( &bind.CallOpts{Context: ctx}, accountAddress, @@ -730,6 +802,8 @@ func (r *ChainReader) ListAppointeePermissions( accountAddress gethcommon.Address, appointeeAddress gethcommon.Address, ) ([]gethcommon.Address, [][4]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.listappointeepermissions") + targets, selectors, err := r.permissionController.GetAppointeePermissions( &bind.CallOpts{Context: ctx}, accountAddress, @@ -745,6 +819,8 @@ func (r *ChainReader) ListPendingAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.listpendingadmins") + pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) if err != nil { return nil, errors.New("call to permission controller failed: " + err.Error()) @@ -756,6 +832,8 @@ func (r *ChainReader) ListAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.listadmins") + pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) if err != nil { return nil, errors.New("call to permission controller failed: " + err.Error()) @@ -768,6 +846,8 @@ func (r *ChainReader) IsPendingAdmin( accountAddress gethcommon.Address, pendingAdminAddress gethcommon.Address, ) (bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.ispendingadmin") + isPendingAdmin, err := r.permissionController.IsPendingAdmin( &bind.CallOpts{Context: ctx}, accountAddress, @@ -784,6 +864,8 @@ func (r *ChainReader) IsAdmin( accountAddress gethcommon.Address, adminAddress gethcommon.Address, ) (bool, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainreader.isadmin") + isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) if err != nil { return isAdmin, errors.New("call to permission controller failed: " + err.Error()) diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index 6b91f1fd..09ed50f4 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -23,6 +23,7 @@ import ( strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/metrics" + "github.com/Layr-Labs/eigensdk-go/telemetry" "github.com/Layr-Labs/eigensdk-go/types" "github.com/Layr-Labs/eigensdk-go/utils" ) @@ -62,6 +63,7 @@ func NewChainWriter( txMgr txmgr.TxManager, ) *ChainWriter { logger = logger.With(logging.ComponentKey, "elcontracts/writer") + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newchainwriter") return &ChainWriter{ delegationManager: delegationManager, @@ -88,6 +90,8 @@ func BuildELChainWriter( eigenMetrics metrics.Metrics, txMgr txmgr.TxManager, ) (*ChainWriter, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.buildelchainwriter") + elContractBindings, err := NewEigenlayerContractBindings( delegationManagerAddr, avsDirectoryAddr, @@ -130,6 +134,8 @@ func NewWriterFromConfig( eigenMetrics metrics.Metrics, txMgr txmgr.TxManager, ) (*ChainWriter, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newwriterfromconfig") + elContractBindings, err := NewBindingsFromConfig( cfg, ethClient, @@ -169,6 +175,8 @@ func (w *ChainWriter) RegisterAsOperator( operator types.Operator, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.registerasoperator") + if w.delegationManager == nil { return nil, errors.New("DelegationManager contract not provided") } @@ -202,6 +210,8 @@ func (w *ChainWriter) UpdateOperatorDetails( operator types.Operator, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.updateoperatordetails") + if w.delegationManager == nil { return nil, errors.New("DelegationManager contract not provided") } @@ -242,6 +252,8 @@ func (w *ChainWriter) UpdateMetadataURI( uri string, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.updatemetadatauri") + if w.delegationManager == nil { return nil, errors.New("DelegationManager contract not provided") } @@ -274,6 +286,8 @@ func (w *ChainWriter) DepositERC20IntoStrategy( amount *big.Int, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.depositerc20intostrategy") + if w.strategyManager == nil { return nil, errors.New("StrategyManager contract not provided") } @@ -318,6 +332,8 @@ func (w *ChainWriter) SetClaimerFor( claimer gethcommon.Address, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.setclaimerfor") + if w.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } @@ -345,6 +361,8 @@ func (w *ChainWriter) ProcessClaim( earnerAddress gethcommon.Address, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.processclaim") + if w.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } @@ -373,6 +391,8 @@ func (w *ChainWriter) SetOperatorAVSSplit( split uint16, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.setoperatoravssplit") + if w.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } @@ -400,6 +420,8 @@ func (w *ChainWriter) SetOperatorPISplit( split uint16, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.setoperatorpisplit") + if w.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } @@ -427,6 +449,8 @@ func (w *ChainWriter) ProcessClaims( earnerAddress gethcommon.Address, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.processclaims") + if w.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } @@ -459,6 +483,8 @@ func (w *ChainWriter) ForceDeregisterFromOperatorSets( operatorSetIds []uint32, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.forcederegisterfromoperatorsets") + if w.allocationManager == nil { return nil, errors.New("AVSDirectory contract not provided") } @@ -495,6 +521,8 @@ func (w *ChainWriter) ModifyAllocations( allocations []allocationmanager.IAllocationManagerTypesAllocateParams, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.modifyallocations") + if w.allocationManager == nil { return nil, errors.New("AllocationManager contract not provided") } @@ -523,6 +551,8 @@ func (w *ChainWriter) SetAllocationDelay( delay uint32, waitForReceipt bool, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.setallocationdelay") + if w.allocationManager == nil { return nil, errors.New("AllocationManager contract not provided") } @@ -549,6 +579,8 @@ func (w *ChainWriter) DeregisterFromOperatorSets( operator gethcommon.Address, request DeregistrationRequest, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.deregisterfromoperatorsets") + if w.allocationManager == nil { return nil, errors.New("AllocationManager contract not provided") } @@ -581,6 +613,8 @@ func (w *ChainWriter) RegisterForOperatorSets( ctx context.Context, request RegistrationRequest, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.registerforoperatorsets") + if w.allocationManager == nil { return nil, errors.New("AllocationManager contract not provided") } @@ -613,6 +647,8 @@ func (w *ChainWriter) RemovePermission( ctx context.Context, request RemovePermissionRequest, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.removepermission") + txOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, utils.WrapError("failed to get no-send tx opts", err) @@ -628,6 +664,8 @@ func (w *ChainWriter) NewRemovePermissionTx( txOpts *bind.TransactOpts, request RemovePermissionRequest, ) (*gethtypes.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newremovepermissiontx") + if w.permissionController == nil { return nil, errors.New("permission contract not provided") } @@ -645,6 +683,8 @@ func (w *ChainWriter) NewSetPermissionTx( txOpts *bind.TransactOpts, request SetPermissionRequest, ) (*gethtypes.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newsetpermissiontx") + if w.permissionController == nil { return nil, errors.New("permission contract not provided") } @@ -661,6 +701,8 @@ func (w *ChainWriter) SetPermission( ctx context.Context, request SetPermissionRequest, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.setpermission") + txOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, utils.WrapError("failed to get no-send tx opts", err) @@ -678,6 +720,8 @@ func (w *ChainWriter) NewAcceptAdminTx( txOpts *bind.TransactOpts, request AcceptAdminRequest, ) (*gethtypes.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newacceptadmintx") + if w.permissionController == nil { return nil, errors.New("permission contract not provided") } @@ -688,6 +732,8 @@ func (w *ChainWriter) AcceptAdmin( ctx context.Context, request AcceptAdminRequest, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.acceptadmin") + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, utils.WrapError("failed to get no send tx opts", err) @@ -704,6 +750,8 @@ func (w *ChainWriter) NewAddPendingAdminTx( txOpts *bind.TransactOpts, request AddPendingAdminRequest, ) (*gethtypes.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newaddpendingadmintx") + if w.permissionController == nil { return nil, errors.New("permission contract not provided") } @@ -711,6 +759,8 @@ func (w *ChainWriter) NewAddPendingAdminTx( } func (w *ChainWriter) AddPendingAdmin(ctx context.Context, request AddPendingAdminRequest) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.addpendingadmin") + txOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, utils.WrapError("failed to get no send tx opts", err) @@ -726,6 +776,8 @@ func (w *ChainWriter) NewRemoveAdminTx( txOpts *bind.TransactOpts, request RemoveAdminRequest, ) (*gethtypes.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newremoveadmintx") + if w.permissionController == nil { return nil, errors.New("permission contract not provided") } @@ -736,6 +788,8 @@ func (w *ChainWriter) RemoveAdmin( ctx context.Context, request RemoveAdminRequest, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.removeadmin") + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, utils.WrapError("failed to get no send tx opts", err) @@ -752,6 +806,8 @@ func (w *ChainWriter) NewRemovePendingAdminTx( txOpts *bind.TransactOpts, request RemovePendingAdminRequest, ) (*gethtypes.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.newremovependingadmintx") + if w.permissionController == nil { return nil, errors.New("permission contract not provided") } @@ -762,6 +818,8 @@ func (w *ChainWriter) RemovePendingAdmin( ctx context.Context, request RemovePendingAdminRequest, ) (*gethtypes.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("elcontracts.chainwriter.removependingadmin") + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, utils.WrapError("failed to get no send tx opts", err) diff --git a/chainio/clients/eth/instrumented_client.go b/chainio/clients/eth/instrumented_client.go index 0e69347a..e42aea80 100644 --- a/chainio/clients/eth/instrumented_client.go +++ b/chainio/clients/eth/instrumented_client.go @@ -6,6 +6,7 @@ import ( "time" rpccalls "github.com/Layr-Labs/eigensdk-go/metrics/collectors/rpc_calls" + "github.com/Layr-Labs/eigensdk-go/telemetry" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -31,6 +32,8 @@ var _ HttpBackend = (*InstrumentedClient)(nil) var _ WsBackend = (*InstrumentedClient)(nil) func NewInstrumentedClient(rpcAddress string, rpcCallsCollector *rpccalls.Collector) (*InstrumentedClient, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.newinstrumentedclient") + client, err := ethclient.Dial(rpcAddress) if err != nil { return nil, err @@ -43,6 +46,8 @@ func NewInstrumentedClientFromClient( client *ethclient.Client, rpcCallsCollector *rpccalls.Collector, ) *InstrumentedClient { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.newinstrumentedclientfromclient") + clientAndVersion := getClientAndVersion(client) return &InstrumentedClient{ client: client, @@ -54,6 +59,8 @@ func NewInstrumentedClientFromClient( // gethClient interface methods func (iec *InstrumentedClient) ChainID(ctx context.Context) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.chainid") + chainID := func() (*big.Int, error) { return iec.client.ChainID(ctx) } id, err := instrumentFunction[*big.Int](chainID, "eth_chainId", iec) return id, err @@ -64,6 +71,8 @@ func (iec *InstrumentedClient) BalanceAt( account common.Address, blockNumber *big.Int, ) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.balanceat") + balanceAt := func() (*big.Int, error) { return iec.client.BalanceAt(ctx, account, blockNumber) } balance, err := instrumentFunction[*big.Int](balanceAt, "eth_getBalance", iec) if err != nil { @@ -73,6 +82,8 @@ func (iec *InstrumentedClient) BalanceAt( } func (iec *InstrumentedClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.blockbyhash") + blockByHash := func() (*types.Block, error) { return iec.client.BlockByHash(ctx, hash) } block, err := instrumentFunction[*types.Block](blockByHash, "eth_getBlockByHash", iec) if err != nil { @@ -82,6 +93,8 @@ func (iec *InstrumentedClient) BlockByHash(ctx context.Context, hash common.Hash } func (iec *InstrumentedClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.blockbynumber") + blockByNumber := func() (*types.Block, error) { return iec.client.BlockByNumber(ctx, number) } block, err := instrumentFunction[*types.Block]( blockByNumber, @@ -95,6 +108,8 @@ func (iec *InstrumentedClient) BlockByNumber(ctx context.Context, number *big.In } func (iec *InstrumentedClient) BlockNumber(ctx context.Context) (uint64, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.blocknumber") + blockNumber := func() (uint64, error) { return iec.client.BlockNumber(ctx) } number, err := instrumentFunction[uint64](blockNumber, "eth_blockNumber", iec) if err != nil { @@ -108,6 +123,8 @@ func (iec *InstrumentedClient) CallContract( call ethereum.CallMsg, blockNumber *big.Int, ) ([]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.callcontract") + callContract := func() ([]byte, error) { return iec.client.CallContract(ctx, call, blockNumber) } bytes, err := instrumentFunction[[]byte](callContract, "eth_call", iec) if err != nil { @@ -121,6 +138,8 @@ func (iec *InstrumentedClient) CodeAt( contract common.Address, blockNumber *big.Int, ) ([]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.codeat") + call := func() ([]byte, error) { return iec.client.CodeAt(ctx, contract, blockNumber) } bytes, err := instrumentFunction[[]byte](call, "eth_getCode", iec) if err != nil { @@ -130,6 +149,8 @@ func (iec *InstrumentedClient) CodeAt( } func (iec *InstrumentedClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.estimategas") + estimateGas := func() (uint64, error) { return iec.client.EstimateGas(ctx, call) } gas, err := instrumentFunction[uint64](estimateGas, "eth_estimateGas", iec) if err != nil { @@ -144,6 +165,8 @@ func (iec *InstrumentedClient) FeeHistory( lastBlock *big.Int, rewardPercentiles []float64, ) (*ethereum.FeeHistory, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.feehistory") + feeHistory := func() (*ethereum.FeeHistory, error) { return iec.client.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles) } @@ -159,6 +182,8 @@ func (iec *InstrumentedClient) FeeHistory( } func (iec *InstrumentedClient) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.filterlogs") + filterLogs := func() ([]types.Log, error) { return iec.client.FilterLogs(ctx, query) } logs, err := instrumentFunction[[]types.Log](filterLogs, "eth_getLogs", iec) if err != nil { @@ -168,6 +193,8 @@ func (iec *InstrumentedClient) FilterLogs(ctx context.Context, query ethereum.Fi } func (iec *InstrumentedClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.headerbyhash") + headerByHash := func() (*types.Header, error) { return iec.client.HeaderByHash(ctx, hash) } header, err := instrumentFunction[*types.Header]( headerByHash, @@ -181,6 +208,8 @@ func (iec *InstrumentedClient) HeaderByHash(ctx context.Context, hash common.Has } func (iec *InstrumentedClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.headerbynumber") + headerByNumber := func() (*types.Header, error) { return iec.client.HeaderByNumber(ctx, number) } header, err := instrumentFunction[*types.Header]( headerByNumber, @@ -198,6 +227,8 @@ func (iec *InstrumentedClient) NonceAt( account common.Address, blockNumber *big.Int, ) (uint64, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.nonceat") + nonceAt := func() (uint64, error) { return iec.client.NonceAt(ctx, account, blockNumber) } nonce, err := instrumentFunction[uint64](nonceAt, "eth_getTransactionCount", iec) if err != nil { @@ -207,6 +238,8 @@ func (iec *InstrumentedClient) NonceAt( } func (iec *InstrumentedClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.pendingbalanceat") + pendingBalanceAt := func() (*big.Int, error) { return iec.client.PendingBalanceAt(ctx, account) } balance, err := instrumentFunction[*big.Int](pendingBalanceAt, "eth_getBalance", iec) if err != nil { @@ -216,6 +249,8 @@ func (iec *InstrumentedClient) PendingBalanceAt(ctx context.Context, account com } func (iec *InstrumentedClient) PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.pendingcallcontract") + pendingCallContract := func() ([]byte, error) { return iec.client.PendingCallContract(ctx, call) } bytes, err := instrumentFunction[[]byte](pendingCallContract, "eth_call", iec) if err != nil { @@ -225,6 +260,8 @@ func (iec *InstrumentedClient) PendingCallContract(ctx context.Context, call eth } func (iec *InstrumentedClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.pendingcodeat") + pendingCodeAt := func() ([]byte, error) { return iec.client.PendingCodeAt(ctx, account) } bytes, err := instrumentFunction[[]byte](pendingCodeAt, "eth_getCode", iec) if err != nil { @@ -234,6 +271,8 @@ func (iec *InstrumentedClient) PendingCodeAt(ctx context.Context, account common } func (iec *InstrumentedClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.pendingnonceat") + pendingNonceAt := func() (uint64, error) { return iec.client.PendingNonceAt(ctx, account) } nonce, err := instrumentFunction[uint64]( pendingNonceAt, @@ -251,6 +290,8 @@ func (iec *InstrumentedClient) PendingStorageAt( account common.Address, key common.Hash, ) ([]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.pendingstorageat") + pendingStorageAt := func() ([]byte, error) { return iec.client.PendingStorageAt(ctx, account, key) } bytes, err := instrumentFunction[[]byte](pendingStorageAt, "eth_getStorageAt", iec) if err != nil { @@ -260,6 +301,8 @@ func (iec *InstrumentedClient) PendingStorageAt( } func (iec *InstrumentedClient) PendingTransactionCount(ctx context.Context) (uint, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.pendingtransactioncount") + pendingTransactionCount := func() (uint, error) { return iec.client.PendingTransactionCount(ctx) } count, err := instrumentFunction[uint]( pendingTransactionCount, @@ -273,6 +316,8 @@ func (iec *InstrumentedClient) PendingTransactionCount(ctx context.Context) (uin } func (iec *InstrumentedClient) SendTransaction(ctx context.Context, tx *types.Transaction) error { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.sendtransaction") + // instrumentFunction takes a function that returns a value and an error // so we just wrap the SendTransaction method in a function that returns 0 as its value, // which we throw out below @@ -287,6 +332,8 @@ func (iec *InstrumentedClient) StorageAt( key common.Hash, blockNumber *big.Int, ) ([]byte, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.storageat") + storageAt := func() ([]byte, error) { return iec.client.StorageAt(ctx, account, key, blockNumber) } bytes, err := instrumentFunction[[]byte](storageAt, "eth_getStorageAt", iec) if err != nil { @@ -300,6 +347,8 @@ func (iec *InstrumentedClient) SubscribeFilterLogs( query ethereum.FilterQuery, ch chan<- types.Log, ) (ethereum.Subscription, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.subscribefilterlogs") + subscribeFilterLogs := func() (ethereum.Subscription, error) { return iec.client.SubscribeFilterLogs(ctx, query, ch) } subscription, err := instrumentFunction[ethereum.Subscription]( subscribeFilterLogs, @@ -316,6 +365,8 @@ func (iec *InstrumentedClient) SubscribeNewHead( ctx context.Context, ch chan<- *types.Header, ) (ethereum.Subscription, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.subscribenewhead") + subscribeNewHead := func() (ethereum.Subscription, error) { return iec.client.SubscribeNewHead(ctx, ch) } subscription, err := instrumentFunction[ethereum.Subscription]( subscribeNewHead, @@ -329,6 +380,8 @@ func (iec *InstrumentedClient) SubscribeNewHead( } func (iec *InstrumentedClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.suggestgasprice") + suggestGasPrice := func() (*big.Int, error) { return iec.client.SuggestGasPrice(ctx) } gasPrice, err := instrumentFunction[*big.Int](suggestGasPrice, "eth_gasPrice", iec) if err != nil { @@ -338,6 +391,8 @@ func (iec *InstrumentedClient) SuggestGasPrice(ctx context.Context) (*big.Int, e } func (iec *InstrumentedClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.suggestgastipcap") + suggestGasTipCap := func() (*big.Int, error) { return iec.client.SuggestGasTipCap(ctx) } gasTipCap, err := instrumentFunction[*big.Int]( suggestGasTipCap, @@ -369,6 +424,8 @@ func (iec *InstrumentedClient) TransactionByHash( ctx context.Context, hash common.Hash, ) (tx *types.Transaction, isPending bool, err error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.transactionbyhash") + start := time.Now() tx, isPending, err = iec.client.TransactionByHash(ctx, hash) // we count both successful and erroring calls (even though this is not well defined in the spec) @@ -388,6 +445,8 @@ func (iec *InstrumentedClient) TransactionByHash( } func (iec *InstrumentedClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.transactioncount") + transactionCount := func() (uint, error) { return iec.client.TransactionCount(ctx, blockHash) } count, err := instrumentFunction[uint]( transactionCount, @@ -405,6 +464,8 @@ func (iec *InstrumentedClient) TransactionInBlock( blockHash common.Hash, index uint, ) (*types.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.transactioninblock") + transactionInBlock := func() (*types.Transaction, error) { return iec.client.TransactionInBlock(ctx, blockHash, index) } tx, err := instrumentFunction[*types.Transaction]( transactionInBlock, @@ -418,6 +479,8 @@ func (iec *InstrumentedClient) TransactionInBlock( } func (iec *InstrumentedClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.transactionreceipt") + transactionReceipt := func() (*types.Receipt, error) { return iec.client.TransactionReceipt(ctx, txHash) } receipt, err := instrumentFunction[*types.Receipt]( transactionReceipt, @@ -434,6 +497,8 @@ func (iec *InstrumentedClient) TransactionReceipt(ctx context.Context, txHash co // but it is needed to comply with the rpc metrics defined in avs-node spec // https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/metrics/metrics-prom-spec func getClientAndVersion(client *ethclient.Client) string { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.getclientandversion") + var clientVersion string err := client.Client().Call(&clientVersion, "web3_clientVersion") if err != nil { @@ -448,6 +513,8 @@ func instrumentFunction[T any]( rpcMethodName string, iec *InstrumentedClient, ) (value T, err error) { + _ = telemetry.GetTelemetry().CaptureEvent("eth.instrumentedclient.instrumentfunction") + start := time.Now() result, err := rpcCall() // we count both successful and erroring calls (even though this is not well defined in the spec) diff --git a/chainio/txmgr/geometric/geometric.go b/chainio/txmgr/geometric/geometric.go index f7c9627d..e961f251 100644 --- a/chainio/txmgr/geometric/geometric.go +++ b/chainio/txmgr/geometric/geometric.go @@ -11,6 +11,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/telemetry" "github.com/Layr-Labs/eigensdk-go/utils" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -130,6 +131,8 @@ func NewGeometricTxnManager( metrics Metrics, params GeometricTxnManagerParams, ) *GeometricTxManager { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.newgeometrictxnmanager") + fillUnsetParamsWithDefaultValues(¶ms) return &GeometricTxManager{ ethClient: ethClient, @@ -143,6 +146,8 @@ func NewGeometricTxnManager( // GetNoSendTxOpts This generates a noSend TransactOpts so that we can use // this to generate the transaction without actually sending it func (m *GeometricTxManager) GetNoSendTxOpts() (*bind.TransactOpts, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.getnosendtxopts") + ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() from, err := m.wallet.SenderAddress(ctxWithTimeout) @@ -157,6 +162,8 @@ func (m *GeometricTxManager) GetNoSendTxOpts() (*bind.TransactOpts, error) { } func newTxnRequest(tx *types.Transaction) *txnRequest { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.newtxnrequest") + return &txnRequest{ tx: tx, requestedAt: time.Now(), @@ -174,6 +181,8 @@ func (t *GeometricTxManager) Send( tx *types.Transaction, waitForReceipt bool, ) (*types.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.send") + return t.processTransaction(ctx, newTxnRequest(tx)) } @@ -183,6 +192,8 @@ func (t *GeometricTxManager) Send( // But sending nonces 2,1 and forgetting 0 would cause the manager to get stuck waiting for nonce 0 to be mined. // Thus a wallet which manages nonces should be used to ensure the correct nonce is set. func (t *GeometricTxManager) processTransaction(ctx context.Context, req *txnRequest) (*types.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.processtransaction") + t.logger.Debug("new transaction", "nonce", req.tx.Nonce(), "gasFeeCap", req.tx.GasFeeCap(), "gasTipCap", req.tx.GasTipCap(), ) @@ -266,6 +277,8 @@ func (t *GeometricTxManager) processTransaction(ctx context.Context, req *txnReq // this is only needed for the Fireblocks wallet, where some processing is done in their backend before broadcasting to // the ethereum network. func (t *GeometricTxManager) ensureAnyFireblocksTransactionBroadcasted(ctx context.Context, txs []*transaction) error { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.ensureanyfireblockstransactionbroadcasted") + queryTicker := time.NewTicker(t.params.GetTxReceiptTickerDuration) defer queryTicker.Stop() @@ -294,6 +307,8 @@ func (t *GeometricTxManager) ensureAnyTransactionConfirmed( ctx context.Context, txs []*transaction, ) (*types.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.ensureanytransactionconfirmed") + queryTicker := time.NewTicker(t.params.GetTxReceiptTickerDuration) defer queryTicker.Stop() var receipt *types.Receipt @@ -366,6 +381,8 @@ func (t *GeometricTxManager) ensureAnyTransactionConfirmed( // It returns the receipt once the transaction has been confirmed. // It returns an error if the transaction fails to be sent for reasons other than timeouts. func (t *GeometricTxManager) monitorTransaction(ctx context.Context, req *txnRequest) (*types.Receipt, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.monitortransaction") + numSpeedUps := 0 retryFromFailure := 0 @@ -505,6 +522,8 @@ func (t *GeometricTxManager) speedUpTxn( tx *types.Transaction, numSpeedUps int, ) (*types.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.speeduptxn") + // bump the current gasTip, and also reestimate it from the node, and take the highest value var newGasTipCap *big.Int { @@ -551,6 +570,8 @@ func (t *GeometricTxManager) updateGasTipCap( newGasTipCap *big.Int, from common.Address, ) (*types.Transaction, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.updategastipcap") + gasFeeCap, err := t.estimateGasFeeCap(ctx, newGasTipCap) if err != nil { return nil, utils.WrapError("failed to estimate gas fee cap", err) @@ -587,6 +608,8 @@ func (t *GeometricTxManager) updateGasTipCap( } func (t *GeometricTxManager) estimateGasTipCap(ctx context.Context) (gasTipCap *big.Int, err error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.estimategastipcap") + gasTipCap, err = t.ethClient.SuggestGasTipCap(ctx) if err != nil { // If the transaction failed because the backend does not support @@ -605,6 +628,8 @@ func (t *GeometricTxManager) estimateGasTipCap(ctx context.Context) (gasTipCap * // addGasTipCapBuffer adds a buffer to the gas tip cap to account for potential changes in the state of the chain // The result is returned in a new big.Int to avoid modifying the input gasTipCap. func (t *GeometricTxManager) addGasTipCapBuffer(gasTipCap *big.Int) *big.Int { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.addgastipcapbuffer") + bumpedGasTipCap := new(big.Int).Set(gasTipCap) return bumpedGasTipCap.Mul(bumpedGasTipCap, big.NewInt(int64(t.params.GasTipMultiplier*100))). Div(bumpedGasTipCap, big.NewInt(100)) @@ -615,6 +640,8 @@ func (t *GeometricTxManager) addGasTipCapBuffer(gasTipCap *big.Int) *big.Int { // Rationale: https://www.blocknative.com/blog/eip-1559-fees // The result is returned in a new big.Int to avoid modifying gasTipCap. func (t *GeometricTxManager) estimateGasFeeCap(ctx context.Context, gasTipCap *big.Int) (*big.Int, error) { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.estimategasfeecap") + header, err := t.ethClient.HeaderByNumber(ctx, nil) if err != nil { return nil, utils.WrapError("failed to get latest header", err) @@ -623,5 +650,7 @@ func (t *GeometricTxManager) estimateGasFeeCap(ctx context.Context, gasTipCap *b } func (t *GeometricTxManager) addGasBuffer(gasLimit uint64) uint64 { + _ = telemetry.GetTelemetry().CaptureEvent("txmgr.geometric.addgasbuffer") + return uint64(t.params.GasMultiplier * float64(gasLimit)) } diff --git a/go.mod b/go.mod index 8217b155..8782e6b8 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/moby/sys/user v0.1.0 // indirect + github.com/posthog/posthog-go v1.2.24 // direct go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/otel v1.24.0 // indirect go.opentelemetry.io/otel/metric v1.24.0 // indirect diff --git a/go.sum b/go.sum index 9584993b..5a23a982 100644 --- a/go.sum +++ b/go.sum @@ -216,6 +216,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 v1.2.24 h1:A+iG4saBJemo++VDlcWovbYf8KFFNUfrCoJtsc40RPA= +github.com/posthog/posthog-go v1.2.24/go.mod h1:uYC2l1Yktc8E+9FAHJ9QZG4vQf/NHJPD800Hsm7DzoM= 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= diff --git a/telemetry/README.md b/telemetry/README.md new file mode 100644 index 00000000..e69de29b diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go new file mode 100644 index 00000000..473b5669 --- /dev/null +++ b/telemetry/telemetry.go @@ -0,0 +1,68 @@ +//go:telemetry + +package telemetry + +import ( + "runtime" + "sync" + + "github.com/posthog/posthog-go" +) + +var once sync.Once + +var telemetrySingleton Telemetry = &BogusTelemetry{} + +type BogusTelemetry struct{} + +type RealTelemetry struct { + Client *posthog.Client + ApiKey string + UserId string +} + +// The telemetry config should be configured as a singleton, +// so that it can be accessed from anywhere in the codebase. +func InitTelemetry( + ApiKey string, + UserId string) Telemetry { + once.Do(func() { + client, _ := posthog.NewWithConfig( + ApiKey, + posthog.Config{ + Endpoint: "https://us.i.posthog.com", + }, + ) + runtime.SetFinalizer(&client, func(client *posthog.Client) { + (*client).Close() + }) + + telemetrySingleton = &RealTelemetry{ + Client: &client, + ApiKey: ApiKey, + UserId: UserId, + } + }) + return telemetrySingleton +} + +type Telemetry interface { + CaptureEvent(event string) error +} + +func GetTelemetry() Telemetry { + return telemetrySingleton +} + +func (telemetry *RealTelemetry) CaptureEvent(event string) error { + userId := telemetry.UserId + err := (*telemetry.Client).Enqueue(posthog.Capture{ + DistinctId: userId, + Event: event, + }) + return err +} + +func (telemetry *BogusTelemetry) CaptureEvent(event string) error { + return nil +}