Skip to main content

Pokeshop API with AWS X-Ray (Node.js SDK) and AWS Distro for OpenTelemetry

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.

AWS X-Ray provides a complete view of requests as they travel through your application and filters visual data across payloads, functions, traces, services, APIs, and more with no-code and low-code motions.

AWS Distro for OpenTelemetry (ADOT) is a secure, production-ready, AWS-supported distribution of the OpenTelemetry project. Part of the Cloud Native Computing Foundation, OpenTelemetry provides open source APIs, libraries, and agents to collect distributed traces and metrics for application monitoring.

Pokeshop API As a testing ground, the team at Tracetest has implemented a sample instrumented API around the PokeAPI.

Pokeshop API Demo with AWS X-Ray (Node.js SDK), AWS Distro for OpenTelemetry 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 AWS X-Ray as the trace data store, the ADOT as a middleware and the Pokeshop API to generate the telemetry data.

Prerequisites​

Tracetest Account:

AWS 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 AWS X-Ray Pokeshop Quickstart:

git clone https://github.com/kubeshop/tracetest
cd tracetest/examples/tracetest-amazon-x-ray-pokeshop

Follow these instructions to run the quick start:

  1. Copy the .env.template file to .env.
  2. Fill out the TRACETEST_TOKEN and ENVIRONMENT_ID details by editing your .env file.
  3. Fill out the AWS credentials in the .env file. You can create credentials by following this guide.
  4. Run docker compose run tracetest-run.
  5. Follow the links in the output to view the test results.

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 the Pokeshop Demo app.

The docker-compose.yaml file in the root directory of the quick start runs the Pokeshop Demo app, AWS Distro for OpenTelemetry (ADOT), and the Tracetest Agent setup.

Configuring the Pokeshop Demo App​

The Pokeshop API is a fully instrumented REST API that makes use of different services to mimic a real life scenario.

It is instrumented using the OpenTelemetry standards for Node.js, sending the data to the ADOT collector that will be pushing the telemetry information to both the AWS X-Ray service.

This is a fragment from the main tracing file from the Pokeshop API repo.

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>"

AWS_ACCESS_KEY_ID="<YOUR_AWS_ACCESS_KEY_ID>"
AWS_SECRET_ACCESS_KEY="<YOUR_AWS_SECRET_ACCESS_KEY>"
AWS_SESSION_TOKEN="<YOURAWS_SESSION_TOKEN>"
AWS_REGION="<YOUR_AWS_REGION>"

Run the Pokeshop Demo App, ADOT, and Tracetest Agent with Docker Compose​

The docker-compose.yaml file in the root directory contains the Pokeshop Demo app services.

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

To run everything including Tracetest tests, run this command:

docker compose run tracetest-run

This will:

  1. Start the Pokeshop app, the OpenTelemetry Collector, and send the traces to AWS X-Ray.
  2. Start the Tracetest Agent.
  3. Configure the tracing backend and create tests in your environment.
  4. Run the tests.

Learn More​

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