Today, we are happy to announce that Tracetest now works with Azure App Insights. This integration enables you and your team to fully leverage your system's observability from Azure Monitor. By using Tracetest in conjunction with Azure, you can improve your instrumentation setup, enhance quality using the new Tracetest Analyzer, test system behavior by creating assertions based on traces, and integrate it into your automated pipelines.
Check out this hands-on example of how Tracetest works with Azure App Insights, or check out the recipe in the docs!
What is Azure App Insights?
Azure App Insights is an extension of Azure Monitor and provides application performance monitoring (APM) features. APM tools are useful to monitor applications from development, through test and into production in the following ways:
- Proactively understand how an application is performing.
- Reactively review application execution data to determine the cause of an incident.
What is Tracetest?
Tracetest is an open-source project, part of the CNCF landscape. It allows you to quickly build integration and end-to-end tests, powered by your distributed traces.
Tracetest uses your existing distributed traces to power trace-based testing with assertions against your trace data at every point of the request transaction. You only need to point Tracetest to your existing trace data source or send traces to Tracetest directly!
Tracetest makes it possible to:
- Define tests and assertions against every single microservice that a trace goes through.
- Work with your existing distributed tracing solution, allowing you to build tests based on your already instrumented system.
- Define multiple transaction triggers, such as a GET against an API endpoint, a GRPC request, etc.
- Define assertions against both the response and trace data, ensuring both your response and the underlying processes worked correctly, quickly, and without errors.
- Save and run the tests manually or via CI build jobs with the Tracetest CLI.
Tracetest Now Works with Azure App Insights!
Tracetest now works with Azure App Insights, enabling you to use Azure Monitor as a data store to pull traces generated by your distributed system.
In your existing observability setup, you can have the OpenTelemetry instrumentation configured in your code with OpenTelemetry Collector and send telemetry data to both Azure App Insights and Tracetest.
Or, you can decide to use the native approach by instrumenting your app directly with any of the available Azure Monitor distros to send data directly to the cloud provider and connect Tracetest to fetch data directly from Azure Monitor API.
Why is it important?
Enhancing your test suites with Azure App Insights and Trace-based Testing is crucial. When running integration tests, it can be difficult to pinpoint exactly where an HTTP transaction went wrong within a network of microservices. By enabling tracing, Tracetest can run tests with assertions against existing trace data for every service involved in the transaction. These tests can be used as part of your CI/CD process to ensure system functionality and catch regressions.
Combining the test creation capability of Tracetest with Azure App Insights allows you to take advantage of your existing instrumentation setup to explore new frontiers. You will now have the ability to evaluate complex system behaviors beyond just the initial request response, by analyzing the full list of steps taken to complete an asynchronous transaction.
Try Tracetest with Azure App Insights
For this blog post, we are going to focus on the native connection from Tracetest to Azure App Insights which pulls telemetry data through the Azure Monitor API. Showcasing how you can instrument a simple Node.js containerized application, validate the traces from Tracetest and add a test to the generated telemetry data.
The first task is to gather the necessary information from your Azure Cloud. This information will be used to connect the Node.js app to your App Insights instance and for Tracetest to pull data from the Azure Monitor API.
The things you need are:
After gathering the required information, the next step is to download the quick start example from the Tracetest repo that can be found here.
This repo contains the code to run the Node.js app, the docker-compose setup to run the services, and the configuration for the Tracetest server.
/src # the Node.js application code
/tests # Tracetest test YAML definitions
/tracetest # Tracetest server setup
.env # environment variables
docker-compose.yaml # main docker compose configuration
Dockerfile # Node.js app dockerization
Then, you can start overriding the template values for the configuration with the information you gathered in the first step.
In the .env
file add the CONNECTION_STRING
information
CONNECTION_STRING="<your-connection-string>"
This will enable the Node.js instrumentation code to send traces to the Azure Cloud.
In the tracetest/tracetest-provision.yaml
file add the resourceArmId
and the accessToken
---
type: Config
spec:
analyticsEnabled: true
---
type: PollingProfile
spec:
name: Custom Profile
strategy: periodic
default: true
periodic:
timeout: 5m
retryDelay: 5s
---
type: DataStore
spec:
name: azureappinsights
type: azureappinsights
azureappinsights:
connectionType: direct
resourceArmId: <your-arm-id>
accessToken: <your-access-token>
useAzureActiveDirectoryAuth: false
This will enable Tracetest to connect with the Azure Monitor API and fetch traces from the Azure Cloud. With the configuration ready, you can now execute the example by running:
docker compose -f ./docker-compose.yaml -f ./tracetest/docker-compose.yaml up -d
[Output]
[+] Running 3/3
⠿ Container tracetest-azure-app-insights-tracetest-1 Started 2.3s
⠿ Container tracetest-azure-app-insights-app-1 Started 0.5s
⠿ Container tracetest-azure-app-insights-postgres-1 Healthy
This will start the Tracetest server on port 11633
.
To validate that the configuration is correct and Tracetest is ready to start running tests, you can open the UI by opening [http://localhost:11663](http://localhost:11663)
in a browser.
Then, head to the settings page where you’ll find the Data Store configuration and you should see the Azure App Insights option selected with the configuration we added earlier.
At the bottom of the settings page, you will find the Test Connection button, click on it to validate that Tracetest is able to connect and fetch traces from Azure App Insights.
Now that we have everything set up, let’s execute a test!
To begin with, start by installing the Tracetest CLI:
brew install kubeshop/tracetest/tracetest
Note: Check out the download page for more info.
Then, from the example root folder, let’s use the test definition from the tests
folder.
# tests/test.yaml
type: Test
spec:
id: 4F1jCHJVR
name: App Insights
description: App Insights
trigger:
type: http
httpRequest:
url: http://app:8080/http-request
method: GET
headers:
- key: Content-Type
value: application/json
specs:
- selector: span[tracetest.span.type="http"]
assertions:
- attr:tracetest.selected_spans.count = 2
- attr:tracetest.span.duration < 1s
- selector: span[tracetest.span.type="http" name="GET /"]
assertions:
- attr:http.target = "/"
By executing the following command:
tracetest test run -d tests/test.yaml -s http://localhost:11633
✔ App Insights (http://localhost:11633/test/<test-id>/run/1/test)
After executing the test, you can follow the result link back to the UI, which after a couple of minutes, should display the generated trace and test results.
This is just one of three recipes we have created covering different setups and ways you can combine the power of Azure App Insights and Tracetest.
To learn more, head to the following links:
- Running Tracetest with Azure App Insights (ApplicationInsights Node.js SDK)
- Running Tracetest with Azure App Insights (Node.js + OpenTelemetry Collector)
- Running Tracetest with Azure App Insights (OpenTelemetry Collector & Pokeshop API)
What's next?
Would you like to learn more about Tracetest and what it brings to the table? Check the docs and try it out today by downloading it today! Want to learn more about Azure App Insights? Read more here.
Also, please feel free to join our Discord community, give Tracetest a star on GitHub, or schedule a time to chat 1:1.