Skip to main content

Node.js 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.

Node.js App with Azure Application Insights, OpenTelemetry Collector and Tracetest

This is a simple quick start guide on how to configure a Node.js app to use instrumentation with traces and 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 to process and route the telemetry data and a Node.js app to generate it.


Tracetest Account:

Azure Account:

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
cd tracetest/examples/tracetest-azure-app-insights-collector

Follow these instructions to run the quick start:

  1. Copy the .env.template file to .env.
  2. Log into the Tracetest app.
  3. Fill out the token and API key details by editing your .env file. You can find these values in the Settings area for your environment.
  4. Run docker compose up -d.
  5. This example is configured to use the Azure Application Insights Tracing Backend. Ensure the environment you're using to run this example is configured to use the Application Insights Tracing Backend by clicking on Settings, Tracing Backend, Azure Application Insights, Save. Or, use the CLI as explained below.
  6. Run tests from the Tracetest Web UI by accessing the app with the URL http://app:8080/.

Follow along with the sections below for an in detail breakdown of what the example you just ran did and how it works.

Project Structure

The project contains the Tracetest Agent, and a Node.js app.

The docker-compose.yaml file in the root directory of the quick start runs the Node.js app, Elasticsearch, Elastic APM server, OpenTelemetry Collector, and the Tracetest Agent setup.

Configuring the Node.js App

The Node.js app is a simple Express app, contained in the app.js file.

Configure the .env like shown below.


The OpenTelemetry tracing is contained in the tracing.js file. Traces will be sent to Azure Application Insights.

The tracing.js file will send traces to the Azure Application Insights endpoint.

Enabling the tracer is done by preloading the trace file. As seen in the package.json.

"scripts": {
"start": "node -r ./tracing.js app.js"

Configuring Azure Application Insights

Create an Application Insights resource in your Azure account. Copy the Instrumentation Key.

Configure the .env like shown below.


Configure Azure Application Insights as a Tracing Backend in Tracetest:

type: DataStore
id: current
name: azureappinsights
type: azureappinsights
connectionType: collector
useAzureActiveDirectoryAuth: false
tracetest config -t <YOUR_API_TOKEN>
tracetest apply datastore -f ./tracetest-tracing-backend.yaml

Run the Node.js App and OpenTelemetry Collector with Docker Compose

The docker-compose.yaml file and Dockerfile in the root directory contain the Node.js app.

The docker-compose.yaml file also contains the Tracetest Agent and OpenTelemetry Collector.

To start it, run this command:

docker compose up -d

This will start the Node.js app and Tracetest Agent.

Run Tracetest Tests

  1. Open Tracetest.
  2. Configure Azure Application Insights as a tracing backend if you have not already as explained above.
  3. Start creating tests! Make sure to use the http://app:8080/ URL in your test creation.
  4. To trigger tests in the CLI, first install the CLI, configure it, and run a test. From the root of the quick start directory, run:
tracetest configure -t <YOUR_API_TOKEN>
tracetest run test -f ./test-api.yaml

Learn More

Please visit our examples in GitHub and join our Slack Community for more info!