Skip to content

feat(http): improve error logging with client IP#7503

Open
maximk777 wants to merge 4 commits intoGreptimeTeam:mainfrom
maximk777:feat/http-error-logging
Open

feat(http): improve error logging with client IP#7503
maximk777 wants to merge 4 commits intoGreptimeTeam:mainfrom
maximk777:feat/http-error-logging

Conversation

@maximk777
Copy link

@maximk777 maximk777 commented Dec 30, 2025

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

Closes #7328

What's changed and what's your intention?

This PR improves HTTP error logging as requested in #7328.

  1. ErrorResponse::from_error_message() now logs errors (error_result.rs)

Previously, from_error_message() created error responses without logging, while from_error() did log. This meant handlers using from_error_message() directly bypassed the logging mechanism.
Now both methods log consistently:

  • error! level for server errors (where should_log_error() returns true)
  • debug! level for client errors (e.g., InvalidArguments)
  1. New middleware log_error_with_client_ip (client_ip.rs)

Added middleware that logs all 4xx/5xx responses with client IP address.

  1. Enabled ConnectInfo in HTTP server (http.rs)

Changed into_make_service() to into_make_service_with_connect_info::() to make client IP available in request extensions.

Limitations:

Client IP may not be available in tests (middleware handles this gracefully by logging without IP)

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.

    Logging behavior was verified manually.

  • This PR requires documentation updates. (Not required - internal changes only)
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

@maximk777 maximk777 requested a review from a team as a code owner December 30, 2025 23:06
@github-actions github-actions bot added size/XS docs-not-required This change does not impact docs. labels Dec 30, 2025
@maximk777 maximk777 force-pushed the feat/http-error-logging branch from 8a1b081 to cffbbc3 Compare December 30, 2025 23:14
@yihong0618
Copy link
Collaborator

I think we add a new function here, add a unittest for it would be better

- Add logging to ErrorResponse::from_error_message()
- Add middleware to log HTTP errors with client IP

Closes GreptimeTeam#7328

Signed-off-by: maximk777 <maximkirienkov777@gmail.com>
@maximk777 maximk777 force-pushed the feat/http-error-logging branch from cffbbc3 to 5a86ec8 Compare December 31, 2025 08:51
@github-actions github-actions bot added size/S and removed size/XS labels Dec 31, 2025
@maximk777
Copy link
Author

Done! Added unit tests for the middleware.

Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

I have also found one place missing the error log:

impl IntoResponse for PrometheusJsonResponse {
fn into_response(self) -> Response {
let metrics = if self.resp_metrics.is_empty() {
None
} else {
serde_json::to_string(&self.resp_metrics).ok()
};
let http_code = self.status_code.map(|c| status_code_to_http_status(&c));

Could you also add it for the PrometheusJsonResponse?

@MichaelScofield MichaelScofield marked this pull request as draft January 19, 2026 03:19
evenyag added 2 commits March 13, 2026 17:40
Restore rich Debug logging in from_error(), add URI/method/matched path
to client IP middleware, and only log when client address is available.

Signed-off-by: evenyag <realevenyag@gmail.com>
…ging

Signed-off-by: evenyag <realevenyag@gmail.com>

# Conflicts:
#	src/servers/src/http.rs
@evenyag evenyag marked this pull request as ready for review March 13, 2026 13:36
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44166133cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 883 to +886
authorize::check_http_auth,
))
.layer(middleware::from_fn(hints::extract_hints))
.layer(middleware::from_fn(client_ip::log_error_with_client_ip))

Choose a reason for hiding this comment

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

P2 Badge Move client-IP error logger ahead of auth short-circuit

Placing log_error_with_client_ip after the auth middleware means any response that authorize::check_http_auth returns directly (for example 401/403 from missing or invalid credentials) never reaches this logger, so those error responses are not logged with client address. This is a behavior gap for real traffic where auth rejects requests, and it contradicts the intended “log 4xx/5xx with client IP” coverage.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP handler error log improvement

3 participants