Skip to content

Commit

Permalink
record string status (#2861)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com>
  • Loading branch information
trajan0x and trajan0x authored Jul 9, 2024
1 parent a554e13 commit 0a083a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions services/rfq/relayer/service/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"fmt"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"

"github.com/cornelk/hashmap"
"github.com/synapsecns/sanguine/core/metrics"
Expand Down Expand Up @@ -32,7 +33,7 @@ type otelRecorder struct {
statusCountGauge metric.Int64ObservableGauge
// statusCounts is used for metrics.
// status -> count
statusCounts *hashmap.Map[int, int]
statusCounts *hashmap.Map[reldb.QuoteRequestStatus, int]
// signer is the signer for signing transactions.
signer signer.Signer
}
Expand All @@ -41,7 +42,7 @@ func newOtelRecorder(meterHandler metrics.Handler, signer signer.Signer) (_ iOte
or := otelRecorder{
metrics: meterHandler,
meter: meterHandler.Meter(meterName),
statusCounts: hashmap.New[int, int](),
statusCounts: hashmap.New[reldb.QuoteRequestStatus, int](),
signer: signer,
}

Expand All @@ -63,9 +64,10 @@ func (o *otelRecorder) recordStatusCounts(_ context.Context, observer metric.Obs
return nil
}

o.statusCounts.Range(func(status int, count int) bool {
o.statusCounts.Range(func(status reldb.QuoteRequestStatus, count int) bool {
opts := metric.WithAttributes(
attribute.Int("status", status),
attribute.Int("status_int", int(status.Int())),
attribute.String("status", status.String()),
attribute.String("wallet", o.signer.Address().Hex()),
)
observer.ObserveInt64(o.statusCountGauge, int64(count), opts)
Expand All @@ -76,7 +78,7 @@ func (o *otelRecorder) recordStatusCounts(_ context.Context, observer metric.Obs
return nil
}

// RecordStatusCounts records the request status count.
func (o *otelRecorder) RecordStatusCount(status, count int) {
// RecordStatusCount records the request status count.
func (o *otelRecorder) RecordStatusCount(status reldb.QuoteRequestStatus, count int) {
o.statusCounts.Set(status, count)
}
6 changes: 5 additions & 1 deletion services/rfq/relayer/service/otel_generated.go

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

2 changes: 1 addition & 1 deletion services/rfq/relayer/service/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func (r *Relayer) recordMetrics(ctx context.Context) (err error) {
return fmt.Errorf("could not get status counts: %w", err)
}
for status, count := range statusCounts {
r.otelRecorder.RecordStatusCount(int(status.Int()), count)
r.otelRecorder.RecordStatusCount(status, count)
}
}
}
Expand Down

0 comments on commit 0a083a5

Please sign in to comment.