Pokeshop API and Azure Application Insights with OpenTelemetry Collector
Tracetest is a testing tool based on OpenTelemetry that allows you to test your distributed application. It allows you to use data from distributed traces generated by OpenTelemetry to validate and assert if your application has the desired behavior defined by your test definitions.
Azure Application 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.
OpenTelemetry Collector Contrib - The official OpenTelemetry Distribution for packages outside of the core collector.
Pokeshop API As a testing ground, the team at Tracetest has implemented a sample instrumented API around the PokeAPI.
Pokeshop API with Azure Application Insights, OpenTelemetry Collector and Tracetest​
This is a simple quick start guide on how to configure a fully instrumented API to be used with Tracetest for enhancing your E2E and integration tests with trace-based testing. The infrastructure will use Azure App Insights as the trace data store, the OpenTelemetry Collector as a middleware and the Pokeshop API to generate the telemetry data.
Prerequisites​
Tracetest Account:
- Sign up to
app.tracetest.io
or follow the get started docs. - Have access to the environment's agent API key.
Azure Account:
- Sign up to Azure.
- Install Azure CLI.
- Create an Application Insights app and get a Instrumentation Key.
Docker: Have Docker and Docker Compose installed on your machine.
Run This Quckstart Example​
The example below is provided as part of the Tracetest project. You can download and run the example by following these steps:
Clone the Tracetest project and go to the Azure Node.js Quickstart:
git clone https://github.com/kubeshop/tracetest
cd tracetest/examples/tracetest-azure-app-insights-pokeshop
Follow these instructions to run the quick start:
- Copy the
.env.template
file to.env
. - Fill out the TRACETEST_TOKEN and ENVIRONMENT_ID details by editing your
.env
file. - Fill out the APP_INSIGHTS_ACCESS_TOKEN, APP_INSIGHTS_ARM_ID and APP_INSIGHTS_INSTRUMENTATION_STRING details by editing your
.env
file. - Run
docker compose run tracetest-run
. - Follow the links in the output to view the test results.
Follow the sections below for a detailed breakdown of what the example you just ran did and how it works.
Pokeshop API​
The Pokeshop API is instrumented using the OpenTelemetry standards for Node.js, sending the data to the OpenTelemetry collector that will be pushing the telemetry information to the Azure Cloud.
Configuring the Pokeshop Demo API​
Configure the .env
like shown below.
# Get the required information here: https://app.tracetest.io/retrieve-token
TRACETEST_TOKEN="<YOUR_TRACETEST_TOKEN>"
TRACETEST_ENVIRONMENT_ID="<YOUR_ENV_ID>"
# Azure
APP_INSIGHTS_ACCESS_TOKEN=""
APP_INSIGHTS_ARM_ID="/subscriptions/<id>/resourceGroups/app-insights-1/providers/microsoft.insights/components/<name>"
APP_INSIGHTS_INSTRUMENTATION_STRING=""
Running the Pokeshop Demo API, OpenTelemetry Collector, and Tracetest​
The docker-compose.yaml
file in the root directory contains the Node.js app, OpenTelemetry Collector and Tracetest Agent.
To run everything including Tracetest tests, run this command:
docker compose run tracetest-run
This will:
- Start the Node.js app and send the traces to Azure App Insights.
- Start the Tracetest Agent.
- Configure the Azure App Insights tracing backend and create tests in your environment.
- Run the tests.
The Test File​
Check out the resources/test.yaml
file.
# resources/test.yaml
type: Test
spec:
id: -ao9stJVg
name: Pokeshop - Import
description: Import a Pokemon
pollingProfile: azure
trigger:
type: http
httpRequest:
url: http://demo-api:8081/pokemon/import
method: POST
headers:
- key: Content-Type
value: application/json
body: '{"id":6}'
specs:
- name: Import Pokemon Span Exists
selector: span[tracetest.span.type="general" name="import pokemon"]
assertions:
- attr:tracetest.selected_spans.count = 1
- name: Uses Correct PokemonId
selector: span[tracetest.span.type="http" name="GET /pokemon/6" http.method="GET"]
assertions:
- attr:http.url = "https://pokeapi.co/api/v2/pokemon/6"
- name: Matching db result with the Pokemon Name
selector: span[tracetest.span.type="database" name="create pokeshop.pokemon"]:first
assertions:
- attr:db.result contains "charizard"
Learn More​
Please visit our examples in GitHub and join our Slack Community for more info!