Skip to content

feat(logger): add HTTP request/response logging fields#2450

Open
AdaAibaby wants to merge 6 commits intoe2b-dev:mainfrom
AdaAibaby:feature-logger
Open

feat(logger): add HTTP request/response logging fields#2450
AdaAibaby wants to merge 6 commits intoe2b-dev:mainfrom
AdaAibaby:feature-logger

Conversation

@AdaAibaby
Copy link
Copy Markdown

Summary

Add structured HTTP request/response logging fields to the logger package.

This PR introduces reusable zap logger fields for standard HTTP metadata:

  • Request ID tracing (X-Request-ID, X-Trace-ID, X-Correlation-ID)
  • HTTP version
  • Request/response body size
  • API operation (method + path)
  • Remote client IP with proxy header support
  • Cache status
  • Structured API error object
  • HTTP status code to error code mapping

All functions are fully covered by unit tests.

Changes

  • Added request_fields.go – HTTP logging field functions
  • Added request_fields_test.go – comprehensive test suite

Testing

  • All unit tests pass
  • Coverage: 32.6%
  • Verified cross-environment stability

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copy link
Copy Markdown

@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: 6f4f807c07

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/shared/pkg/logger/request_fields.go Outdated
Comment thread packages/shared/pkg/logger/request_fields.go Outdated
Comment thread packages/shared/pkg/logger/request_fields.go Outdated
@jakubno
Copy link
Copy Markdown
Member

jakubno commented Apr 20, 2026

@AdaAibaby could you add motivation for this? I don't see the methods used anywhere

@AdaAibaby
Copy link
Copy Markdown
Author

AdaAibaby commented Apr 21, 2026

@AdaAibaby could you add motivation for this? I don't see the methods used anywhere

@jakubno Thanks for the feedback! You're right that these methods aren't used yet in the current codebase.

Motivation and Context:
This stems from debugging a 502 error in the dashboard. After investigation, the issue was traced to the LB returning a static page (see GitHub issue #1262), but I noticed that when the dashboard returns a 502, the API responses lacked clear, structured logging for request metadata. This made it hard to diagnose distributed tracing, client IPs, request sizes, and error codes in production logs.

These functions (WithRequestID, WithRemoteIP, WithAPIError, etc.) provide standardized Zap logging fields for HTTP requests, enabling structured logging of key metadata (e.g., request IDs from headers like X-Request-ID/X-Trace-ID, real client IPs from X-Forwarded-For, API operations, and error codes). They follow Zap best practices and prepare the codebase for better observability, making future debugging of issues like 502s much easier by ensuring consistent, searchable logs.

While not integrated yet, they're designed for use in HTTP middleware or handlers (e.g., in packages/dashboard-api/internal/handlers/). For example, we could add them to request logging like:

logger.Info("Request processed", 
    request_fields.WithRequestID(r),
    request_fields.WithRemoteIP(r),
    request_fields.WithAPIError("INTERNAL_ERROR", "upstream failure"),
)

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.

5 participants