-
Notifications
You must be signed in to change notification settings - Fork 614
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
feat(prover): integrate sentry to monitor error logs & panic events #1477
base: develop
Are you sure you want to change the base?
Changes from all commits
0bd20e8
a1803c1
376e300
9927cae
2956a25
bbfbfc5
09f4830
89d7f6d
53b48b8
1c31cec
ee41125
c213c0b
dd003ad
5495a73
52666a7
91fe9c8
229eef2
43fba89
2352802
fa25261
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,14 @@ package api | |
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
jwt "github.com/appleboy/gin-jwt/v2" | ||
"github.com/gin-gonic/gin" | ||
"gorm.io/gorm" | ||
|
||
commonTypes "scroll-tech/common/types" | ||
|
||
"scroll-tech/coordinator/internal/config" | ||
"scroll-tech/coordinator/internal/logic/auth" | ||
"scroll-tech/coordinator/internal/logic/verifier" | ||
|
@@ -16,12 +19,14 @@ import ( | |
|
||
// AuthController is login API | ||
type AuthController struct { | ||
cfg *config.Config | ||
loginLogic *auth.LoginLogic | ||
} | ||
|
||
// NewAuthController returns an LoginController instance | ||
func NewAuthController(db *gorm.DB, cfg *config.Config, vf *verifier.Verifier) *AuthController { | ||
return &AuthController{ | ||
cfg: cfg, | ||
loginLogic: auth.NewLoginLogic(db, cfg, vf), | ||
} | ||
} | ||
|
@@ -98,3 +103,13 @@ func (a *AuthController) IdentityHandler(c *gin.Context) interface{} { | |
|
||
return nil | ||
} | ||
|
||
// LoginResponse replies to client for /login | ||
func (a *AuthController) LoginResponse(c *gin.Context, code int, message string, time time.Time) { | ||
resp := types.LoginSchema{ | ||
Time: time, | ||
Token: message, | ||
SentryEndpoint: a.cfg.ProverManager.ProverSentryEndpoint, | ||
} | ||
commonTypes.RenderSuccess(c, resp) | ||
} | ||
Comment on lines
+108
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider these improvements to the LoginResponse method.
Here's a suggested improvement: -func (a *AuthController) LoginResponse(c *gin.Context, code int, message string, time time.Time) {
+func (a *AuthController) LoginResponse(c *gin.Context, code int, message string) {
+ if c == nil {
+ return
+ }
+ if message == "" {
+ message = "Login successful"
+ }
resp := types.LoginSchema{
- Time: time,
+ Time: time.Now(),
Token: message,
SentryEndpoint: a.cfg.ProverManager.ProverSentryEndpoint,
}
commonTypes.RenderSuccess(c, resp)
}
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,9 @@ const ( | |
|
||
// LoginSchema for /login response | ||
type LoginSchema struct { | ||
Time time.Time `json:"time"` | ||
Token string `json:"token"` | ||
Time time.Time `json:"time"` | ||
Token string `json:"token"` | ||
SentryEndpoint string `json:"sentry_endpoint,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding validation and documentation for the SentryEndpoint field. Since this field contains sensitive configuration information:
Here's a suggested improvement: type LoginSchema struct {
Time time.Time `json:"time"`
Token string `json:"token"`
- SentryEndpoint string `json:"sentry_endpoint,omitempty"`
+ // SentryEndpoint holds the URL for error reporting to Sentry.
+ // This field should not be logged or exposed in debug output.
+ // Format: https://<key>@<organization>.ingest.sentry.io/<project>
+ SentryEndpoint string `json:"sentry_endpoint,omitempty" sensitive:"true"`
} Consider adding a validation method: // ValidateSentryEndpoint ensures the endpoint URL is properly formatted
func (l *LoginSchema) ValidateSentryEndpoint() error {
if l.SentryEndpoint == "" {
return nil
}
_, err := url.Parse(l.SentryEndpoint)
if err != nil {
return fmt.Errorf("invalid sentry endpoint format: %w", err)
}
return nil
} |
||
} | ||
|
||
// Message the login message struct | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding URL validation for the Sentry endpoint.
Since this endpoint is critical for error monitoring, consider adding validation in the
NewConfig
function to ensure the URL is properly formatted when provided.Here's a suggested implementation:
Don't forget to add these imports: