Skip to content

Commit

Permalink
[screener] enable otel (#2809)
Browse files Browse the repository at this point in the history
* enable otel

* fix sig
  • Loading branch information
golangisfun123 authored Jun 28, 2024
1 parent 17ef0b1 commit 02767e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
11 changes: 8 additions & 3 deletions contrib/screener-api/chainalysis/chainalysisapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"context"
"errors"
"fmt"
"github.com/TwiN/gocache/v2"
"github.com/valyala/fastjson"
"net/http"
"slices"
"strings"
"time"

"github.com/TwiN/gocache/v2"
"github.com/dubonzi/otelresty"
"github.com/valyala/fastjson"

"github.com/go-resty/resty/v2"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/core/retry"
)

Expand Down Expand Up @@ -41,7 +44,7 @@ const (
)

// NewClient creates a new Chainalysis API client.
func NewClient(riskLevels []string, apiKey, url string) Client {
func NewClient(metricHandler metrics.Handler, riskLevels []string, apiKey, url string) Client {

Check warning on line 47 in contrib/screener-api/chainalysis/chainalysisapi.go

View check run for this annotation

Codecov / codecov/patch

contrib/screener-api/chainalysis/chainalysisapi.go#L47

Added line #L47 was not covered by tests
client := resty.New().
SetBaseURL(url).
SetHeader("Content-Type", "application/json").
Expand All @@ -52,6 +55,8 @@ func NewClient(riskLevels []string, apiKey, url string) Client {
// TODO: make this configurable.
registrationCache := gocache.NewCache().WithEvictionPolicy(gocache.LeastRecentlyUsed).WithMaxMemoryUsage(maxCacheSizeGB * bytesInGB)

otelresty.TraceClient(client, otelresty.WithTracerProvider(metricHandler.GetTracerProvider()))

Check warning on line 59 in contrib/screener-api/chainalysis/chainalysisapi.go

View check run for this annotation

Codecov / codecov/patch

contrib/screener-api/chainalysis/chainalysisapi.go#L58-L59

Added lines #L58 - L59 were not covered by tests
return &clientImpl{
client: client,
apiKey: apiKey,
Expand Down
3 changes: 1 addition & 2 deletions contrib/screener-api/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func NewScreener(ctx context.Context, cfg config.Config, metricHandler metrics.H
docs.SwaggerInfo.Title = "Screener API"
docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%d", cfg.Port)

screener.client = chainalysis.NewClient(
cfg.RiskLevels, cfg.ChainalysisKey, core.GetEnv("CHAINALYSIS_URL", cfg.ChainalysisURL))
screener.client = chainalysis.NewClient(metricHandler, cfg.RiskLevels, cfg.ChainalysisKey, core.GetEnv("CHAINALYSIS_URL", cfg.ChainalysisURL))

screener.blacklistCache = make(map[string]bool)
screener.whitelist = make(map[string]bool)
Expand Down
2 changes: 1 addition & 1 deletion contrib/screener-api/screener/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *ScreenerSuite) TestScreener() {
Equal(s.T(), len(statuses), 1)
NotNil(s.T(), err)

c := chainalysis.NewClient([]string{"Severe", "High"}, "key", "url")
c := chainalysis.NewClient(s.metrics, []string{"Severe", "High"}, "key", "url")
NotNil(s.T(), c)

ot, err := c.ScreenAddress(s.GetTestContext(), "0x123")
Expand Down

0 comments on commit 02767e6

Please sign in to comment.