Skip to content

Commit

Permalink
Add support for beholder events
Browse files Browse the repository at this point in the history
  • Loading branch information
dimriou committed Dec 19, 2024
1 parent 40fc378 commit d6f9598
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 0 deletions.
27 changes: 27 additions & 0 deletions core/chains/evm/txm/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"go.opentelemetry.io/otel/metric"
"google.golang.org/protobuf/proto"

"github.com/smartcontractkit/chainlink-common/pkg/beholder"
"github.com/smartcontractkit/chainlink-common/pkg/metrics"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txm/pb"
)

var (
Expand Down Expand Up @@ -91,3 +94,27 @@ func (m *txmMetrics) RecordTimeUntilTxConfirmed(ctx context.Context, duration fl
promTimeUntilTxConfirmed.WithLabelValues(m.chainID.String()).Observe(duration)
m.timeUntilTxConfirmed.Record(ctx, duration)
}

func (m *txmMetrics) EmitTxMessage(ctx context.Context, tx common.Hash, fromAddress common.Address, toAddress common.Address, nonce uint64) error {
message := &pb.TxMessage{
Hash: tx.String(),
FromAddress: fromAddress.String(),
ToAddress: toAddress.String(),
Nonce: nonce,
}

messageBytes, err := proto.Marshal(message)
if err != nil {
return err
}

err = beholder.GetEmitter().Emit(
ctx,
messageBytes,
"beholder_domain", "svr",
"beholder_entity", "TxMessage",
"beholder_data_schema", "/beholder-tx-message/versions/1",
)

return err
}
159 changes: 159 additions & 0 deletions core/chains/evm/txm/pb/beholder-tx-message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions core/chains/evm/txm/pb/beholder-tx-message.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

option go_package = "github.com/smartcontractkit/chainlink-common/pkg/beholder/pb";

package pb;

message TxMessage {
string Hash = 1;
string FromAddress = 2;
string ToAddress = 3;
uint64 Nonce = 4;
}
3 changes: 3 additions & 0 deletions core/chains/evm/txm/txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ func (t *Txm) sendTransactionWithError(ctx context.Context, tx *types.Transactio
}

t.metrics.IncrementNumBroadcastedTxs(ctx)
if bErr := t.metrics.EmitTxMessage(ctx, attempt.Hash, address, tx.ToAddress, *tx.Nonce); bErr != nil {
t.lggr.Errorw("Beholder error emitting tx message", "err", bErr)
}
return t.txStore.UpdateTransactionBroadcast(ctx, attempt.TxID, *tx.Nonce, attempt.Hash, address)
}

Expand Down

0 comments on commit d6f9598

Please sign in to comment.