Skip to content

Commit

Permalink
mroe tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
golangisfun123 committed May 28, 2024
1 parent af00f8c commit c5b5674
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions contrib/screener-api/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

span.AddEvent("blacklistedAddress", trace.WithAttributes(attribute.String("address", blacklistBody.Address)))
c.JSON(http.StatusOK, gin.H{"status": "success"})
return
Expand All @@ -194,6 +195,7 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

span.AddEvent("blacklistedAddress", trace.WithAttributes(attribute.String("address", blacklistBody.Address)))
c.JSON(http.StatusOK, gin.H{"status": "success"})
return
Expand Down Expand Up @@ -233,23 +235,32 @@ func (s *screenerImpl) authMiddleware(cfg config.Config) gin.HandlerFunc {

c.Request.Body = io.NopCloser(strings.NewReader(bodyStr))

span.SetAttributes(attribute.String("appId", appID))
span.SetAttributes(attribute.String("timestamp", timestamp))
span.SetAttributes(attribute.String("nonce", nonce))
span.SetAttributes(attribute.String("signature", signature))
span.SetAttributes(attribute.String("bodyString", bodyStr))
span.SetAttributes(
attribute.String("appId", appID),
attribute.String("timestamp", timestamp),
attribute.String("nonce", nonce),
attribute.String("signature", signature),
attribute.String("queryString", queryString),
attribute.String("bodyString", bodyStr),
)

message := fmt.Sprintf("%s%s%s%s%s%s%s",
appID, timestamp, nonce, "POST", "/api/data/sync/", queryString, bodyStr)

span.AddEvent("message", trace.WithAttributes(attribute.String("message", message)))

expectedSignature := client.GenerateSignature(cfg.AppSecret, message)

span.AddEvent("generated_signature", trace.WithAttributes(attribute.String("expectedSignature", expectedSignature)))

if expectedSignature != signature {
span.AddEvent("error", trace.WithAttributes(attribute.String("error", "Invalid signature")))
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid signature"})
c.Abort()
return
}

span.AddEvent("signature_validated")
c.Next()
}
}
Expand Down

0 comments on commit c5b5674

Please sign in to comment.