mukan-ibc/modules/apps/transfer/internal/telemetry/telemetry.go
Mukan Erkin Törük 6852832fe8
Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
initial: sovereign Mukan Network fork
2026-05-11 03:18:28 +03:00

71 lines
2.2 KiB
Go

package telemetry
import (
"fmt"
"github.com/hashicorp/go-metrics"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/telemetry"
"github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
coremetrics "github.com/cosmos/ibc-go/v10/modules/core/metrics"
)
func ReportTransfer(sourcePort, sourceChannel, destinationPort, destinationChannel string, token types.Token) {
labels := []metrics.Label{
telemetry.NewLabel(coremetrics.LabelDestinationPort, destinationPort),
telemetry.NewLabel(coremetrics.LabelDestinationChannel, destinationChannel),
}
amount, ok := sdkmath.NewIntFromString(token.Amount)
if ok && amount.IsInt64() {
telemetry.SetGaugeWithLabels(
[]string{"tx", "msg", "ibc", "transfer"},
float32(amount.Int64()),
[]metrics.Label{telemetry.NewLabel(coremetrics.LabelDenom, token.Denom.Path())},
)
}
labels = append(labels, telemetry.NewLabel(coremetrics.LabelSource, fmt.Sprintf("%t", !token.Denom.HasPrefix(sourcePort, sourceChannel))))
telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "send"},
1,
labels,
)
}
func ReportOnRecvPacket(sourcePort, sourceChannel, destinationPort, destinationChannel string, token types.Token) {
labels := []metrics.Label{
telemetry.NewLabel(coremetrics.LabelSourcePort, sourcePort),
telemetry.NewLabel(coremetrics.LabelSourceChannel, sourceChannel),
}
// Modify trace as Recv does.
if token.Denom.HasPrefix(sourcePort, sourceChannel) {
token.Denom.Trace = token.Denom.Trace[1:]
} else {
trace := []types.Hop{types.NewHop(destinationPort, destinationChannel)}
token.Denom.Trace = append(trace, token.Denom.Trace...)
}
// Transfer amount has already been parsed in caller.
transferAmount, ok := sdkmath.NewIntFromString(token.Amount)
if ok && transferAmount.IsInt64() {
telemetry.SetGaugeWithLabels(
[]string{"ibc", types.ModuleName, "packet", "receive"},
float32(transferAmount.Int64()),
[]metrics.Label{telemetry.NewLabel(coremetrics.LabelDenom, token.Denom.Path())},
)
}
labels = append(labels, telemetry.NewLabel(coremetrics.LabelSource, fmt.Sprintf("%t", token.Denom.HasPrefix(sourcePort, sourceChannel))))
telemetry.IncrCounterWithLabels(
[]string{"ibc", types.ModuleName, "receive"},
1,
labels,
)
}