Skip to main content

Create a Trace-based Test

So far, you've learned:

  • How to define a trigger to executes tests against your apps.
  • How to configure trace ingestion.
  • How to configure your application to export traces.

This will enable trace-based testing in your apps that have OpenTelemetry distributed tracing configured.

We've provided a sample application with OpenTelemetry already enabled for you to try.

Start the Sample Pokeshop API​

To create tests quickly, start the official sample called Pokeshop API.

Terminal
git clone --depth 1 https://github.com/kubeshop/tracetest.git
cd tracetest/examples/tracetest-agent/pokeshop/

docker compose up -d --build
  • https://app.tracetest.io/ - Access the Tracetest Web UI. Sign up and create an organization.
  • http://localhost:8081 - The Pokeshop API demo is exposed from Docker to localhost on this port.
  • http://localhost:8081 - To run tests you will use localhost since it is exposed from Docker.
  • http://localhost:4317 - Trace ingestion URL where Tracetest Agent will accept traces. Since Pokeshop is running in Docker and Tracetest Agent is running on localhost this sample uses http://host.docker.internal:4317 to ingest traces instead of http://localhost:4317.
Click to view the sample Pokeshop API architecture

Here's the Architecture of the Pokeshop Sample App:

  • an API that serves client requests,
  • a Worker who deals with background processes.

The communication between the API and Worker is made using a RabbitMQ queue, and both services emit telemetry data to OpenTelemetry Collector and communicate with a Postgres database.

Tracetest triggers tests against the Node.js API.

Create Trace-based Tests in Two Ways​

  1. Programmatically, in YAML
  2. Visually, in the Web UI

Create a Trace-based Test Programatically in YAML​

Create a file called import-pokemon.yaml.

import-pokemon.yaml
type: Test
spec:
name: Import a Pokemon using API and MQ Worker
description: Import a Pokemon
trigger:
type: http
httpRequest:
method: POST
url: http://localhost:8081/pokemon/import
body: |
{
"id": 143
}
headers:
- key: Content-Type
value: application/json

Run it with the CLI.

Terminal
tracetest run test -f ./import-pokemon.yaml

Create a Trace-based Test Visually with the Web UI​

Create a test in the Web UI by opening your Tracetest account, clicking the Create button, and selecting HTTP.

create trace based tests 1

Enter http://localhost:8081/pokemon/import as the URL, select POST, add a JSON body { "id": 6 }, and click Run.

create trace based test 2

View the Trace Response​

With trace ingestion configured you can view the resulting trace that was generated by the app. Every test you run will now have additional observability with distributed traces.

create trace based test 6