Skip to content

Conversation

@ManojTestsigma
Copy link
Contributor

@ManojTestsigma ManojTestsigma commented Jul 25, 2025

Jira

https://testsigma.atlassian.net/browse/TE-28689
https://testsigma.atlassian.net/browse/TE-28600

Addon Name: Store Network Logs Data
account : appini.akhil@testsigma.com
Jarvis Link: https://jarvis.testsigma.com/ui/tenants/2817/addons

fix

  1. Added NLP to get the status code from the network logs.
  2. Fixed issue with file getting overwritten.

Summary by CodeRabbit

  • New Features

    • Introduced functionality to retrieve and store the HTTP status code of a tracked network request.
    • Added the ability to extract and save specific request header values from network logs.
  • Refactor

    • Unified network data storage to capture status code, request headers, and response body together for improved tracking.
    • Enhanced logging and error handling for network data extraction and storage.
  • Chores

    • Updated project version to 1.0.4.

@coderabbitai
Copy link

coderabbitai bot commented Jul 25, 2025

Walkthrough

The changes update the Maven project version, introduce a new action to retrieve HTTP status codes, refactor network tracking to consolidate request and response data handling, and significantly enhance the utility class for managing network data. The focus shifts to handling headers and status codes, with improved error handling and logging throughout.

Changes

File(s) Change Summary
store_network_logs_data/pom.xml Updated Maven project version from 1.0.2 to 1.0.4.
store_network_logs_data/src/main/java/com/testsigma/addons/web/GetDataFromRequestBody.java Refactored: Now retrieves specific header value instead of parsing request body JSON. Removed JSON traversal.
store_network_logs_data/src/main/java/com/testsigma/addons/web/GetStatusCode.java Added: New action class to fetch and store HTTP status code for a stored URL.
store_network_logs_data/src/main/java/com/testsigma/addons/web/StartTracking.java Refactored: Unified request/response interception; now captures headers, status code, and response body together.
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java Major refactor: Enhanced to handle headers and status codes. Added multiple new methods for granular data access and storage, improved logging and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant StartTracking
    participant ResponseDataUtilities
    participant Network
    participant Logger

    StartTracking->>Network: Intercept request
    Network-->>StartTracking: Provide request URL, method, headers
    StartTracking->>ResponseDataUtilities: addRequestHeadersData(runId, headers, logger)
    StartTracking->>Network: Wait for response
    Network-->>StartTracking: Provide response status, headers, body
    StartTracking->>ResponseDataUtilities: addAllNetworkData(runId, statusCode, headers, responseBody, logger)
    StartTracking->>Logger: Log all network data
Loading
sequenceDiagram
    participant GetStatusCode
    participant ResponseDataUtilities
    participant Logger

    GetStatusCode->>ResponseDataUtilities: getStatusCodeData(runId, logger)
    ResponseDataUtilities-->>GetStatusCode: Return status code or error
    GetStatusCode->>Logger: Log result
    GetStatusCode->>RuntimeVar: Store status code
Loading
sequenceDiagram
    participant GetDataFromRequestBody
    participant ResponseDataUtilities
    participant Logger

    GetDataFromRequestBody->>ResponseDataUtilities: getSpecificHeaderValue(runId, headerKey, logger)
    ResponseDataUtilities-->>GetDataFromRequestBody: Return header value or error
    GetDataFromRequestBody->>Logger: Log header value
    GetDataFromRequestBody->>RuntimeVar: Store header value
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Poem

In the warren of code, a new path unfurled,
Headers and status codes now briskly swirled.
With paws on the logs and a nose for the flow,
The rabbit records all the data you know.
From version hops to network hops,
This fluffy review never stops!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch TE-28689

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 3

🔭 Outside diff range comments (1)
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java (1)

16-26: Add synchronization to prevent concurrent file‐write conflicts

A search across the codebase shows no existing locks or synchronized blocks in ResponseDataUtilities or FileUtilities, so simultaneous calls to saveAllData(runId, …) can corrupt the file for the same runId.

Please update store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java (lines 16–26) to serialize access, for example:
• Use a per-runId lock map or a static lock around FileUtilities.writeToFile
• Or acquire a FileChannel.lock() before writing

Example sketch:

private static final ConcurrentMap<Long, Object> runLocks = new ConcurrentHashMap<>();
private static void saveAllData(Long runId, JsonObject jsonObject, Logger logger) throws Exception {
  Object lock = runLocks.computeIfAbsent(runId, id -> new Object());
  synchronized (lock) {
    logger.info("Saving data for the current testcase " + jsonObject);
    String json = gson.toJson(jsonObject);
    String encoded = Base64.getEncoder().encodeToString(json.getBytes());
    FileUtilities.writeToFile(runId, encoded);
  }
}

– Adjust FileUtilities if it already manages files without locking
– Clean up runLocks entries if you expect many runIds

🧹 Nitpick comments (4)
store_network_logs_data/src/main/java/com/testsigma/addons/web/GetDataFromRequestBody.java (1)

18-22: Consider renaming the class to match its actual functionality.

The class name GetDataFromRequestBody suggests it extracts data from request body, but the action text and implementation clearly indicate it extracts header values. This naming inconsistency could confuse users and developers.

Consider renaming the class to GetDataFromRequestHeader or ExtractRequestHeaderValue to better reflect its actual functionality.

store_network_logs_data/src/main/java/com/testsigma/addons/web/StartTracking.java (1)

89-97: Fallback header mechanism may not represent actual request headers.

The fallback mechanism creates synthetic headers (:method:, :path:, :scheme:) when actual headers are missing. While this prevents empty headers, these synthetic headers may not accurately represent the actual HTTP request headers sent by the browser.

Consider logging a warning when using fallback headers to make it clear that these are not the actual request headers:

+                        logger.warn("Using fallback headers as actual request headers were not available");
store_network_logs_data/src/main/java/com/testsigma/addons/web/GetStatusCode.java (2)

31-31: Remove unused variable declaration.

The result variable is declared but never used in the method. The method directly returns Result.SUCCESS or Result.FAILED.

-            Result result = Result.SUCCESS;

15-17: Consider making the runtime variable name configurable.

The action text hardcodes the runtime variable name to "status_code", but the implementation allows for a configurable variable name via the statusCodeVariable field. This could confuse users who expect to use a different variable name.

Consider updating the action text to be more generic:

-@Action(actionText = "get the status code of the stored URL and store it in runtime variable status_code",
+@Action(actionText = "get the status code of the stored URL and store it in runtime variable variable_name",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 045a344 and 72fe81c.

📒 Files selected for processing (5)
  • store_network_logs_data/pom.xml (1 hunks)
  • store_network_logs_data/src/main/java/com/testsigma/addons/web/GetDataFromRequestBody.java (2 hunks)
  • store_network_logs_data/src/main/java/com/testsigma/addons/web/GetStatusCode.java (1 hunks)
  • store_network_logs_data/src/main/java/com/testsigma/addons/web/StartTracking.java (5 hunks)
  • store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
store_network_logs_data/src/main/java/com/testsigma/addons/web/GetDataFromRequestBody.java (1)
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java (1)
  • ResponseDataUtilities (12-217)
store_network_logs_data/src/main/java/com/testsigma/addons/web/GetStatusCode.java (3)
store_network_logs_data/src/main/java/com/testsigma/addons/web/GetDataFromRequestBody.java (1)
  • Data (17-76)
store_network_logs_data/src/main/java/com/testsigma/addons/web/StartTracking.java (1)
  • Data (23-157)
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java (1)
  • ResponseDataUtilities (12-217)
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java (1)
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/FileUtilities.java (1)
  • FileUtilities (10-71)
🔇 Additional comments (7)
store_network_logs_data/pom.xml (1)

9-9: Version update looks appropriate.

The version increment from 1.0.2 to 1.0.4 aligns well with the significant refactoring and new functionality being introduced in this PR.

store_network_logs_data/src/main/java/com/testsigma/addons/web/GetDataFromRequestBody.java (1)

48-75: Excellent refactoring with improved error handling.

The shift from complex JSON parsing to direct header extraction using the utility method is much cleaner and more maintainable. The error handling is comprehensive with appropriate logging.

store_network_logs_data/src/main/java/com/testsigma/addons/web/StartTracking.java (2)

56-57: Verify the necessity of the large buffer size.

The buffer size is set to 100MB (100000000 bytes), which is quite large. Ensure this is necessary for your use case and won't cause memory issues.

Consider if this buffer size is appropriate for typical network responses or if it could be reduced to a more reasonable value like 10MB (10000000).


124-137: Excellent consolidation of network data storage.

The unified approach to storing status code, request headers, and response body in a single JSON object is a significant improvement. This addresses the file overwriting issue mentioned in the PR objectives by consolidating all data into one operation.

store_network_logs_data/src/main/java/com/testsigma/addons/web/GetStatusCode.java (1)

28-48: Well-implemented status code extraction functionality.

The implementation is clean, focused, and handles errors appropriately. The logging provides good visibility into the execution flow, and the utility method integration is seamless.

store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java (2)

140-171: Well-implemented header value extraction with robust parsing.

The getSpecificHeaderValue method provides robust parsing of header strings with good error handling and case-insensitive matching. The logging is comprehensive for debugging purposes.


192-215: Solid status code data retrieval implementation.

The status code retrieval logic is well-implemented with appropriate error handling, logging, and fallback behavior (returning -1 when no data is found). This supports the PR objective of adding status code extraction functionality.

devTool.addListener(Network.requestWillBeSent(), request -> {
String requestUrl = request.getRequest().getUrl();

request.getRequest().getHeaders();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove or complete the incomplete statement.

Line 67 contains an incomplete statement request.getRequest().getHeaders(); that doesn't assign the result to any variable or perform any action. This appears to be leftover code from refactoring.

-                request.getRequest().getHeaders();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
request.getRequest().getHeaders();
// (The redundant call to request.getRequest().getHeaders() has been removed)
🤖 Prompt for AI Agents
In
store_network_logs_data/src/main/java/com/testsigma/addons/web/StartTracking.java
at line 67, the statement `request.getRequest().getHeaders();` is incomplete and
unused. Remove this line entirely or assign its result to a variable if headers
are needed later; otherwise, deleting it will clean up leftover code from
refactoring.

Comment on lines +65 to 68
public static String getResponseBody(Long runId, Logger logger) throws Exception {
String responseBody = getResponseBodyData(runId, logger).getAsString();
clearResponseDataByRunId(runId);
return responseBody;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Inconsistent data clearing behavior across methods.

Some methods like getResponseBody, getRequestHeaders, and getStatusCode automatically clear the data after reading, while others like getStatusCodeData and getRequestHeadersData don't. This inconsistency could lead to unexpected behavior.

Consider either:

  1. Making all "get" methods non-destructive and providing separate "clear" methods
  2. Creating separate methods with clear naming like getAndClearStatusCode vs getStatusCode
  3. Adding a boolean parameter to control clearing behavior

Also applies to: 134-138, 182-190

🤖 Prompt for AI Agents
In
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java
around lines 65-68, 134-138, and 182-190, the data clearing behavior after
reading is inconsistent across methods. To fix this, refactor all "get" methods
to be non-destructive by removing automatic clearing, and implement separate
clearly named methods like "getAndClearStatusCode" or add a boolean parameter to
control whether the data should be cleared after retrieval. This will ensure
consistent and predictable behavior across all data access methods.

Comment on lines +98 to +113
public static void addRequestHeadersData(Long runId, String requestHeaders, Logger logger) throws Exception {
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
jsonArray.add(requestBody);
jsonObject.add("requestBody", jsonArray);
jsonArray.add(requestHeaders);
jsonObject.add("requestHeaders", jsonArray);
saveAllData(runId, jsonObject, logger);
}

public static String getRequestBody(Long runId, com.testsigma.sdk.Logger logger) throws Exception {
String requestBody = getRequestBodyData(runId, logger).getAsString();
public static void addStatusCodeAndRequestHeadersData(Long runId, int statusCode, String requestHeaders, Logger logger) throws Exception {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("statusCode", statusCode);
JsonArray jsonArray = new JsonArray();
jsonArray.add(requestHeaders);
jsonObject.add("requestHeaders", jsonArray);
saveAllData(runId, jsonObject, logger);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Method naming and proliferation concerns.

The class has multiple similar methods with slight variations (addRequestHeadersData, addStatusCodeAndRequestHeadersData, addAllNetworkData, saveAllNetworkData) which could lead to confusion about which method to use when.

Consider consolidating these methods or providing clearer naming conventions. For example:

  • addRequestHeadersOnly
  • addStatusCodeAndHeaders
  • addCompleteNetworkData
  • saveNetworkData (for pre-built JsonObject)
🤖 Prompt for AI Agents
In
store_network_logs_data/src/main/java/com/testsigma/addons/web/utilities/ResponseDataUtilities.java
around lines 98 to 113, there are multiple similar methods with overlapping
functionality and unclear naming. Refactor by consolidating these methods into
fewer, more clearly named methods such as addRequestHeadersOnly,
addStatusCodeAndHeaders, addCompleteNetworkData, and saveNetworkData for
pre-built JsonObjects. This will reduce confusion and improve code clarity by
making method purposes explicit and avoiding redundant variations.

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