Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add trace to sync #2601

Merged
merged 3 commits into from
May 9, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions contrib/screener-api/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
}

screener.router = ginhelper.New(logger)
screener.router.Use(screener.metrics.Gin())
screener.router.Handle(http.MethodGet, "/:ruleset/address/:address", screener.screenAddress)

screener.router.Handle(http.MethodPost, "/api/data/sync", screener.authMiddleware(cfg), screener.blacklistAddress)
Expand Down Expand Up @@ -144,6 +145,12 @@
// @Produce json
// @Router /api/data/sync [post].
func (s *screenerImpl) blacklistAddress(c *gin.Context) {
var err error
ctx, span := s.metrics.Tracer().Start(c.Request.Context(), "blacklistAddress")
defer func() {
metrics.EndSpanWithErr(span, err)
}()

var blacklistBody client.BlackListBody

// Grab the body of the JSON request and unmarshal it into the blacklistBody struct.
Expand All @@ -152,6 +159,14 @@
return
}

span.SetAttributes(attribute.String("type", blacklistBody.TypeReq))
span.SetAttributes(attribute.String("id", blacklistBody.ID))
span.SetAttributes(attribute.String("data", blacklistBody.Data))
span.SetAttributes(attribute.String("network", blacklistBody.Network))
span.SetAttributes(attribute.String("tag", blacklistBody.Tag))
span.SetAttributes(attribute.String("remark", blacklistBody.Remark))
span.SetAttributes(attribute.String("address", blacklistBody.Address))

blacklistedAddress := db.BlacklistedAddress{
TypeReq: blacklistBody.TypeReq,
ID: blacklistBody.ID,
Expand All @@ -164,7 +179,8 @@

switch blacklistBody.TypeReq {
case "create":
if err := s.db.PutBlacklistedAddress(c, blacklistedAddress); err != nil {
if err := s.db.PutBlacklistedAddress(ctx, blacklistedAddress); err != nil {
span.AddEvent("error", trace.WithAttributes(attribute.String("error", err.Error())))

Check warning on line 183 in contrib/screener-api/screener/screener.go

View check run for this annotation

Codecov / codecov/patch

contrib/screener-api/screener/screener.go#L183

Added line #L183 was not covered by tests
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
Expand Down Expand Up @@ -262,7 +278,7 @@
// @Success 200 {object} map[string]bool "Returns the risk assessment result"
// @Failure 400 {object} map[string]string "Returns error if the required parameters are missing or invalid"
// @Failure 500 {object} map[string]string "Returns error if there are problems processing the indicators"
// @Router /screen/{ruleset}/{address} [get]
// @Router /screen/{ruleset}/{address} [get].
func (s *screenerImpl) screenAddress(c *gin.Context) {
var err error

Expand Down
Loading