Reproduce production bugs locally with AREX
Tags: opensource, testing, showdev
Published: 2023-11-07 07:41:13

<!-- TOC start (generated with https://github.com/derlin/bitdowntoc) -->

- [How to reproduce issues with AREX](#how-to-reproduce-issues-with-arex)
- [Deploy and start AREX](#deploy-and-start-arex)
   * [Step 1: Deploy AREX with Docker](#step-1-deploy-arex-with-docker)
   * [Step 2: Start the application with AREX Java Agent](#step-2-start-the-application-with-arex-java-agent)
- [Reproduce online issues locally ](#reproduce-online-issues-locally)
   * [Step 3: Record requests for bugs in the production environment](#step-3-record-requests-for-bugs-in-the-production-environment)
   * [Step 4: Debugging with local replay](#step-4-debugging-with-local-replay)

<!-- TOC end -->

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 https://github.com/arextest/deployments.git 
cd deployments docker-compose up
```

### 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 git@github.com:arextest/arex-agent-java.git 
mvn clean install
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ug9setzn983ykrt4nz8q.png)

The complete environment variables are as follows:

```
JAVA_TOOL_OPTIONS='-javaagent:E:/github-arex/arex-agent-java/arex-agent-jar/arex-agent-0.1.0.jar'
```

Program arguments:

```
-Darex.service.name=arex-community-test6 -Darex.storage.service.host=10.5.153.1:8093 -Darex.enable.debug=true  -Dspring.datasource.url=jdbc:mysql://10.5.153.1:13306/community?useUnicode=true&characterEncoding=utf-8 -Dspring.datasource.username=arex_admin -Dspring.datasource.password=arex_admin_password -Dspring.redis.host=10.5.153.1 -Dspring.redis.port=16379
```

View the log at startup:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6pv9zzae32hg2sfbt53.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya5y85ru6psuijzrcqlb.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hnhqn11fg8mjugpqyw2.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/prtbqbre7z9kgr8youd7.png)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhdrp6txirr2ws2rb24e.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fch9bri0k7q1b6znvn8.png)

After debugging is completed, you can view the response.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4y5oi37eg6ulv3htx24u.png)

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.

---

Community⤵️
🐦 Follow us on [Twitter](https://twitter.com/AREX_Test)
📝 Join AREX [Slack](https://arexcommunity.slack.com/ssb/redirect)
📧 Join the [Mailing List](https://groups.google.com/g/arex-test)