Skip to content

Commit

Permalink
add more tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
golangisfun123 committed May 28, 2024
1 parent 5623b32 commit af00f8c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions contrib/screener-api/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,28 @@ 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

case "update":
if err := s.db.UpdateBlacklistedAddress(c, blacklistedAddress.ID, blacklistedAddress); err != nil {
if err := s.db.UpdateBlacklistedAddress(ctx, blacklistedAddress.ID, blacklistedAddress); err != nil {
span.AddEvent("error", trace.WithAttributes(attribute.String("error", err.Error())))

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L193 was not covered by tests
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

case "delete":
if err := s.db.DeleteBlacklistedAddress(c, blacklistedAddress.Address); err != nil {
if err := s.db.DeleteBlacklistedAddress(ctx, blacklistedAddress.Address); err != nil {
span.AddEvent("error", trace.WithAttributes(attribute.String("error", err.Error())))

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L203 was not covered by tests
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 @@ -220,6 +221,7 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {
func (s *screenerImpl) authMiddleware(cfg config.Config) gin.HandlerFunc {
return func(c *gin.Context) {
_, span := s.metrics.Tracer().Start(c.Request.Context(), "authMiddleware")
defer span.End()

appID := c.Request.Header.Get("AppID")
timestamp := c.Request.Header.Get("Timestamp")
Expand All @@ -243,11 +245,11 @@ func (s *screenerImpl) authMiddleware(cfg config.Config) gin.HandlerFunc {
expectedSignature := client.GenerateSignature(cfg.AppSecret, message)

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
}

c.Next()
}
}
Expand Down

0 comments on commit af00f8c

Please sign in to comment.