Skip to content

Conversation

@kavindasr
Copy link

@kavindasr kavindasr commented Nov 12, 2025

Purpose

  • Fixes:
    • Incorrect username displayed in the fault event on the Moesif dashboard
    • Method name and URI shown as N/A

Approach

  • Fetch the username from properties
  • Add apiResourceTemplate and method to the required list

Testing

Screenshot 2025-11-12 at 12 39 42

Summary by CodeRabbit

  • Bug Fixes

    • Improved username sanitization in analytics data collection to correctly handle special identifiers.
    • Enhanced error event construction with proper API method and URI derivation.
  • New Features

    • Extended event schema to capture additional API method and resource template information for improved analytics tracking.

…to metadata and improving username sanitization
@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Walkthrough

This PR refactors username sanitization logic by extracting it into a dedicated helper method and enhances error-path event construction with more robust verb and URI derivation. Additionally, event validation schemas are extended with two new fields to support API method and resource template tracking.

Changes

Cohort / File(s) Summary
Username Sanitization & Error Path Refactoring
component/publisher-client/src/main/java/org/wso2/am/analytics/publisher/client/SimpleMoesifClient.java
Introduces new sanitizeUserName(Map<String, Object>) helper method that extracts usernames from data or properties and removes @carbon.super suffix; replaces inline username logic in success path. Error path now derives verb from API_METHOD with fallback to NOT_APPLICABLE, and constructs request URI from API_CONTEXT + API_RESOURCE_TEMPLATE or overrides with GATEWAY_URL if present.
Schema Field Extensions
component/publisher-client/src/main/java/org/wso2/am/analytics/publisher/reporter/GenericInputValidator.java
Adds API_METHOD and API_RESOURCE_TEMPLATE fields to both defaultResponseEventSchema and moesifFaultEventSchema to support enhanced API metadata collection in validation schemas.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • SimpleMoesifClient.java: Review the new sanitizeUserName() method logic for correctness, verify error path URI and verb construction handles all edge cases (empty values, fallback chains), and ensure the refactored success path behaves identically to the original
  • GenericInputValidator.java: Verify field additions in both schemas don't conflict with existing validation logic and that field names align with their usage in SimpleMoesifClient

Poem

🐰 A sanitizer born to scrub away,
Those pesky carbon.super marks of day!
With schemas extended, our validators shine,
API methods and templates now align!
Through error paths we gracefully refine.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete; it lacks many required template sections including Goals, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, and others. Complete the PR description using the provided template. At minimum, add Goals, Release note, Documentation, Security checks, and Automation tests sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main changes: fixing username and path issues in Moesif fault events, matching the core objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

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

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1 N
#### Log Improvement Suggestion No: 2 N

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3df621f and 8905146.

📒 Files selected for processing (2)
  • component/publisher-client/src/main/java/org/wso2/am/analytics/publisher/client/SimpleMoesifClient.java (3 hunks)
  • component/publisher-client/src/main/java/org/wso2/am/analytics/publisher/reporter/GenericInputValidator.java (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
component/publisher-client/src/main/java/org/wso2/am/analytics/publisher/client/SimpleMoesifClient.java (1)
component/publisher-client/src/main/java/org/wso2/am/analytics/publisher/util/Constants.java (1)
  • Constants (24-145)

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.

1 participant