Skip to content

Commit

Permalink
feat(fxcore): Updated panic recovery to prevent observability middlew…
Browse files Browse the repository at this point in the history
…ares interruption (#214)
  • Loading branch information
ekkinox authored Apr 17, 2024
1 parent e13711a commit 06f3ba8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions fxcore/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ require (
github.com/ankorstore/yokai/fxtrace v1.2.0
github.com/ankorstore/yokai/generate v1.1.0
github.com/ankorstore/yokai/healthcheck v1.1.0
github.com/ankorstore/yokai/httpserver v1.4.1
github.com/ankorstore/yokai/httpserver v1.5.0
github.com/ankorstore/yokai/log v1.2.0
github.com/ankorstore/yokai/trace v1.2.0
github.com/ankorstore/yokai/trace v1.3.0
github.com/arl/statsviz v0.6.0
github.com/labstack/echo/v4 v4.11.4
github.com/labstack/gommon v0.4.2
github.com/prometheus/client_golang v1.19.0
github.com/rs/zerolog v1.32.0
github.com/stretchr/testify v1.9.0
Expand All @@ -40,7 +41,6 @@ require (
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
8 changes: 4 additions & 4 deletions fxcore/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ github.com/ankorstore/yokai/generate v1.1.0 h1:tu3S+uEYh+2qNo8Rf/WxWneDjh49YgDPz
github.com/ankorstore/yokai/generate v1.1.0/go.mod h1:gqS/i20wnvCOhcXydYdiGcASzBaeuW7GK6YYg/kkuY4=
github.com/ankorstore/yokai/healthcheck v1.1.0 h1:PXkEccym7iaVnQltpM5UFi0Xl0n+5rZDzlQju6HmGms=
github.com/ankorstore/yokai/healthcheck v1.1.0/go.mod h1:IiYgjRa4G3OLZMwAuacuryZZAfDHsBH8PQoK4PgRdZ4=
github.com/ankorstore/yokai/httpserver v1.4.1 h1:Zz25h6fYvRsJ+1TtnbJP2fO4Dt/tD3+Kgqs2QkpCJzw=
github.com/ankorstore/yokai/httpserver v1.4.1/go.mod h1:AOCL4cK2bPKrtGFULvOvc8mKHAOw2bLW30CKJra2BB0=
github.com/ankorstore/yokai/httpserver v1.5.0 h1:42nfCFCGWuBKbwU8Jhlf1/ofrezDes8HlCa0mhiVoI8=
github.com/ankorstore/yokai/httpserver v1.5.0/go.mod h1:AOCL4cK2bPKrtGFULvOvc8mKHAOw2bLW30CKJra2BB0=
github.com/ankorstore/yokai/log v1.2.0 h1:jiuDiC0dtqIGIOsFQslUHYoFJ1qjI+rOMa6dI1LBf2Y=
github.com/ankorstore/yokai/log v1.2.0/go.mod h1:MVvUcms1AYGo0BT6l88B9KJdvtK6/qGKdgyKVXfbmyc=
github.com/ankorstore/yokai/trace v1.2.0 h1:Jnl++IGNpDYumsZJXP3qjhMdvyHbejiajQwIlU604w0=
github.com/ankorstore/yokai/trace v1.2.0/go.mod h1:m7EL2MRBilgCtrly5gA4F0jkGSXR2EbG6LsotbTJ4nA=
github.com/ankorstore/yokai/trace v1.3.0 h1:0ji32oymIcxTmH5h6GRWLo5ypwBbWrZkXRf9rWF9070=
github.com/ankorstore/yokai/trace v1.3.0/go.mod h1:m7EL2MRBilgCtrly5gA4F0jkGSXR2EbG6LsotbTJ4nA=
github.com/arl/statsviz v0.6.0 h1:jbW1QJkEYQkufd//4NDYRSNBpwJNrdzPahF7ZmoGdyE=
github.com/arl/statsviz v0.6.0/go.mod h1:0toboo+YGSUXDaS4g1D5TVS4dXs7S7YYT5J/qnW2h8s=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
11 changes: 8 additions & 3 deletions fxcore/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"net/http"
"strconv"

"github.com/labstack/echo/v4"

"github.com/ankorstore/yokai/config"
"github.com/ankorstore/yokai/fxconfig"
"github.com/ankorstore/yokai/fxgenerate"
Expand All @@ -23,7 +21,9 @@ import (
httpservermiddleware "github.com/ankorstore/yokai/httpserver/middleware"
"github.com/ankorstore/yokai/log"
"github.com/arl/statsviz"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
gommonlog "github.com/labstack/gommon/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
oteltrace "go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -109,7 +109,6 @@ func NewFxCore(p FxCoreParam) (*Core, error) {
coreServer, err := httpserver.NewDefaultHttpServerFactory().Create(
httpserver.WithDebug(appDebug),
httpserver.WithBanner(false),
httpserver.WithRecovery(true),
httpserver.WithLogger(coreLogger),
httpserver.WithRenderer(NewDashboardRenderer(templatesFS, "templates/dashboard.html")),
httpserver.WithHttpErrorHandler(
Expand Down Expand Up @@ -216,6 +215,12 @@ func withMiddlewares(coreServer *echo.Echo, p FxCoreParam) *echo.Echo {
coreServer.Use(httpservermiddleware.RequestMetricsMiddlewareWithConfig(metricsMiddlewareConfig))
}

// recovery middleware
coreServer.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
DisableErrorHandler: true,
LogLevel: gommonlog.ERROR,
}))

return coreServer
}

Expand Down

0 comments on commit 06f3ba8

Please sign in to comment.