-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add stack trace logging for internal server errors (500) #2204
Add stack trace logging for internal server errors (500) #2204
Conversation
Hi @kevkevinpal, Please review this PR. |
routes/index.go
Outdated
@@ -145,17 +147,27 @@ func getFromAuth(path string) (*extractResponse, error) { | |||
// Middleware to handle InternalServerError | |||
func internalServerErrorHandler(next http.Handler) http.Handler { | |||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |||
fmt.Println("Inside Internal Server Middleware") |
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.
can you remove this comment it would unnecessarily flood the logs for every request
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.
@kevkevinpal Sure
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.
@kevkevinpal Done.
routes/test_routes.go
Outdated
r := chi.NewRouter() | ||
|
||
r.Get("/internal-server-error", func(w http.ResponseWriter, r *http.Request) { | ||
http.Error(w, "Forced internal server error", http.StatusInternalServerError) |
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.
instead of sending back http.Error can you try doing a try: except but forcing the exception
right now when I look at the stacktrace I expect it to come from this test_routes.go file but its grabbing the stacktrace from in the middleware
this is the output I got
Internal Server Error: GET /test/internal-server-error
Stack Trace:
goroutine 53 [running]:
github.com/stakwork/sphinx-tribes/routes.internalServerErrorHandler.func1({0x7f6acd306f30, 0xc000394fc0}, 0xc000371440)
/mnt/shared_drive/DEVDIR/sphinx-tribes/routes/index.go:157 +0x187
net/http.HandlerFunc.ServeHTTP(0x413ea5?, {0x7f6acd306f30?, 0xc000394fc0?}, 0x2239a01?)
/usr/local/go/src/net/http/server.go:2171 +0x29
github.com/go-chi/chi/middleware.Recoverer.func1({0x7f6acd306f30?, 0xc000394fc0?}, 0xc00061bce0?)
/home/kevkevin/go/pkg/mod/github.com/go-chi/[email protected]/middleware/recoverer.go:37 +0x78
net/http.HandlerFunc.ServeHTTP(0x22556e0?, {0x7f6acd306f30?, 0xc000394fc0?}, 0x18?)
/usr/local/go/src/net/http/server.go:2171 +0x29
github.com/go-chi/chi/middleware.init.0.RequestLogger.func1.1({0x18b0e70, 0xc0002ba8c0}, 0xc000370ea0)
/home/kevkevin/go/pkg/mod/github.com/go-chi/[email protected]/middleware/logger.go:57 +0x16a
net/http.HandlerFunc.ServeHTTP(0x18b2f30?, {0x18b0e70?, 0xc0002ba8c0?}, 0x1897ce0?)
/usr/local/go/src/net/http/server.go:2171 +0x29
github.com/go-chi/chi/middleware.
2024/12/16 17:23:43 [fedora/NwyCgyx1sr-000003] "GET http://100.97.107.124:5002/test/internal-server-error HTTP/1.1" from 100.89.29.16:59100 - 500 51B in 250.927µs
Hi @kevkevinpal, please review this PR. If anything is needed, please let me know. |
The new commits look good! This is the new error I see now
I will create a new issue to replace the places where we just throw internal server error and instead use a panic instead
|
Describe your changes
Issue ticket number and link: #2186
Closed: #2186
Type of change
Please delete options that are not relevant.
Checklist before requesting a review