Skip to content

feat(api): add HTTP access request logging#3711

Open
abh wants to merge 4 commits intosemaphoreui:developfrom
abh:request-logging
Open

feat(api): add HTTP access request logging#3711
abh wants to merge 4 commits intosemaphoreui:developfrom
abh:request-logging

Conversation

@abh
Copy link
Copy Markdown
Contributor

@abh abh commented Mar 22, 2026

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.

Copilot AI review requested due to automatic review settings March 22, 2026 05:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.AccessLogMiddleware to 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.

Comment thread api/access_log.go Outdated
Comment thread api/access_log.go Outdated
Comment thread cli/cmd/root.go
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.
@abh abh force-pushed the request-logging branch from 9476d15 to 809eb20 Compare March 22, 2026 06:19
@abh abh requested a review from Copilot March 22, 2026 06:20
@abh
Copy link
Copy Markdown
Contributor Author

abh commented Mar 22, 2026

I made a new implementation to address the copilot feedback.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread api/access_log.go Outdated
Comment thread api/access_log.go
Verify that the middleware emits structured log fields (method, path,
status, size, duration, remote) and that /api/ping requests are excluded
from logging.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread api/access_log.go Outdated
Comment thread api/access_log_test.go
Comment thread cli/cmd/root.go
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).
@fiftin
Copy link
Copy Markdown
Collaborator

fiftin commented Mar 23, 2026

I think it should be debug, not info

@abh
Copy link
Copy Markdown
Contributor Author

abh commented Apr 13, 2026

@fiftin I updated it to debug.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread api/access_log_test.go
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)
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants