Skip to main content

Node.js and Honeycomb

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.

Honeycomb is an observability solution that shows you the patterns and outliers of how users experience your code in complex and unpredictable environments.

Node.js App with Honeycomb, OpenTelemetry and Tracetest​

This is a quick start on how to configure a Node.js app to use OpenTelemetry instrumentation with traces, and Tracetest for enhancing your E2E and integration tests with trace-based testing and Honeycomb as a trace data store.

Prerequisites​

Tracetest 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 Node.js Quickstart:

git clone https://github.com/kubeshop/tracetest
cd tracetest/examples/tracetest-honeycomb

Follow these instructions to run the quick start:

  1. Copy the .env.template file to .env.
  2. Log into the Tracetest app.
  3. This example is configured to use the Honeycomb Tracing Backend. Ensure the environment you will be utilizing to run this example is also configured to use the Honeycomb Tracing Backend by clicking on Settings, Tracing Backend, Honeycomb, Save.
  4. 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.
  5. Run docker compose -f ./docker-compose.agent.yaml up -d.
  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 a detailed breakdown of what the example you just ran did and how it works.

Project Structure​

The quick start Node.js project is built with Docker Compose and contains the Tracetest Agent and a Node.js app.

The docker-compose.agent.yaml file in the root directory of the quick start runs the Node.js app 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.

TRACETEST_API_KEY="<YOUR_TRACETEST_API_KEY>"
HONEYCOMB_API_KEY="<YOUR_HONEYCOMB_API_KEY>"

The OpenTelemetry tracing is contained in the tracing.otel.grpc.js or tracing.otel.http.js files. Traces will be sent to Tracetest Agent.

Choosing the tracing.otel.grpc.js file will send traces to Tracetest Agent's GRPC endpoint.

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

"scripts": {
"app-with-grpc-tracer": "node -r ./tracing.otel.grpc.js app.js",
},

Configuring Honeycomb​

Configure Honeycomb as a Tracing Backend in Tracetest.

tracetest-tracing-backend.yaml
---
type: DataStore
spec:
name: Honeycomb
type: honeycomb
default: true
tracetest config -t <YOUR_API_TOKEN>
tracetest apply datastore -f ./tracetest-tracing-backend.yaml

Run the Node.js App, OpenTelemetry Collector, and Tracetest Agent with Docker Compose​

To start the full setup, run the following command:

docker compose -f ./docker-compose.agent.yaml up -d

Run Tracetest Tests​

  1. Open Tracetest.
  2. Configure Honeycomb 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​

Feel free to check out our examples in GitHub and join our Slack Community for more info!