fix: add comprehensive logging to track startup hooks
- Added logging when HTTP server OnStart hook is called - Added error logging for database migration failures - This will help identify if hooks are being called and where failures occur
This commit is contained in:
@@ -110,6 +110,9 @@ func ProvideDatabase() fx.Option {
|
|||||||
// Run migrations on startup
|
// Run migrations on startup
|
||||||
log.Info("Running database migrations...")
|
log.Info("Running database migrations...")
|
||||||
if err := dbClient.Migrate(ctx); err != nil {
|
if err := dbClient.Migrate(ctx); err != nil {
|
||||||
|
log.Error("Database migrations failed",
|
||||||
|
logger.Error(err),
|
||||||
|
)
|
||||||
return fmt.Errorf("failed to run database migrations: %w", err)
|
return fmt.Errorf("failed to run database migrations: %w", err)
|
||||||
}
|
}
|
||||||
log.Info("Database migrations completed successfully")
|
log.Info("Database migrations completed successfully")
|
||||||
@@ -227,6 +230,8 @@ func ProvideHTTPServer() fx.Option {
|
|||||||
// Register lifecycle hooks
|
// Register lifecycle hooks
|
||||||
lc.Append(fx.Hook{
|
lc.Append(fx.Hook{
|
||||||
OnStart: func(ctx context.Context) error {
|
OnStart: func(ctx context.Context) error {
|
||||||
|
log.Info("HTTP server OnStart hook called")
|
||||||
|
|
||||||
// Get server address from config
|
// Get server address from config
|
||||||
port := cfg.GetInt("server.port")
|
port := cfg.GetInt("server.port")
|
||||||
if port == 0 {
|
if port == 0 {
|
||||||
@@ -279,7 +284,7 @@ func ProvideHTTPServer() fx.Option {
|
|||||||
} else {
|
} else {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("HTTP server started successfully",
|
log.Info("HTTP server started successfully",
|
||||||
logger.String("addr", addr),
|
logger.String("addr", addr),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
|
|
||||||
"go.opentelemetry.io/otel/trace"
|
|
||||||
"git.dcentral.systems/toolz/goplt/internal/health"
|
"git.dcentral.systems/toolz/goplt/internal/health"
|
||||||
"git.dcentral.systems/toolz/goplt/internal/metrics"
|
"git.dcentral.systems/toolz/goplt/internal/metrics"
|
||||||
"git.dcentral.systems/toolz/goplt/pkg/config"
|
"git.dcentral.systems/toolz/goplt/pkg/config"
|
||||||
"git.dcentral.systems/toolz/goplt/pkg/errorbus"
|
"git.dcentral.systems/toolz/goplt/pkg/errorbus"
|
||||||
"git.dcentral.systems/toolz/goplt/pkg/logger"
|
"git.dcentral.systems/toolz/goplt/pkg/logger"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server wraps the HTTP server and Gin router.
|
// Server wraps the HTTP server and Gin router.
|
||||||
@@ -149,4 +149,3 @@ func (s *Server) Shutdown(ctx context.Context) error {
|
|||||||
func (s *Server) Router() *gin.Engine {
|
func (s *Server) Router() *gin.Engine {
|
||||||
return s.router
|
return s.router
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user