Announcing the Tracetest Integration with Azure App Insights
Tracetest integrates with Azure App Insights, enhancing code quality w/trace analysis, assertions based on traces & works w/your existing Azure Monitor setup.
Table of Contents
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](https://github.com/kubeshop/tracetest/tree/main/examples/tracetest-azure-app-insights) of how Tracetest works with Azure App Insights, or check out [the recipe in the docs](https://docs.tracetest.io/examples-tutorials/recipes/running-tracetest-with-azure-app-insights)!*
![](https://res.cloudinary.com/djwdcmwdz/image/upload/v1688556660/Blogposts/azure-app-insights-announcement/Untitled_2_xx6s5n.png)
## What is Azure App Insights?
[Azure App Insights](https://learn.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview?tabs=net) is an extension of [Azure Monitor](https://learn.microsoft.com/en-us/azure/azure-monitor/overview) 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](https://tracetest.io/) is an [open-source project, part of the CNCF landscape](https://github.com/kubeshop/tracetest). 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](https://docs.tracetest.io/configuration/connecting-to-data-stores/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.
![](https://res.cloudinary.com/djwdcmwdz/image/upload/v1688556660/Blogposts/azure-app-insights-announcement/Untitled_2_xx6s5n.png)
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.
![https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901565/Blogposts/azure-app-insights-announcement/azure-app-insights-dashboard_avolqm.png](https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901565/Blogposts/azure-app-insights-announcement/azure-app-insights-dashboard_avolqm.png)
## 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.
![https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901418/Blogposts/azure-app-insights-announcement/diagram_nty1ui.png](https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901418/Blogposts/azure-app-insights-announcement/diagram_nty1ui.png)
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:
- [The App Insights Connection String](https://learn.microsoft.com/en-us/azure/bot-service/bot-service-resources-app-insights-keys?view=azure-bot-service-4.0)
- [The App Insights ARM ID](https://microsoft.github.io/botframework-solutions/solution-accelerators/tutorials/view-analytics/2-get-application-insights-application-id/)
- [An Access Token](https://learn.microsoft.com/en-us/azure/azure-monitor/app/app-insights-azure-ad-api)
After gathering the required information, the next step is to download the quick start example from the Tracetest repo that can be found [here](https://github.com/kubeshop/tracetest/tree/main/examples/tracetest-azure-app-insights).
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.
```bash
/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
```bash
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`
```yaml
---
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:
```bash
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` in a browser.
![https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901418/Blogposts/azure-app-insights-announcement/tracetest-home_a3o0xv.png](https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901418/Blogposts/azure-app-insights-announcement/tracetest-home_a3o0xv.png)
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.
![https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901885/Blogposts/azure-app-insights-announcement/azure-test-connection-3_iyamcz.png](https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901885/Blogposts/azure-app-insights-announcement/azure-test-connection-3_iyamcz.png)
Now that we have everything set up, let’s execute a test!
To begin with, start by installing the Tracetest CLI:
```bash
brew install kubeshop/tracetest/tracetest
```
> *Note: Check out the [download page](https://tracetest.io/download) for more info.*
Then, from the example root folder, let’s use the test definition from the `tests` folder.
```yaml
# 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:
```bash
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.
![https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901418/Blogposts/azure-app-insights-announcement/test-run_mcmif3.png](https://res.cloudinary.com/djwdcmwdz/image/upload/v1687901418/Blogposts/azure-app-insights-announcement/test-run_mcmif3.png)
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)](https://docs.tracetest.io/examples-tutorials/recipes/running-tracetest-with-azure-app-insights)
- [Running Tracetest with Azure App Insights (Node.js + OpenTelemetry Collector)](https://docs.tracetest.io/examples-tutorials/recipes/running-tracetest-with-azure-app-insights-collector)
- [Running Tracetest with Azure App Insights (OpenTelemetry Collector & Pokeshop API)](https://docs.tracetest.io/examples-tutorials/recipes/running-tracetest-with-azure-app-insights-pokeshop/)
## What's next?
Would you like to learn more about Tracetest and what it brings to the table? Check the [docs](https://docs.tracetest.io/examples-tutorials/recipes/running-tracetest-with-lightstep/) and try it out today by [downloading](https://tracetest.io/download) it today! Want to learn more about Azure App Insights? [Read more here](https://testkube.io/get-started).
Also, please feel free to join our [Slack community](https://dub.sh/tracetest-community), give [Tracetest a star on GitHub](https://github.com/kubeshop/tracetest), or schedule a [time to chat 1:1](http://calendly.com/ken-kubeshop/otel-user-interview-w-tracetest).