Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
fix: make all attributes to follow OTLP specification convention format
Browse files Browse the repository at this point in the history
  • Loading branch information
P1sar committed Aug 2, 2023
1 parent 6ff836f commit c026f57
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion chains/evm/calls/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package events

import (
"fmt"

"github.com/ChainSafe/chainbridge-core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -41,5 +42,5 @@ type Deposit struct {
}

func (d *Deposit) TraceEventAttributes() []attribute.KeyValue {
return []attribute.KeyValue{attribute.Int("deposit_dstdomain", int(d.DestinationDomainID)), attribute.String("deposit_rID", fmt.Sprintf("%x", d.ResourceID)), attribute.String("tx_sender", d.SenderAddress.Hex())}
return []attribute.KeyValue{attribute.Int("deposit.dstdomain", int(d.DestinationDomainID)), attribute.String("deposit.rID", fmt.Sprintf("%x", d.ResourceID)), attribute.String("tx.sender", d.SenderAddress.Hex())}
}
2 changes: 1 addition & 1 deletion chains/evm/calls/events/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (l *Listener) FetchDeposits(ctx context.Context, contractAddress common.Add

d.SenderAddress = common.BytesToAddress(dl.Topics[1].Bytes())
logger.Debug().Msgf("Found deposit log in block: %d, TxHash: %s, contractAddress: %s, sender: %s", dl.BlockNumber, dl.TxHash, dl.Address, d.SenderAddress)
span.AddEvent("Found deposit", traceapi.WithAttributes(append(d.TraceEventsttributes(), attribute.String("tx_hash", dl.TxHash.Hex()))...))
span.AddEvent("Found deposit", traceapi.WithAttributes(append(d.TraceEventAttributes(), attribute.String("tx.hash", dl.TxHash.Hex()))...))
deposits = append(deposits, d)
}
span.SetStatus(codes.Ok, "Deposits fetched")
Expand Down
2 changes: 1 addition & 1 deletion chains/evm/executor/message-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (mh *EVMMessageHandler) HandleMessage(m *message.Message) (*proposal.Propos
if err != nil {
return nil, err
}
log.Info().Str("msg_id", m.ID()).Msg("Handling new message")
log.Info().Str("msg.id", m.ID()).Msg("Handling new message")
prop, err := handleMessage(m, addr, *mh.handlerMatcher.ContractAddress())
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions chains/evm/listener/event-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (eh *DepositEventHandler) HandleEvent(ctx context.Context, startBlock *big.
return
}

logger.Debug().Str("msg_id", m.ID()).Msgf("Resolved message %s in block range: %s-%s", m.String(), startBlock.String(), endBlock.String())
span.AddEvent("Resolved message", traceapi.WithAttributes(attribute.String("msg_id", m.ID()), attribute.String("msg_type", string(m.Type))))
logger.Debug().Str("msg.id", m.ID()).Msgf("Resolved message %s in block range: %s-%s", m.String(), startBlock.String(), endBlock.String())
span.AddEvent("Resolved message", traceapi.WithAttributes(attribute.String("msg.id", m.ID()), attribute.String("msg.type", string(m.Type))))
domainDeposits[m.Destination] = append(domainDeposits[m.Destination], m)
}(d)
}
Expand Down
2 changes: 1 addition & 1 deletion example/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func Run() error {
}
}()

metrics, err := opentelemetry.NewRelayerMetrics(mp.Meter("relayer-metric-provider"), attribute.String("relayerid", configuration.RelayerConfig.Id), attribute.String("env", configuration.RelayerConfig.Env))
metrics, err := opentelemetry.NewRelayerMetrics(mp.Meter("relayer-metric-provider"), attribute.String("relayer.id", configuration.RelayerConfig.Id), attribute.String("env", configuration.RelayerConfig.Env))
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions relayer/message/message_processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type MessageProcessor func(ctx context.Context, message *Message) error
func AdjustDecimalsForERC20AmountMessageProcessor(args ...interface{}) MessageProcessor {
return func(ctx context.Context, m *Message) error {
_, span := otel.Tracer("relayer-core").Start(ctx, "relayer.core.MessageProcessor.AdjustDecimalsForERC20AmountMessageProcessor")
span.SetAttributes(attribute.String("msg_id", m.ID()), attribute.String("msg_type", string(m.Type)))
span.SetAttributes(attribute.String("msg.id", m.ID()), attribute.String("msg.type", string(m.Type)))
defer span.End()
if len(args) == 0 {
span.SetStatus(codes.Error, "processor requires 1 argument")
Expand Down Expand Up @@ -51,7 +51,7 @@ func AdjustDecimalsForERC20AmountMessageProcessor(args ...interface{}) MessagePr
diff := sourceDecimal - destDecimal
roundedAmount := big.NewInt(0)
roundedAmount.Div(amount, big.NewInt(0).Exp(big.NewInt(10), big.NewInt(0).SetUint64(diff), nil))
log.Info().Str("msg_id", m.ID()).Msgf("amount %s rounded to %s from chain %v to chain %v", amount.String(), roundedAmount.String(), m.Source, m.Destination)
log.Info().Str("msg.id", m.ID()).Msgf("amount %s rounded to %s from chain %v to chain %v", amount.String(), roundedAmount.String(), m.Source, m.Destination)
m.Payload[0] = roundedAmount.Bytes()
span.SetStatus(codes.Ok, "msg processed")
return nil
Expand All @@ -61,7 +61,7 @@ func AdjustDecimalsForERC20AmountMessageProcessor(args ...interface{}) MessagePr
roundedAmount := big.NewInt(0)
roundedAmount.Mul(amount, big.NewInt(0).Exp(big.NewInt(10), big.NewInt(0).SetUint64(diff), nil))
m.Payload[0] = roundedAmount.Bytes()
log.Info().Str("msg_id", m.ID()).Msgf("amount %s rounded to %s from chain %v to chain %v", amount.String(), roundedAmount.String(), m.Source, m.Destination)
log.Info().Str("msg.id", m.ID()).Msgf("amount %s rounded to %s from chain %v to chain %v", amount.String(), roundedAmount.String(), m.Source, m.Destination)
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func (r *Relayer) route(msgs []*message.Message) {

log.Debug().Msgf("Routing %d messages to destination %d", len(msgs), destChain.DomainID())
for _, m := range msgs {
span.AddEvent("Routing message", traceapi.WithAttributes(attribute.String("msg_id", m.ID()), attribute.String("msg_type", string(m.Type))))
log.Debug().Str("msg_id", m.ID()).Msgf("Routing message %+v", m.String())
span.AddEvent("Routing message", traceapi.WithAttributes(attribute.String("msg.id", m.ID()), attribute.String("msg.type", string(m.Type))))
log.Debug().Str("msg.id", m.ID()).Msgf("Routing message %+v", m.String())
r.metrics.TrackDepositMessage(m)
for _, mp := range r.messageProcessors {
if err := mp(ctxWithSpan, m); err != nil {
log.Error().Str("msg_id", m.ID()).Err(fmt.Errorf("error %w processing message %v", err, m.String()))
log.Error().Str("msg.id", m.ID()).Err(fmt.Errorf("error %w processing message %v", err, m.String()))
return
}
}
Expand All @@ -90,7 +90,7 @@ func (r *Relayer) route(msgs []*message.Message) {
err := destChain.Write(ctxWithSpan, msgs)
if err != nil {
for _, m := range msgs {
log.Err(err).Str("msg_id", m.ID()).Msgf("Failed sending message %s to destination %v", m.String(), destChain.DomainID())
log.Err(err).Str("msg.id", m.ID()).Msgf("Failed sending message %s to destination %v", m.String(), destChain.DomainID())
r.metrics.TrackExecutionError(m)
}
return
Expand Down

0 comments on commit c026f57

Please sign in to comment.