Skip to content

Master gateway error log#1371

Open
ritikegov wants to merge 5 commits into
masterfrom
master-gateway-error-log
Open

Master gateway error log#1371
ritikegov wants to merge 5 commits into
masterfrom
master-gateway-error-log

Conversation

@ritikegov

@ritikegov ritikegov commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Error events can now be captured and sent to the gateway’s logging pipeline, including request details, status, timing, and response body.
    • Request logs now include a unique identifier field.
  • Bug Fixes

    • Improved error handling so failures while recording error events do not interrupt the normal error response.
    • Added support for excluding specific URL prefixes from error capture.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The gateway's ExceptionUtils class is converted into a Spring component that injects a Kafka Producer and configuration values to publish error events. ErrorFilter now uses an injected ExceptionUtils instance instead of a static call. EventLogRequest gains an id field, and application.properties adds error logging configuration (enable flag, topic, URL blacklist).

Changes

Gateway error event logging

Layer / File(s) Summary
ExceptionUtils component conversion and event publishing
core-services/gateway/.../utils/ExceptionUtils.java, core-services/gateway/.../model/EventLogRequest.java
ExceptionUtils becomes a @Component with injected Producer and @Value configuration (enable flag, topic, blacklist); raiseErrorFilterException becomes an instance method; a new pushErrorEvent builds an EventLogRequest (now including an id field) with request metadata and publishes it to Kafka before the error response body is written, skipping when disabled or blacklisted, catching publish failures.
ErrorFilter wiring to injected ExceptionUtils
core-services/gateway/.../filters/error/ErrorFilter.java
ErrorFilter autowires an ExceptionUtils field and calls the instance method inside onErrorResume instead of a static import; unused imports removed.
Error logging configuration properties
core-services/gateway/src/main/resources/application.properties
Adds errorlog.enabled=false, errorlog.topic, and an empty errorlog.urls.blacklist with an explanatory comment.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ErrorFilter
  participant ExceptionUtils
  participant Producer
  participant Kafka

  ErrorFilter->>ExceptionUtils: raiseErrorFilterException(exchange, e)
  ExceptionUtils->>ExceptionUtils: _setExceptionBody(exchange, e)
  ExceptionUtils->>ExceptionUtils: pushErrorEvent(exchange, e)
  alt errorLogEnabled and not blacklisted
    ExceptionUtils->>ExceptionUtils: build EventLogRequest
    ExceptionUtils->>Producer: send(errorLogTopic, EventLogRequest)
    Producer->>Kafka: publish message
  else disabled or blacklisted
    ExceptionUtils-->>ExceptionUtils: skip publishing
  end
  ExceptionUtils-->>ErrorFilter: write response body
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related to the main change: adding gateway error logging support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch master-gateway-error-log

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@core-services/gateway/src/main/java/com/example/gateway/utils/ExceptionUtils.java`:
- Around line 44-45: The blacklist parsing in ExceptionUtils currently leaves
entries untrimmed and the error logging flow in pushErrorEvent still captures
sensitive data by default for any non-blacklisted URL. Update the `@Value-backed`
errorLogUrlsBlacklist handling so each comma-separated prefix is trimmed before
use, and adjust the pushErrorEvent path to avoid blindly including
queryParams/responseBody for sensitive endpoints unless explicitly allowed. Use
the existing ExceptionUtils and pushErrorEvent symbols to locate the logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: faa7ff12-2447-4ce9-85d2-9ec65c68e539

📥 Commits

Reviewing files that changed from the base of the PR and between e22c7c5 and 41af4ab.

📒 Files selected for processing (4)
  • core-services/gateway/src/main/java/com/example/gateway/filters/error/ErrorFilter.java
  • core-services/gateway/src/main/java/com/example/gateway/model/EventLogRequest.java
  • core-services/gateway/src/main/java/com/example/gateway/utils/ExceptionUtils.java
  • core-services/gateway/src/main/resources/application.properties

Comment on lines +44 to +45
@Value("#{'${errorlog.urls.blacklist:}'.split(',')}")
private List<String> errorLogUrlsBlacklist;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Opt-out blacklist defaults to "capture everything," risking sensitive data leaking into Kafka.

errorLogUrlsBlacklist defaults to empty (also confirmed by application.properties comment: "Empty = capture all"), and pushErrorEvent unconditionally captures queryParams (Line 129) and the full error responseBody (Line 136) for every non-blacklisted path once errorlog.enabled=true. The application's own egov.open-endpoints-whitelist list includes auth-sensitive endpoints (e.g. /user/oauth/token, /otp/v1/_validate, /user-otp/v1/_send), whose query params could carry tokens/OTPs. Since the model is opt-out rather than opt-in (unlike eventlog.urls.whitelist used for regular event logging), an admin who enables error logging without curating the blacklist will unintentionally persist sensitive request data to a Kafka topic.

Consider defaulting to redacting/omitting queryParams for known sensitive prefixes, or switching to an opt-in whitelist model consistent with the existing eventlog.urls.whitelist pattern.

Separately, blacklist prefixes aren't trimmed — a value like "/a, /b" yields " /b" as a prefix, which will never match /b... paths, silently breaking blacklist entries.

💡 Proposed fix for prefix trimming
-            boolean blacklisted = errorLogUrlsBlacklist.stream()
-                    .anyMatch(prefix -> !prefix.isEmpty() && requestPath.startsWith(prefix));
+            boolean blacklisted = errorLogUrlsBlacklist.stream()
+                    .map(String::trim)
+                    .anyMatch(prefix -> !prefix.isEmpty() && requestPath.startsWith(prefix));

Also applies to: 108-144

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@core-services/gateway/src/main/java/com/example/gateway/utils/ExceptionUtils.java`
around lines 44 - 45, The blacklist parsing in ExceptionUtils currently leaves
entries untrimmed and the error logging flow in pushErrorEvent still captures
sensitive data by default for any non-blacklisted URL. Update the `@Value-backed`
errorLogUrlsBlacklist handling so each comma-separated prefix is trimmed before
use, and adjust the pushErrorEvent path to avoid blindly including
queryParams/responseBody for sensitive endpoints unless explicitly allowed. Use
the existing ExceptionUtils and pushErrorEvent symbols to locate the logic.

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