feat(api): add HTTP access request logging#3711
Open
abh wants to merge 4 commits intosemaphoreui:developfrom
Open
feat(api): add HTTP access request logging#3711abh wants to merge 4 commits intosemaphoreui:developfrom
abh wants to merge 4 commits intosemaphoreui:developfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds structured HTTP access logging to the API server so each request is logged with method/path/status/duration/remote address.
Changes:
- Introduce
api.AccessLogMiddlewareto log request/response metadata via logrus fields. - Wire the middleware into the main HTTP handler chain in
runService().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
cli/cmd/root.go |
Wraps the main router with the new access log middleware and ProxyHeaders. |
api/access_log.go |
Implements AccessLogMiddleware and a ResponseWriter wrapper to capture status codes. |
Add AccessLogMiddleware using gorilla/handlers.CustomLoggingHandler to log HTTP requests with structured logrus fields (method, path, status, size, duration, remote addr). Skip /api/ping to avoid noise.
Contributor
Author
|
I made a new implementation to address the copilot feedback. |
Verify that the middleware emits structured log fields (method, path, status, size, duration, remote) and that /api/ping requests are excluded from logging.
Use strings.HasSuffix so the ping health check is also skipped when the app is served under a non-root web path (e.g. /semaphore/api/ping).
Collaborator
|
I think it should be debug, not info |
Contributor
Author
|
@fiftin I updated it to debug. |
Comment on lines
+51
to
+56
| func TestAccessLogMiddleware_SkipsPing(t *testing.T) { | ||
| hook := test.NewLocal(log.StandardLogger()) | ||
|
|
||
| handler := AccessLogMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log every HTTP request with method, path, status code, duration, and
remote address using logrus structured fields. Middleware is placed
after ProxyHeaders so remote address reflects X-Forwarded-For.
/api/ping health checks are not logged.