layout | title | authors | date | categories | redirect_from | ||
---|---|---|---|---|---|---|---|
post |
Using OpenSearch as the traces storage for Tracetest |
|
2022-09-27 12:15:00 -0300 |
|
/blog/community/2022/09/opensearch-supported-by-tracetest/ |
I am excited to announce that Tracetest now supports OpenSearch! If you already use OpenSearch Trace Analytics, you can start writing tests based on your telemetry using Tracetest without having to change anything in your application. In this article, we will explain how you can start building trace-based tests right now.
Tracetest is an open-source project that allows you to use your telemetry data to assert the behavior of your application. It fetches the telemetry generated by your application during a test execution and uses it to run assertions against it. With this functionality, you can verify if the latencies of your system are within your thresholds, validate your application flow and much more. It is also quite useful for writing end-to-end tests when you don't have a complete understanding of how the application interacts with other services. You can use the trace generated by a test to do exploration work while writing your tests.
The Tracetest team is working diligently to make installation as seamless as possible. Currently, you can use CLI to install the server to run on either Docker Compose or Kubernetes. Visit the installation guide to install both the CLI and server.
Before proceeding, make sure you have an OpenSearch instance running and have a Data Prepper instance pointing to it. Data Prepper is an OpenSearch component capable of converting OpenTelemetry format into JSON that can be indexed by OpenSearch. Tracetest has an example application. See how Data Prepper is configured.
For simplicity's sake in this article, you will learn how to setup Tracetest using Docker Compose. Execute the following steps to configure your Tracetest instance to connect to your OpenSearch instance:
- Run tracetest version to verify your CLI version.
- Check if your CLI version is greater or equal to 0.7.2.
- Create a folder called tracetest-demo.
mkdir ~/tracetest-demo
- Open the folder on your terminal.
cd ~/tracetest-demo
- Run tracetest server install and follow the steps:
- Select Using Docker Compose.
- Allow the CLI to install any dependency that might be missing from your system.
- Project's docker-compose file? Press Enter
- Do you want me to create an empty docker-compose file? Yes
- Do you have a supported tracing backend you want to use? (Jaeger, Tempo, OpenSearch, SignalFX) Yes
- Select OpenSearch
- Set the addresses to match your nodes' addresses
- Consider that the collector is running inside a Docker container, so you cannot use
localhost
to reference other containers running on your machine. Use eitherhost.docker.internal
(Mac) or172.17.0.1
(Linux) to reference your local machine.
- Set the index used to store your traces.
- Set your data-prepper endpoint.
- Consider that the collector is running inside a Docker container, so you cannot use
localhost
to reference other containers running on your machine. Use eitherhost.docker.internal
(Mac) or172.17.0.1
(Linux) to reference your local machine.
- Do you have an OpenTelemetry Collector? No
- Do you want me to set up one? Yes
- Do you want to enable the demo app? Yes
- Tracetest output directory Press Enter
- Run the docker compose command that the CLI just printed on your terminal:
docker compose -f docker-compose.yaml -f tracetest/docker-compose.yaml up -d
Now you should have Tracetest running and connected to your OpenSearch instance.
You should be able to access Tracetest by opening http://localhost:8080
on your browser and see Tracetest's home screen:
Click on Create Test, select HTTP Request and then click on Next.
Click on Choose Example, select Pokemon - Add, and then click on Next.
To review the request that is used to trigger the test, you don't have to change anything. Just click on Create.
Now you can see the result of the test execution. You should be seeing the response from the Pokemon demo:
Click on Trace to see the trace generated by the Pokemon demo when the test was executed. This trace was retrieved from your OpenSearch instance!
And, if you click on Test, you will see all assertions for this test. However, as you just created the test, there aren't any assertions yet. You can add one to see how it works. Click on the POST /pokemon span and then click on Add Test Spec.
This will generate the query to select that specific span in the trace. Then you can add assertions based on attributes from that span. Next, test executions will run those assertions against the new trace automatically. To show its capabilities, add two assertions to that span.
Select http.status_code Equals 201 to assert that the status code of the request will be 201 everytime this test is run. Select tracetest.span.duration Less than 100ms and to assert that the request will take less than 100ms to run in future tests.
Click on Save Test Spec and then on Publish.
Now it's possible to run the test. Tracetest will execute all assertions you just created using the new trace. Click on Run Test and wait for the test to finish executing.
Tracetest is not only a UI tool. You also can run that test from your CI environment. Click on the gear icon at the top of the page and click on Test Definition.
Copy the test definition and save into a file. Then open your terminal, and type tracetest test run -d your-file.yaml -w and wait for the result.
With this new integration, any team using OpenSearch as your OpenTelemetry trace data store will be able to use Tracetest to help you test your application. We are super excited to work with the OpenSearch community to release the integration and to continue to enhance this feature as we develop Tracetest. If you have any issues or questions about Tracetest with OpenSearch, reach out the team on the Discord channel or open an issue on the git repository.