Skip to content

Commit

Permalink
feat(opbot): experimental logger (#3132)
Browse files Browse the repository at this point in the history
* use experimental logger to debug

* fix lint

* [goreleaser]
  • Loading branch information
golangisfun123 authored Sep 16, 2024
1 parent 7ffafac commit 377a7fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 7 additions & 0 deletions contrib/opbot/botmd/botmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"github.com/synapsecns/sanguine/core/dbcommon"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/core/metrics/instrumentation/slackertrace"
experimentalLogger "github.com/synapsecns/sanguine/core/metrics/logger"
signerConfig "github.com/synapsecns/sanguine/ethergo/signer/config"
"github.com/synapsecns/sanguine/ethergo/signer/signer"
"github.com/synapsecns/sanguine/ethergo/submitter"
cctpSql "github.com/synapsecns/sanguine/services/cctp-relayer/db/sql"
omnirpcClient "github.com/synapsecns/sanguine/services/omnirpc/client"
"github.com/uptrace/opentelemetry-go-extra/otelzap"
"golang.org/x/sync/errgroup"
)

Expand All @@ -30,15 +32,20 @@ type Bot struct {
signer signer.Signer
submitter submitter.TransactionSubmitter
screener screenerClient.ScreenerClient
logger experimentalLogger.ExperimentalLogger
}

// NewBot creates a new bot server.
func NewBot(handler metrics.Handler, cfg config.Config) *Bot {
server := slacker.NewClient(cfg.SlackBotToken, cfg.SlackAppToken)

sugaredLogger := otelzap.New(experimentalLogger.MakeZapLogger()).Sugar()

Check warning on line 43 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L41-L43

Added lines #L41 - L43 were not covered by tests
bot := Bot{
handler: handler,
cfg: cfg,
server: server,
logger: experimentalLogger.MakeWrappedSugaredLogger(sugaredLogger),

Check warning on line 48 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L48

Added line #L48 was not covered by tests
}

// you should be able to run opbot even without signoz.
Expand Down
18 changes: 12 additions & 6 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (b *Bot) traceCommand() *slacker.CommandDefinition {
// search for the transaction
res, err := b.signozClient.SearchTraces(ctx.Context(), signoz.Last3Hr, searchMap)
if err != nil {
b.logger.Errorf(ctx.Context(), "error searching for the transaction: %v", err)

Check warning on line 85 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L85

Added line #L85 was not covered by tests
_, err := ctx.Response().Reply("error searching for the transaction")
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -290,6 +291,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
}
}
if err != nil {
b.logger.Errorf(ctx.Context(), "error fetching quote request: %v", err)

Check warning on line 294 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L294

Added line #L294 was not covered by tests
_, err := ctx.Response().Reply("error fetching quote request")
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -338,19 +340,23 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
err = retry.WithBackoff(
ctx.Context(),
func(ctx context.Context) error {
txHash, err = relClient.GetTxHashByNonce(ctx, &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
txHash, err = relClient.GetTxHashByNonce(
ctx,
&relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})

Check warning on line 348 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L343-L348

Added lines #L343 - L348 were not covered by tests
if err != nil {
b.logger.Errorf(ctx, "error fetching quote request: %v", err)

Check warning on line 350 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L350

Added line #L350 was not covered by tests
return fmt.Errorf("error fetching quote request: %w", err)
}
return nil
},
retry.WithMaxAttempts(3),
retry.WithMaxAttemptTime(15*time.Second),
retry.WithMaxAttempts(5),
retry.WithMaxAttemptTime(30*time.Second),
)
if err != nil {
b.logger.Errorf(ctx.Context(), "error fetching quote request: %v", err)

Check warning on line 359 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L359

Added line #L359 was not covered by tests
_, err := ctx.Response().Reply(fmt.Sprintf("error fetching explorer link to refund, but nonce is %d", nonce))
log.Printf("error fetching quote request: %v\n", err)
return
Expand Down
2 changes: 1 addition & 1 deletion contrib/opbot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/synapsecns/sanguine/services/cctp-relayer v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/services/omnirpc v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/services/rfq v0.0.0-00010101000000-000000000000
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.1
github.com/urfave/cli/v2 v2.27.2
golang.org/x/sync v0.8.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -240,7 +241,6 @@ require (
github.com/uptrace/opentelemetry-go-extra/otelgorm v0.3.1 // indirect
github.com/uptrace/opentelemetry-go-extra/otelsql v0.3.1 // indirect
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.1 // indirect
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.1 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
Expand Down

0 comments on commit 377a7fa

Please sign in to comment.