DEV Community

Jing for AREX Test

Posted on • Updated on

Reproduce production bugs locally with AREX

In the software development cycle, software bugs are a natural occurrence. Reproducing and fixing issues in the development environment is a common activity for developers.

Reproducing production issues locally allows us to test and validate any proposed fixes before deploying them. This is essential for preventing regressions and ensuring the fix resolves the issue. It can also help identify and resolve other problems that may have been overlooked.

However, what often troubles developers is the differences in configuration and data between the production and local environments (such as data in the database, data in the cache, etc.), issues that occur in the production environment cannot be quickly reproduced in the local testing environment, making troubleshooting much more challenging.

How to reproduce issues with AREX

AREX is an automated regression testing tool, that can record traffic and data in the production environment by Java agent and replay them in the testing environment to identify the correlation between code changes and result differences.

AREX Java Agent can mock all external dependencies of the recorded real request during recording. This ensures that the data and behavior in the development environment are identical to the production environment, enabling issue reproduction and troubleshooting locally.

In this blog post, we’ll show you how to use AREX to reproduce issues. Let’s get started!

Deploy and start AREX

Step 1: Deploy AREX with Docker

git clone 
cd deployments docker-compose up
Enter fullscreen mode Exit fullscreen mode

Step 2: Start the application with AREX Java Agent

AREX Agent is the core component for traffic recording. Therefore, before using the recording feature, it is necessary to configure the AREX Agent for the application under test.

git clone 
mvn clean install
Enter fullscreen mode Exit fullscreen mode

After compilation, you will find a new folder named "arex-agent-jar" in the "arex-agent-java" directory, which contains two JAR files.

To configure the Java Agent for the application to be tested, add the Java Agent configuration to the startup of the Java application.

Image description

The complete environment variables are as follows:

Enter fullscreen mode Exit fullscreen mode

Program arguments: -Darex.enable.debug=true  -Dspring.datasource.url=jdbc:mysql:// -Dspring.datasource.username=arex_admin -Dspring.datasource.password=arex_admin_password -Dspring.redis.port=16379
Enter fullscreen mode Exit fullscreen mode

View the log at startup:

Image description

You will see the message "ArexJavaAgent installed" in the printout, indicating that the Agent has been successfully installed.

At the same time, you can see Java printing out command-line parameter information, such as Agent address and Storage service address, as indicated by the arrows in the above image.

Reproduce online issues locally

Step 3: Record requests for bugs in the production environment

A normal HTTP request and the response are as follows:

Image description

When a bug occurs in a production request, configure all the settings for the request in AREX, and click on "action.record" to enable recording this request, as shown in the figure below:

Image description

After clicking the button, a new key named "arex-force-record" with a value of "true" will be added to the Header List. Then save the changes.

Send the request and the response headers will generate a new key called "arex-record-id" with a value of "AREX-172-20-0-4-708656889122" (a unique value randomly generated by the AREX Agent). This indicates that the request has been successfully recorded and all the data that the request depends on in the production environment has been stored in AREX.

Image description

Step 4: Debugging with local replay

Create a new request and modify the environment of the URL to the local environment. In the AREX request headers, add a key "arex-record-id" with the value set to the previously generated "AREX-172-20-0-4-708656889122". After clicking save, send the request.

Image description

Now you can debug the issue step by step in your IDEA environment:

Image description

After debugging is completed, you can view the response.

Image description

The response message contains an "arex-replay-id" key with a value of "AREX-172-20-0-4-708658384473" (an ID randomly generated by the AREX Agent for analysis purposes). It means that the request has been successfully replayed.

The above is the complete process of using the AREX traffic recording feature to quickly reproduce and debug online issues locally.

🐦 Follow us on Twitter
📝 Join AREX Slack
📧 Join the Mailing List

Top comments (0)