Skip to content

Commit

Permalink
Feat: add tracing around HasSufficientGas()
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Apr 9, 2024
1 parent b0468e9 commit 270a984
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion services/rfq/relayer/inventory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,15 @@ func (i *inventoryManagerImpl) approve(parentCtx context.Context, tokenAddr, con
}

// HasSufficientGas checks if there is sufficient gas for a given route.
func (i *inventoryManagerImpl) HasSufficientGas(ctx context.Context, origin, dest int) (sufficient bool, err error) {
func (i *inventoryManagerImpl) HasSufficientGas(parentCtx context.Context, origin, dest int) (sufficient bool, err error) {
ctx, span := i.handler.Tracer().Start(parentCtx, "HasSufficientGas", trace.WithAttributes(
attribute.Int(metrics.Origin, origin),
attribute.Int(metrics.Destination, dest),
))
defer func(err error) {
metrics.EndSpanWithErr(span, err)
}(err)

Check warning on line 375 in services/rfq/relayer/inventory/manager.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/inventory/manager.go#L368-L375

Added lines #L368 - L375 were not covered by tests

gasThresh, err := i.cfg.GetMinGasToken(dest)
if err != nil {
return false, fmt.Errorf("error getting min gas token: %w", err)
Expand All @@ -380,6 +388,12 @@ func (i *inventoryManagerImpl) HasSufficientGas(ctx context.Context, origin, des
}

sufficient = gasOrigin.Cmp(gasThresh) >= 0 && gasDest.Cmp(gasThresh) >= 0
span.SetAttributes(
attribute.String("gas_threshold", gasThresh.String()),
attribute.String("gas_origin", gasOrigin.String()),
attribute.String("gas_dest", gasDest.String()),
attribute.Bool("sufficient", sufficient),
)

Check warning on line 396 in services/rfq/relayer/inventory/manager.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/inventory/manager.go#L391-L396

Added lines #L391 - L396 were not covered by tests
return sufficient, nil
}

Expand Down

0 comments on commit 270a984

Please sign in to comment.