Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 26 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var (
tlsDomain string
)

const (
HealthyEndpoint = "/healthy"
)

func init() {
config.BoolVar(&tlsEnabled, "tls-enabled", false, "whether tls enabled or not, bot will use Letsencrypt (also via TLS_ENABLED)")
config.StringVar(&tlsDomain, "tls-domain", "", "which domain is used for ssl certificate (also via TLS_DOMAIN)")
Expand All @@ -31,14 +35,34 @@ func init() {
func start() {
e := echo.New()

e.Use(middleware.Logger())
// Custom request logger middleware that skips /healthy endpoint
e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
Skipper: func(c echo.Context) bool {
return c.Request().URL.Path == HealthyEndpoint
},
LogURI: true,
LogStatus: true,
LogMethod: true,
LogRemoteIP: true,
LogLatency: true,
LogValuesFunc: func(c echo.Context, values middleware.RequestLoggerValues) error {
logger.Info("request",
"method", values.Method,
"uri", values.URI,
"status", values.Status,
"remote_ip", values.RemoteIP,
"latency", values.Latency,
)
return nil
},
}))
e.Use(middleware.Recover())

if logger.IsSentryEnabled() {
e.Use(sentryecho.New(sentryecho.Options{Repanic: true, WaitForDelivery: false}))
}

e.GET("/healthy", healthcheck)
e.GET(HealthyEndpoint, healthcheck)
e.POST("/mergebot/webhook/:provider/", Handler)

if tlsEnabled {
Expand Down
4 changes: 4 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func Debug(msg string, args ...any) {
slog.Debug(msg, args...)
}

func Info(msg string, args ...any) {
slog.Info(msg, args...)
}

func IsSentryEnabled() bool {
return sentryEnabled
}
Loading