From 298aef1c7918e2fc7f0c391ece3b075008b263f9 Mon Sep 17 00:00:00 2001 From: Oscar Reyes Date: Wed, 14 Aug 2024 09:15:43 -0600 Subject: [PATCH] chore(docs/examples): Updating Tempo X Node.js (#3960) * chore(docs/examples): Updating Tempo X Node.js * updating pokeshop grafana tempo example/recipe * updating pokeshop grafana tempo example/recipe * updating grafana tempo nodejs examples * updating grafana cloud tempo pokeshop * PR suggestions updates --- ...test-with-grafana-cloud-tempo-pokeshop.mdx | 98 +--- ...ing-tracetest-with-grafana-cloud-tempo.mdx | 384 +--------------- ...-tracetest-with-grafana-tempo-pokeshop.mdx | 213 ++++----- .../recipes/running-tracetest-with-tempo.mdx | 435 +----------------- .../.env.template | 10 +- .../.gitignore | 1 + .../Dockerfile.tracetest | 11 + .../collector.config.yaml | 12 +- .../docker-compose.agent.yaml | 18 - .../docker-compose.yaml | 61 ++- .../resources/apply.sh | 32 ++ .../resources/run.sh | 16 + .../{test-api.yaml => resources/test.yaml} | 0 .../tracetest-tracing-backend.yaml | 12 - .../tracetest/collector.config.yaml | 27 -- .../tracetest/docker-compose.yaml | 46 -- .../tracetest/tracetest-config.yaml | 7 - .../tracetest/tracetest-provision.yaml | 12 - .../quick-start-tempo-nodejs/.env.template | 6 +- .../Dockerfile.tracetest | 11 + examples/quick-start-tempo-nodejs/app.js | 14 +- .../docker-compose.agent.yaml | 22 - .../docker-compose.yaml | 64 +++ .../resources/apply.sh | 17 + .../datastore.yaml} | 0 .../quick-start-tempo-nodejs/resources/run.sh | 16 + .../{test-api.yaml => resources/test.yaml} | 0 .../tempo.config.yaml | 46 ++ .../tracetest/docker-compose.yaml | 56 --- .../tracetest/tempo.config.yaml | 46 -- .../tracetest/tracetest-config.yaml | 7 - .../.env.template | 10 +- .../Dockerfile.tracetest | 11 + .../collector.config.yaml | 12 +- .../docker-compose.yml | 65 ++- .../resources/apply.sh | 32 ++ .../resources/datastore.yaml | 13 + .../resources/run.sh | 16 + .../{tests => resources}/test.yaml | 2 +- .../tests/curl_get.sh | 1 - .../tests/curl_post.sh | 1 - .../tests/post-mortem.yaml | 13 - .../tracetest-tracing-backend.yaml | 12 - .../.env.template | 4 + .../.gitignore | 3 +- .../Dockerfile.tracetest | 11 + .../docker-compose.yml | 71 ++- .../resources/apply.sh | 17 + .../resources/datastore.yaml} | 12 +- .../resources/run.sh | 16 + .../resources/test.yaml | 32 ++ .../tests/curl_get.sh | 1 - .../tests/curl_post.sh | 1 - .../tests/post-mortem.yaml | 13 - .../tests/test.yaml | 27 -- .../tracetest.config.yaml | 23 - .../tracetest.provision.yaml | 22 - 57 files changed, 719 insertions(+), 1422 deletions(-) create mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/Dockerfile.tracetest delete mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.agent.yaml create mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/resources/apply.sh create mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/resources/run.sh rename examples/quick-start-grafana-cloud-tempo-nodejs/{test-api.yaml => resources/test.yaml} (100%) delete mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/tracetest-tracing-backend.yaml delete mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/collector.config.yaml delete mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/docker-compose.yaml delete mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-config.yaml delete mode 100644 examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-provision.yaml create mode 100644 examples/quick-start-tempo-nodejs/Dockerfile.tracetest delete mode 100644 examples/quick-start-tempo-nodejs/docker-compose.agent.yaml create mode 100644 examples/quick-start-tempo-nodejs/resources/apply.sh rename examples/quick-start-tempo-nodejs/{tracetest-tracing-backend.yaml => resources/datastore.yaml} (100%) create mode 100644 examples/quick-start-tempo-nodejs/resources/run.sh rename examples/quick-start-tempo-nodejs/{test-api.yaml => resources/test.yaml} (100%) create mode 100644 examples/quick-start-tempo-nodejs/tempo.config.yaml delete mode 100644 examples/quick-start-tempo-nodejs/tracetest/docker-compose.yaml delete mode 100644 examples/quick-start-tempo-nodejs/tracetest/tempo.config.yaml delete mode 100644 examples/quick-start-tempo-nodejs/tracetest/tracetest-config.yaml create mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/Dockerfile.tracetest create mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/resources/apply.sh create mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/resources/datastore.yaml create mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/resources/run.sh rename examples/tracetest-grafana-cloud-tempo-pokeshop/{tests => resources}/test.yaml (96%) delete mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_get.sh delete mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_post.sh delete mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/tests/post-mortem.yaml delete mode 100644 examples/tracetest-grafana-cloud-tempo-pokeshop/tracetest-tracing-backend.yaml create mode 100644 examples/tracetest-grafana-tempo-pokeshop/.env.template create mode 100644 examples/tracetest-grafana-tempo-pokeshop/Dockerfile.tracetest create mode 100644 examples/tracetest-grafana-tempo-pokeshop/resources/apply.sh rename examples/{quick-start-tempo-nodejs/tracetest/tracetest-provision.yaml => tracetest-grafana-tempo-pokeshop/resources/datastore.yaml} (51%) create mode 100644 examples/tracetest-grafana-tempo-pokeshop/resources/run.sh create mode 100644 examples/tracetest-grafana-tempo-pokeshop/resources/test.yaml delete mode 100644 examples/tracetest-grafana-tempo-pokeshop/tests/curl_get.sh delete mode 100644 examples/tracetest-grafana-tempo-pokeshop/tests/curl_post.sh delete mode 100644 examples/tracetest-grafana-tempo-pokeshop/tests/post-mortem.yaml delete mode 100644 examples/tracetest-grafana-tempo-pokeshop/tests/test.yaml delete mode 100644 examples/tracetest-grafana-tempo-pokeshop/tracetest.config.yaml delete mode 100644 examples/tracetest-grafana-tempo-pokeshop/tracetest.provision.yaml diff --git a/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo-pokeshop.mdx b/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo-pokeshop.mdx index fe78ed1458..bd507d2bce 100644 --- a/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo-pokeshop.mdx +++ b/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo-pokeshop.mdx @@ -39,9 +39,7 @@ This is a simple quick start guide on how to configure a fully instrumented API **Tracetest Account**: - Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs. -- Create an [environment](/concepts/environments). -- Create an [environment token](/concepts/environment-tokens). -- Have access to the environment's [agent API key](/configuration/agent). +- Have access to the environment's [agent API key](https://app.tracetest.io/retrieve-token). **Grafana Cloud Account** @@ -64,11 +62,10 @@ cd tracetest/examples/tracetest-grafana-cloud-tempo-pokeshop Follow these instructions to run the quick start: 1. Copy the `.env.template` file to `.env`. -2. Log into the [Tracetest app](https://app.tracetest.io/). -3. Fill out the [token](https://docs.tracetest.io/concepts/environment-tokens) and [API key](https://docs.tracetest.io/concepts/agent) 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 Grafana Tempo Tracing Backend. Ensure the environment you're using to run this example is configured to use the Grafana Tempo Tracing Backend by clicking on Settings, Tracing Backend, Grafana Tempo, Save. Or, use the CLI as explained below. -6. Run tests from the Tracetest Web UI by accessing the app with the URL `http://demo-api:8081/pokemon/import`. +2. Fill out the [TRACETEST_TOKEN and ENVIRONMENT_ID](https://app.tracetest.io/retrieve-token) details by editing your `.env` file. +3. Fill out the [GRAFANA_AUTH_READ_HASH and GRAFANA_AUTH_WRITE_HASH](https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/) deatails from your Tempo setup. +3. Run `docker compose run tracetest-run`. +4. 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. @@ -89,91 +86,34 @@ This is a [fragment from the main tracing file](https://github.com/kubeshop/poke Configure the `.env` like shown below. ```bash -TRACETEST_API_KEY="" -TRACETEST_API_TOKEN="" -``` - -## Configuring OpenTelemetry Collector - -Configure OpenTelemetry Collector to send traces to Grafana Cloud Tempo. - -```yaml title="collector.config.yaml" -receivers: - otlp: - protocols: - grpc: - http: - -exporters: - logging: - verbosity: detailed - otlp: - endpoint: tempo-us-central1.grafana.net:443 - headers: - authorization: Basic - -service: - pipelines: - traces: - receivers: [otlp] - exporters: [logging, otlp] -``` - -Fill the authorization header in the `collector.config.yaml` file from your Grafana Tempo Setup. It should be encoded `base64` with the format of `username:token`. Follow [this guide to learn how](https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/). - -## Configuring Grafana Tempo +# Get the required information here: https://app.tracetest.io/retrieve-token -Configure Tempo as a Tracing Backend: +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" -```yaml title="tracetest-tracing-backend.yaml" ---- -type: DataStore -spec: - id: tempo-cloud - name: Tempo - type: tempo - tempo: - type: http - http: - url: https://tempo-us-central1.grafana.net/tempo - headers: - authorization: Basic - tls: {} -``` - -Fill in the details of your Grafana Cloud Tempo instance by using the HTTP integration `authorization` header. It should be encoded `base64` with the format of `username:token`. Follow [this guide to learn how](https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/). - -```bash -tracetest config -t -tracetest apply datastore -f ./tracetest-tracing-backend.yaml +# https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ +GRAFANA_AUTH_READ_HASH="" +GRAFANA_AUTH_WRITE_HASH="" ``` ## Run the Pokeshop Demo App, OpenTelemetry Collector, and Tracetest Agent with Docker Compose The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/tracetest-grafana-cloud-tempo-pokeshop/docker-compose.yml) in the root directory contains the Pokeshop Demo app services. - The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/tracetest-grafana-cloud-tempo-pokeshop/docker-compose.yml) also contains the Tracetest Agent and OpenTelemetry Collector. -To start it, run this command: - -```bash -docker compose up -d -``` - -This will start the Pokeshop Demo app, OpenTelemetry Collector, and Tracetest Agent. -## Run Tracetest Tests - -1. Open [Tracetest](https://app.tracetest.io/) -2. [Configure Grafana Tempo as a tracing backend](/configuration/connecting-to-data-stores/tempo) if you have not already as explained above. -3. Start creating tests! Make sure to use the `http://demo-api:8081/pokemon/import` URL in your test creation. -4. To trigger tests in the CLI, first [install the CLI](/cli/cli-installation-reference), [configure it](/cli/configuring-your-cli), and [run a test](/cli/running-tests). From the root of the quick start directory, run: +### Run Tracetest Tests ```bash -tracetest configure -t -tracetest run test -f ./tests/test.yaml +docker compose run tracetest-run ``` +This will: +1. Start the Node.js app, the OpenTelemetry Collector, and send the traces to Tempo. +2. Start the Tracetest Agent. +3. Configure the tracing backend and create tests in your environment. +4. Run the tests. + ## Learn More Feel free to check out our [examples in GitHub](https://github.com/kubeshop/tracetest/tree/main/examples) and join our [Slack Community](https://dub.sh/tracetest-community) for more info! diff --git a/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo.mdx b/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo.mdx index 7b5389d0cc..e304cccaa3 100644 --- a/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo.mdx +++ b/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-cloud-tempo.mdx @@ -18,10 +18,6 @@ keywords: image: https://res.cloudinary.com/djwdcmwdz/image/upload/v1698686403/docs/Blog_Thumbnail_14_rsvkmo.jpg --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; -import CodeBlock from '@theme/CodeBlock'; - :::note [Check out the source code on GitHub here.](https://github.com/kubeshop/tracetest/tree/main/examples/quick-start-grafana-cloud-tempo-nodejs) ::: @@ -36,19 +32,12 @@ import CodeBlock from '@theme/CodeBlock'; This is a simple 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. The infrastructure will use Tempo on Grafana Cloud as the trace data store, and OpenTelemetry Collector to receive traces from the Node.js app and send them to Tempo. -```mdx-code-block - - -``` - ## Prerequisites **Tracetest Account**: - Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs. -- Create an [environment](/concepts/environments). -- Create an [environment token](/concepts/environment-tokens). -- Have access to the environment's [agent API key](/configuration/agent). +- Have access to the environment's [agent API key](https://app.tracetest.io/retrieve-token). **Grafana Cloud Account** @@ -71,11 +60,10 @@ cd tracetest/examples/quick-start-grafana-cloud-tempo-nodejs Follow these instructions to run the quick start: 1. Copy the `.env.template` file to `.env`. -2. Log into the [Tracetest app](https://app.tracetest.io/). -3. Fill out the [token](https://docs.tracetest.io/concepts/environment-tokens) and [API key](https://docs.tracetest.io/concepts/agent) details by editing your `.env` file. You can find these values in the Settings area for your environment. -4. Run `docker compose -f ./docker-compose.yaml -f ./docker-compose.agent.yaml up -d`. -5. This example is configured to use the Grafana Tempo Tracing Backend. Ensure the environment you're using to run this example is configured to use the Grafana Tempo Tracing Backend by clicking on Settings, Tracing Backend, Grafana Tempo, 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/`. +2. Fill out the [TRACETEST_TOKEN and ENVIRONMENT_ID](https://app.tracetest.io/retrieve-token) details by editing your `.env` file. +3. Fill out the [GRAFANA_AUTH_READ_HASH and GRAFANA_AUTH_WRITE_HASH](https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/) deatails from your Tempo setup +3. Run `docker compose run tracetest-run`. +4. 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. @@ -92,7 +80,15 @@ The Node.js app is a simple Express app, contained in [the `app.js` file](https: Configure the `.env` like shown below. ```bash -TRACETEST_API_KEY="" +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" + +# https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ +GRAFANA_AUTH_READ_HASH="" +GRAFANA_AUTH_WRITE_HASH="" + ``` The OpenTelemetry tracing is contained in the `tracing.otel.grpc.js` or `tracing.otel.http.js` files. Traces will be sent to Grafana Tempo. @@ -107,368 +103,30 @@ Enabling the tracer is done by preloading the trace file. As seen in the `packag }, ``` -## Configuring OpenTelemetry Collector - -Configure OpenTelemetry Collector to send traces to Grafana Cloud Tempo. - -```yaml title="collector.config.yaml" -receivers: - otlp: - protocols: - grpc: - http: - -exporters: - logging: - verbosity: detailed - otlp: - endpoint: tempo-us-central1.grafana.net:443 - headers: - authorization: Basic - -service: - pipelines: - traces: - receivers: [otlp] - exporters: [logging, otlp] -``` - -Fill the authorization header in the `collector.config.yaml` file from your Grafana Tempo Setup. It should be encoded `base64` with the format of `username:token`. Follow [this guide to learn how](https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/). - -## Configuring Grafana Tempo - -Configure Tempo as a Tracing Backend: - -```yaml title="tracetest-tracing-backend.yaml" ---- -type: DataStore -spec: - id: tempo-cloud - name: Tempo - type: tempo - tempo: - type: http - http: - url: https://tempo-us-central1.grafana.net/tempo - headers: - authorization: Basic - tls: {} -``` - -Fill in the details of your Grafana Cloud Tempo instance by using the HTTP integration `authorization` header. It should be encoded `base64` with the format of `username:token`. Follow [this guide to learn how](https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/). - -```bash -tracetest config -t -tracetest apply datastore -f ./tracetest-tracing-backend.yaml -``` - ## Run the Node.js App, OpenTelemetry Collector, and Tracetest Agent with Docker Compose -The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/docker-compose.yaml) and [`Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/Dockerfile) in the root directory are for the Node.js app. The `docker-compose.yaml` contains one service for the Node.js app. - -The [`docker-compose.agent.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/docker-compose.agent.yaml) is for the Tracetest Agent and OpenTelemetry Collector. +The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/docker-compose.yaml) and [`Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/Dockerfile) in the root directory are for the Node.js app. The `docker-compose.yaml` contains one service for the Node.js app, as well as the Tracetest Agent, Tempo, and OpenTelemetry Collector. [The `collector.config.yaml` configures the OpenTelemetry Collector](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/collector.config.yaml). It receives traces via either `grpc` or `http`. Then, exports them to Tempo via the OTLP `exporter`. To start it, run this command: ```bash -docker compose -f ./docker-compose.yaml -f ./docker-compose.agent.yaml up -d +docker compose run tracetest-run ``` This will start the Node.js app the OpenTelemetry Collector and send the traces to Grafana Tempo. ## Run Tracetest Tests -1. Open [Tracetest](https://app.tracetest.io/) -2. [Configure Tempo as a tracing backend](/configuration/connecting-to-data-stores/tempo) 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](/cli/cli-installation-reference), [configure it](/cli/configuring-your-cli), and [run a test](/cli/running-tests). From the root of the quick start directory, run: - -```bash -tracetest configure -t -tracetest run test -f ./test-api.yaml -``` - -```mdx-code-block - - -``` - -## Prerequisites - -You will need [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine to run this quick start app! - -## Project Structure - -The project is built with Docker Compose. It contains two distinct `docker-compose.yaml` files. - -### 1. Node.js App - -The `docker-compose.yaml` file and `Dockerfile` in the root directory are for the Node.js app. - -### 2. Tracetest - -The `docker-compose.yaml` file, `collector.config.yaml`, `tracetest-provision.yaml`, and `tracetest-config.yaml` in the `tracetest` directory are for the setting up Tracetest, Tempo, and the OpenTelemetry Collector. - -The `tracetest` directory is self-contained and will run all the prerequisites for enabling OpenTelemetry traces and trace-based testing with Tracetest. - -### Docker Compose Network - -All `services` in the `docker-compose.yaml` are on the same network and will be reachable by hostname from within other services. For example, `tempo:4317` in the `collector.config.yaml` will map to the `tempo` service, where the port `4317` is the port where Tempo accepts traces. And, `tempo:9095` in the `tracetest-provision.yaml` will map to the `tempo` service and port `9095` where Tracetest will fetch trace data from Tempo. - -## Node.js App - -The Node.js app is a simple Express app, contained in the `app.js` file. - -The OpenTelemetry tracing is contained in the `tracing.otel.grpc.js` or `tracing.otel.http.js` files, respectively. -Traces will be sent to the OpenTelemetry Collector. - -Here's the content of the `tracing.otel.grpc.js` file: - -```js -const opentelemetry = require('@opentelemetry/sdk-node') -const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node') -const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc'); - -const sdk = new opentelemetry.NodeSDK({ - traceExporter: new OTLPTraceExporter({ url: 'http://otel-collector:4317' }), - instrumentations: [getNodeAutoInstrumentations()], -}) -sdk.start() -``` - -Depending on which of these you choose, traces will be sent to either the `grpc` or `http` endpoint. - -The hostnames and ports for these are: - -- GRPC: `http://otel-collector:4317` -- HTTP: `http://otel-collector:4318/v1/traces` - -Enabling the tracer is done by preloading the trace file. - -```bash -node -r ./tracing.otel.grpc.js app.js -``` - -In the `package.json` you will see two npm scripts for running the respective tracers alongside the `app.js`. - -```json -"scripts": { - "with-grpc-tracer":"node -r ./tracing.otel.grpc.js app.js", - "with-http-tracer":"node -r ./tracing.otel.http.js app.js" -}, -``` - -To start the server, run this command: - -```bash -npm run with-grpc-tracer -# or -npm run with-http-tracer -``` - -As you can see the `Dockerfile` uses the command above. - -```Dockerfile -FROM node:slim -WORKDIR /usr/src/app -COPY package*.json ./ -RUN npm install -COPY . . -EXPOSE 8080 -CMD [ "npm", "run", "with-grpc-tracer" ] -``` - -And, the `docker-compose.yaml` contains just one service for the Node.js app. - -```yaml -version: '3' -services: - app: - image: quick-start-nodejs - build: . - ports: - - "8080:8080" -``` - -To start it, run this command: - -```bash -docker compose build # optional if you haven't already built the image -docker compose up -``` - -This will start the Node.js app. But, you're not sending the traces anywhere. - -Let's fix this by configuring Tracetest and OpenTelemetry Collector. - -## Tracetest - -The `docker-compose.yaml` in the `tracetest` directory is configured with four services. - -- **Postgres** - Postgres is a prerequisite for Tracetest to work. It stores trace data when running the trace-based tests. -- [**OpenTelemetry Collector**](https://opentelemetry.io/docs/collector/) - A vendor-agnostic implementation of how to receive, process and export telemetry data. -- [**Tracetest**](https://tracetest.io/) - Trace-based testing that generates end-to-end tests automatically from traces. - -```yaml -version: "3" -services: - tracetest: - image: kubeshop/tracetest:${TAG:-latest} - platform: linux/amd64 - volumes: - - type: bind - source: ./tracetest/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./tracetest/tracetest-provision.yaml - target: /app/provisioning.yaml - ports: - - 11633:11633 - command: --provisioning-file /app/provisioning.yaml - depends_on: - postgres: - condition: service_healthy - tempo: - condition: service_started - otel-collector: - condition: service_started - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:11633"] - interval: 1s - timeout: 3s - retries: 60 - environment: - TRACETEST_DEV: ${TRACETEST_DEV} - - postgres: - image: postgres:14 - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.59.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./tracetest/collector.config.yaml:/otel-local-config.yaml - depends_on: - - tempo -``` - -Tracetest depends on Postgres, Tempo and the OpenTelemetry Collector. All three services require config files to be loaded via a volume. The volumes are mapped from the root directory into the `tracetest` directory and the respective config files. - -To start both the Node.js app and Tracetest, we will run this command: - -```bash -docker-compose -f docker-compose.yaml -f tracetest/docker-compose.yaml up # add --build if the images are not built already -``` - -The `tracetest-config.yaml` file contains the basic setup of connecting Tracetest to the Postgres instance and defining the trace data store and exporter. The exporter is set to the OpenTelemetry Collector. - -```yaml -# tracetest-config.yaml - -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable - -telemetry: - exporters: - collector: - serviceName: tracetest - sampling: 100 # 100% - exporter: - type: collector - collector: - endpoint: otel-collector:4317 - -server: - telemetry: - exporter: collector -``` - -The `tracetest-provision.yaml` file defines the trace data store, set to Grafana Cloud Tempo, meaning the traces will be stored in Tempo and Tracetest will fetch them from Tempo when running tests. - -How does Tracetest fetch traces? - -Tracetest uses `https://tempo-us-central1.grafana.net/tempo` to connect to Tempo and fetch trace data. - -```yaml -# tracetest-provision.yaml - ---- -type: DataStore -spec: - name: Grafana Tempo Cloud - type: tempo - tempo: - type: http - http: - url: https://tempo-us-central1.grafana.net/tempo - headers: - Authorization: Basic - # https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ - -``` - -How do traces reach Tempo? - -The `collector.config.yaml` explains that. It receives traces via either `grpc` or `http`. Then, exports them to Tempo's OTLP HTTP endpoint `tempo-us-central1.grafana.net:443`. - -```yaml -# collector.config.yaml - -receivers: - otlp: - protocols: - grpc: - http: - -exporters: - logging: - verbosity: detailed - otlp: - endpoint: tempo-us-central1.grafana.net:443 - headers: - authorization: Basic - -service: - pipelines: - traces: - receivers: [otlp] - exporters: [logging, otlp] -``` - -## Run Both the Node.js App and Tracetest - -To start both the Node.js app and Tracetest, run this command: - -```bash -docker-compose -f docker-compose.yaml -f tracetest/docker-compose.yaml up # add --build if the images are not built already -``` - -This will start your Tracetest instance on `http://localhost:11633/`. +This will: +1. Start the Node.js app, the OpenTelemetry Collector, and send the traces to Tempo. +2. Start the Tracetest Agent. +3. Configure the tracing backend and create tests in your environment. +4. Run the tests. Open the URL and start creating tests! Make sure to use the `http://app:8080/` URL in your test creation, because your Node.js app and Tracetest are in the same network. -```mdx-code-block - - -``` - ## Learn More Feel free to check out our [examples in GitHub](https://github.com/kubeshop/tracetest/tree/main/examples) and join our [Slack Community](https://dub.sh/tracetest-community) for more info! diff --git a/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-tempo-pokeshop.mdx b/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-tempo-pokeshop.mdx index 03e9f09010..0ff4bfea40 100644 --- a/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-tempo-pokeshop.mdx +++ b/docs/docs/examples-tutorials/recipes/running-tracetest-with-grafana-tempo-pokeshop.mdx @@ -32,7 +32,32 @@ This is a simple quick start guide on how to configure a fully instrumented API ## Prerequisites -You will need [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine to run this quick start app! +**Tracetest Account**: + +- Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs. +- Have access to the environment's [agent API key](https://app.tracetest.io/retrieve-token). + +**Docker**: Have [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) 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 Grafana Tempo Node.js Quickstart: + +```bash +git clone https://github.com/kubeshop/tracetest +cd tracetest/examples/tracetest-grafana-tempo-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](https://app.tracetest.io/retrieve-token) details by editing your `.env` file. +3. Run `docker compose run tracetest-run`. +4. 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. ## Project Structure @@ -40,7 +65,18 @@ The project is built with Docker Compose. ### 1. Tracetest -The `collector.config.yaml` file, `tracetest.provision.yaml`, and `tracetest.config.yaml` in the root directory are for the configuring Tracetest and it's OpenTelemetry Collector. +The project contains [Tracetest Agent](/getting-started/installation#install-the-tracetest-agent), [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main), and a Node.js app. + +The `docker-compose.yaml` file in the root directory of the quick start runs the Node.js app and the [Tracetest Agent](/concepts/agent) setup. + +Configure the `.env` as shown below. + +```bash +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" +``` ### 2. Grafana Tempo @@ -48,7 +84,7 @@ The `grafana.config.yaml` and `tempo.config.yaml` in the root directory contains ### Docker Compose Network -All `services` in the `docker-compose.yaml` are on the same network and will be reachable by hostname from within other services. E.g. `tracetest:4317` in the `tracetest/collector.config.yaml` will map to the `tracetest` service, where the port `4317` is the port where Tracetest accepts telemetry data. +All `services` in the `docker-compose.yaml` are on the same network and will be reachable by hostname from within other services. E.g. `tracetest:4317` in the `tracetest/collector.config.yaml` will map to the `tracetest-agent` service, where the port `4317` is the port where Tracetest accepts telemetry data. ## Pokeshop API @@ -119,6 +155,7 @@ async function createTracer(): Promise { The `docker-compose.yaml` file includes the definitions for all of the required services by the Pokeshop API, which includes: +- [**OpenTelemetry Collector**)](https://opentelemetry.io/docs/collector/getting-started/) - Vendor-agnostic way to receive, process and export telemetry data. - **Postgres** - To save Pokemon information. - **Redis** - For in memory strage. - **RabbitMQ** - For async processing use cases. @@ -240,54 +277,57 @@ services: ## Tracetest -The `docker-compose.yaml` includes two services related to Tracetest. The Tracetest instance also connects to the `postgres` service. - -- **Postgres** - Postgres is a prerequisite for Tracetest to work. It stores trace data when running the trace-based tests. -- [**OpenTelemetry Collector**)](https://opentelemetry.io/docs/collector/getting-started/) - Vendor-agnostic way to receive, process and export telemetry data. -- [**Tracetest**](https://tracetest.io/) - Trace-based testing that generates end-to-end tests automatically from traces. +The `docker-compose.yaml` includes two services related to Tracetest. ```yaml version: "3" - -# ... services: - - # ... - - # Tracetest - tracetest: - image: kubeshop/tracetest:${TAG:-latest} - platform: linux/amd64 + # Cloud-based Managed Tracetest + tracetest-agent: + image: kubeshop/tracetest-agent:latest + environment: + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} + tracetest-apply: + build: + dockerfile: Dockerfile.tracetest volumes: - - type: bind - source: ./tracetest/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./tracetest/tracetest-provision.yaml - target: /app/provision.yaml - command: --provisioning-file /app/provision.yaml - ports: - - 11633:11633 - extra_hosts: - - "host.docker.internal:host-gateway" + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null depends_on: - postgres: - condition: service_healthy - otel-collector: + demo-api: condition: service_started - healthcheck: - test: [ "CMD", "wget", "--spider", "localhost:11633" ] - interval: 1s - timeout: 3s - retries: 60 + tracetest-agent: + condition: service_started + + tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources environment: - TRACETEST_DEV: ${TRACETEST_DEV} + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully # Tracetest End ``` -Tracetest depends on Postgres and the OpenTelemetry Collector. Tracetest requires config files to be loaded via a volume. The volumes are mapped from the `tracetest` directory into the `root` directory of the Tracetest container instance and the respective config files. - The `collector.config.yaml` file contains the OpenTelemetry Collector configuration that enables routing traces from the Pokeshop API to Tempo. ```yaml @@ -319,64 +359,6 @@ service: exporters: [otlp/tempo] ``` -The `tracetest.config.yaml` file contains the basic setup of connecting Tracetest to the Postgres instance. It also enables forwarding Tracetest's internal telemetry to Grafana Tempo as well, with the `telemetry` and `server` config. - -```yaml -# tracetest-config.yaml - -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable - -telemetry: - exporters: - collector: - serviceName: tracetest - sampling: 100 - exporter: - type: collector - collector: - endpoint: otel-collector:4317 - -server: - telemetry: - exporter: collector - applicationExporter: collector -``` - -The `tracetest.provision.yaml` file defines the trace data store, set to Grafana Tempo, meaning the traces will be forwarded via the OpenTelemetry Collector to Tempo where they are stored. - -```yaml -# tracetest-provision.yaml - ---- -type: DataStore -spec: - name: Tempo - type: tempo - tempo: - type: grpc - grpc: - endpoint: tempo:9095 - tls: - insecure: true - ---- -type: Demo -spec: - type: pokeshop - enabled: true - name: pokeshop - opentelemetryStore: {} - pokeshop: - httpEndpoint: http://demo-api:8081 - grpcEndpoint: demo-rpc:8082 -``` - How do traces reach Grafana Tempo? The Pokeshop API code uses the native Node.js OpenTelemetry modules which send information to the OpenTelemetry Collector to be processed and then sent to Grafana Tempo. @@ -436,28 +418,17 @@ services: To start all the services, run this command: ```bash -docker-compose up -d +docker compose run tracetest-run ``` -This will start your Tracetest instance on `http://localhost:11633/`. Open it and start creating tests! - Make sure to use the `http://demo-api:8081/` URL in your test creation, because your Pokeshop API and Tracetest are in the same network. -## Run Tracetest Tests with the Tracetest CLI - -First, [install the CLI](https://docs.tracetest.io/getting-started/installation#install-the-tracetest-cli). -Then, configure the CLI: - -```bash -tracetest configure --server-url http://localhost:11633 -``` - -Once configured, you can run a test against the Tracetest instance via the terminal. +## Trace-Based Tests -Check out the `tests/test.yaml` file. +Check out the `resources/test.yaml` file. ```yaml -# tests/test.yaml +# resources/test.yaml type: Test spec: @@ -493,24 +464,6 @@ spec: - attr:db.result contains "charizard" ``` -This file defines a test the same way you would through the Web UI. - -To run the test, run this command in the terminal: - -```bash -tracetest run test -f ./tests/test.yaml -``` - -```bash title="Output:" -✔ Pokeshop - Import (http://localhost:11633/test/ZVJwkpC4g/run/1/test) - trace id: 4eff1e124f67cf7a802b3c4fc51c19d4 - ✔ All HTTP Spans: Status code is 200 - ✔ Validate that this span always exists after the message queue - ✔ Validate that Redis is using Charizard. - ✔ Validate that the Postgres has Charizard. -``` - -![tracetest web ui overview](https://res.cloudinary.com/djwdcmwdz/image/upload/v1692356467/Blogposts/Docs/screely-1692356427154_ewzduy.png) - ## View Trace Spans Over Time in Grafana To access a historical overview of all the trace spans the Pokeshop App generates, jump over to Grafana on `http://localhost:3000`. diff --git a/docs/docs/examples-tutorials/recipes/running-tracetest-with-tempo.mdx b/docs/docs/examples-tutorials/recipes/running-tracetest-with-tempo.mdx index 4cbdd7b998..900ba1be52 100644 --- a/docs/docs/examples-tutorials/recipes/running-tracetest-with-tempo.mdx +++ b/docs/docs/examples-tutorials/recipes/running-tracetest-with-tempo.mdx @@ -17,10 +17,6 @@ keywords: image: https://res.cloudinary.com/djwdcmwdz/image/upload/v1698686403/docs/Blog_Thumbnail_14_rsvkmo.jpg --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; -import CodeBlock from '@theme/CodeBlock'; - :::note [Check out the source code on GitHub here.](https://github.com/kubeshop/tracetest/tree/main/examples/quick-start-tempo-nodejs) ::: @@ -33,19 +29,12 @@ import CodeBlock from '@theme/CodeBlock'; This is a simple 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. The infrastructure will use Tempo as the trace data store, and OpenTelemetry Collector to receive traces from the Node.js app and send them to Tempo. -```mdx-code-block - - -``` - ## Prerequisites **Tracetest Account**: - Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs. -- Create an [environment](/concepts/environments). -- Create an [environment token](/concepts/environment-tokens). -- Have access to the environment's [agent API key](/configuration/agent). +- Have access to the environment's [agent API key](https://app.tracetest.io/retrieve-token). **Docker**: Have [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine. @@ -63,17 +52,15 @@ cd tracetest/examples/quick-start-tempo-nodejs Follow these instructions to run the quick start: 1. Copy the `.env.template` file to `.env`. -2. Log into the [Tracetest app](https://app.tracetest.io/). -3. Fill out the [token](https://docs.tracetest.io/concepts/environment-tokens) and [API key](https://docs.tracetest.io/concepts/agent) details by editing your `.env` file. You can find these values in the Settings area for your environment. -4. Run `docker compose -f ./docker-compose.yaml -f ./docker-compose.agent.yaml up -d`. -5. This example is configured to use the Grafana Tempo Tracing Backend. Ensure the environment you're using to run this example is configured to use the Grafana Tempo Tracing Backend by clicking on Settings, Tracing Backend, Grafana Tempo, 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/`. +2. Fill out the [TRACETEST_TOKEN and ENVIRONMENT_ID](https://app.tracetest.io/retrieve-token) details by editing your `.env` file. +3. Run `docker compose run tracetest-run`. +4. 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 [Tracetest Agent](/getting-started/installation#install-the-tracetest-agent), [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main), [Grafana Tempo](https://github.com/grafana/tempo), and a Node.js app. +The project contains [Tracetest Agent](/getting-started/installation#install-the-tracetest-agent), [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main), and a Node.js app. The `docker-compose.yaml` file in the root directory of the quick start runs the Node.js app and the [Tracetest Agent](/concepts/agent) setup. @@ -84,7 +71,10 @@ The Node.js app is a simple Express app, contained in [the `app.js` file](https: Configure the `.env` like shown below. ```bash -TRACETEST_API_KEY="" +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" ``` The OpenTelemetry tracing is contained in the `tracing.otel.grpc.js` or `tracing.otel.http.js` files. Traces will be sent to Grafana Tempo. @@ -99,423 +89,30 @@ Enabling the tracer is done by preloading the trace file. As seen in the `packag }, ``` -## Configuring Grafana Tempo - -Configure Tempo as a Tracing Backend: - -```yaml title=tracetest-tracing-backend.yaml ---- -type: DataStore -spec: - name: Tempo - type: tempo - tempo: - type: grpc - grpc: - endpoint: tempo:9095 - tls: - insecure: true -``` - -```bash -tracetest config -t -tracetest apply datastore -f ./tracetest-tracing-backend.yaml -``` - ## Run the Node.js App, Grafana Tempo and OpenTelemetry Collector with Docker Compose -The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/docker-compose.yaml) and [`Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/Dockerfile) in the root directory are for the Node.js app. The `docker-compose.yaml` contains one service for the Node.js app. - -The [`docker-compose.agent.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/docker-compose.agent.yaml) is for the Tracetest Agent, Grafana Tempo, and OpenTelemetry Collector. +The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/docker-compose.yaml) and [`Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/Dockerfile) in the root directory are for the Node.js app. The `docker-compose.yaml` contains one service for the Node.js app, as well as the Tracetest Agent, Tempo, and OpenTelemetry Collector. [The `collector.config.yaml` configures the OpenTelemetry Collector](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-tempo-nodejs/collector.config.yaml). It receives traces via either `grpc` or `http`. Then, exports them to Tempo via the OTLP `exporter`. To start it, run this command: ```bash -docker compose -f ./docker-compose.yaml -f ./docker-compose.agent.yaml up -d +docker compose run tracetest-run ``` This will start the Node.js app the OpenTelemetry Collector and send the traces to Grafana Tempo. ## Run Tracetest Tests -1. Open [Tracetest](https://app.tracetest.io/) -2. [Configure Tempo as a tracing backend](/configuration/connecting-to-data-stores/tempo) 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](/cli/cli-installation-reference), [configure it](/cli/configuring-your-cli), and [run a test](/cli/running-tests). From the root of the quick start directory, run: - -```bash -tracetest configure -t -tracetest run test -f ./test-api.yaml -``` - -```mdx-code-block - - -``` - -## Prerequisites - -You will need [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine to run this quick start app! - -## Project Structure - -The project is built with Docker Compose. It contains two distinct `docker-compose.yaml` files. - -### 1. Node.js App - -The `docker-compose.yaml` file and `Dockerfile` in the root directory are for the Node.js app. - -### 2. Tracetest - -The `docker-compose.yaml` file, `collector.config.yaml`, `tracetest-provision.yaml`, and `tracetest-config.yaml` in the `tracetest` directory are for the setting up Tracetest, Tempo, and the OpenTelemetry Collector. - -The `tracetest` directory is self-contained and will run all the prerequisites for enabling OpenTelemetry traces and trace-based testing with Tracetest. - -### Docker Compose Network - -All `services` in the `docker-compose.yaml` are on the same network and will be reachable by hostname from within other services. For example, `tempo:4317` in the `collector.config.yaml` will map to the `tempo` service, where the port `4317` is the port where Tempo accepts traces. And, `tempo:9095` in the `tracetest-provision.yaml` will map to the `tempo` service and port `9095` where Tracetest will fetch trace data from Tempo. - -## Node.js App - -The Node.js app is a simple Express app, contained in the `app.js` file. - -The OpenTelemetry tracing is contained in the `tracing.otel.grpc.js` or `tracing.otel.http.js` files, respectively. -Traces will be sent to the OpenTelemetry Collector. - -Here's the content of the `tracing.otel.grpc.js` file: - -```js -const opentelemetry = require('@opentelemetry/sdk-node') -const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node') -const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc'); - -const sdk = new opentelemetry.NodeSDK({ - traceExporter: new OTLPTraceExporter({ url: 'http://otel-collector:4317' }), - instrumentations: [getNodeAutoInstrumentations()], -}) -sdk.start() -``` - -Depending on which of these you choose, traces will be sent to either the `grpc` or `http` endpoint. - -The hostnames and ports for these are: - -- GRPC: `http://otel-collector:4317` -- HTTP: `http://otel-collector:4318/v1/traces` - -Enabling the tracer is done by preloading the trace file. - -```bash -node -r ./tracing.otel.grpc.js app.js -``` - -In the `package.json` you will see two npm scripts for running the respective tracers alongside the `app.js`. - -```json -"scripts": { - "with-grpc-tracer":"node -r ./tracing.otel.grpc.js app.js", - "with-http-tracer":"node -r ./tracing.otel.http.js app.js" -}, -``` - -To start the server, run this command: - -```bash -npm run with-grpc-tracer -# or -npm run with-http-tracer -``` - -As you can see the `Dockerfile` uses the command above. - -```Dockerfile -FROM node:slim -WORKDIR /usr/src/app -COPY package*.json ./ -RUN npm install -COPY . . -EXPOSE 8080 -CMD [ "npm", "run", "with-grpc-tracer" ] -``` - -And, the `docker-compose.yaml` contains just one service for the Node.js app. - -```yaml -version: '3' -services: - app: - image: quick-start-nodejs - build: . - ports: - - "8080:8080" -``` - -To start it, run this command: - -```bash -docker compose build # optional if you haven't already built the image -docker compose up -``` - -This will start the Node.js app. But, you're not sending the traces anywhere. - -Let's fix this by configuring Tracetest and OpenTelemetry Collector. - -## Tracetest - -The `docker-compose.yaml` in the `tracetest` directory is configured with four services. - -- **Postgres** - Postgres is a prerequisite for Tracetest to work. It stores trace data when running the trace-based tests. -- [**OpenTelemetry Collector**](https://opentelemetry.io/docs/collector/) - A vendor-agnostic implementation of how to receive, process and export telemetry data. -- [**Tempo**](https://grafana.com/oss/tempo/) - Grafana Tempo is an open source, easy-to-use, and high-scale distributed tracing backend. -- [**Tracetest**](https://tracetest.io/) - Trace-based testing that generates end-to-end tests automatically from traces. - -```yaml -version: "3" -services: - tracetest: - image: kubeshop/tracetest:${TAG:-latest} - platform: linux/amd64 - volumes: - - type: bind - source: ./tracetest/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./tracetest/tracetest-provision.yaml - target: /app/provisioning.yaml - ports: - - 11633:11633 - command: --provisioning-file /app/provisioning.yaml - depends_on: - postgres: - condition: service_healthy - tempo: - condition: service_started - otel-collector: - condition: service_started - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:11633"] - interval: 1s - timeout: 3s - retries: 60 - environment: - TRACETEST_DEV: ${TRACETEST_DEV} - - postgres: - image: postgres:14 - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.59.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./tracetest/collector.config.yaml:/otel-local-config.yaml - depends_on: - - tempo - - tempo: - image: grafana/tempo:2.0.0 - command: ["-config.file=/etc/tempo.yaml"] - volumes: - - ./tracetest/tempo.config.yaml:/etc/tempo.yaml - -``` - -Tracetest depends on Postgres, Tempo and the OpenTelemetry Collector. All three services require config files to be loaded via a volume. The volumes are mapped from the root directory into the `tracetest` directory and the respective config files. - -To start both the Node.js app and Tracetest, we will run this command: - -```bash -docker-compose -f docker-compose.yaml -f tracetest/docker-compose.yaml up # add --build if the images are not built already -``` - -The `tempo.config.yaml` file contains the initial config for running Tempo. - -The key takeaway is the server block. - -```yaml -#... -server: - http_listen_port: 3100 - grpc_listen_port: 9095 -#... -``` - -We'll use the following code. Check out the full Tempo config for reference. - -```yaml -auth_enabled: false - -server: - http_listen_port: 3100 - grpc_listen_port: 9095 - -distributor: - receivers: # this configuration will listen on all ports and protocols that tempo is capable of. - jaeger: # the receives all come from the OpenTelemetry collector. more configuration information can - protocols: # be found there: https://github.com/open-telemetry/opentelemetry-collector/tree/master/receiver - thrift_http: # - grpc: # for a production deployment you should only enable the receivers you need! - thrift_binary: - thrift_compact: - zipkin: - otlp: - protocols: - http: - grpc: - opencensus: - -ingester: - trace_idle_period: 10s # the length of time after a trace has not received spans to consider it complete and flush it - max_block_bytes: 1_000_000 # cut the head block when it hits this size or ... - #traces_per_block: 1_000_000 - max_block_duration: 5m # this much time passes - -compactor: - compaction: - compaction_window: 1h # blocks in this time window will be compacted together - max_compaction_objects: 1000000 # maximum size of compacted blocks - block_retention: 1h - compacted_block_retention: 10m - -storage: - trace: - backend: local # backend configuration to use - wal: - path: /tmp/tempo/wal # where to store the the wal locally - #bloom_filter_false_positive: .05 # bloom filter false positive rate. lower values create larger filters but fewer false positives - #index_downsample: 10 # number of traces per index record - local: - path: /tmp/tempo/blocks - pool: - max_workers: 100 # the worker pool mainly drives querying, but is also used for polling the blocklist - queue_depth: 10000 - -``` - -The `tracetest-config.yaml` file contains the basic setup of connecting Tracetest to the Postgres instance and defining the trace data store and exporter. The exporter is set to the OpenTelemetry Collector. - -```yaml -# tracetest-config.yaml - -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable - -telemetry: - exporters: - collector: - serviceName: tracetest - sampling: 100 # 100% - exporter: - type: collector - collector: - endpoint: otel-collector:4317 - -server: - telemetry: - exporter: collector - -``` - -The `tracetest-provision.yaml` file defines the trace data store, set to Tempo, meaning the traces will be stored in Tempo and Tracetest will fetch them from Tempo when running tests. - -How does Tracetest fetch traces? - -Tracetest uses `tempo:9095` to connect to Tempo and fetch trace data. - -```yaml -# tracetest-provision.yaml - ---- -type: PollingProfile -spec: - name: Default - strategy: periodic - default: true - periodic: - retryDelay: 5s - timeout: 10m - ---- -type: DataStore -spec: - name: Tempo - type: tempo - tempo: - type: grpc - grpc: - endpoint: tempo:9095 - tls: - insecure: true - -``` - -How do traces reach Tempo? - -The `collector.config.yaml` explains that. It receives traces via either `grpc` or `http`. Then, exports them to Tempo's OTLP gRPC endpoint `tempo:4317`. - -```yaml -# collector.config.yaml -receivers: - otlp: - protocols: - grpc: - http: - -processors: - batch: - timeout: 100ms - -exporters: - logging: - loglevel: debug - otlp/1: - endpoint: tempo:4317 - tls: - insecure: true - -service: - pipelines: - traces: - receivers: [otlp] - processors: [batch] - exporters: [otlp/1] - -``` - -## Run Both the Node.js App and Tracetest - -To start both the Node.js app and Tracetest, run this command: - -```bash -docker-compose -f docker-compose.yaml -f tracetest/docker-compose.yaml up # add --build if the images are not built already -``` - -This will start your Tracetest instance on `http://localhost:11633/`. +This will: +1. Start the Node.js app, the OpenTelemetry Collector, and send the traces to Tempo. +2. Start the Tracetest Agent. +3. Configure the tracing backend and create tests in your environment. +4. Run the tests. Open the URL and start creating tests! Make sure to use the `http://app:8080/` URL in your test creation, because your Node.js app and Tracetest are in the same network. -```mdx-code-block - - -``` - ## Learn More Feel free to check out our [examples in GitHub](https://github.com/kubeshop/tracetest/tree/main/examples) and join our [Slack Community](https://dub.sh/tracetest-community) for more info! diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/.env.template b/examples/quick-start-grafana-cloud-tempo-nodejs/.env.template index d780ddb12c..4f29f672ec 100644 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/.env.template +++ b/examples/quick-start-grafana-cloud-tempo-nodejs/.env.template @@ -1,2 +1,8 @@ -TRACETEST_API_KEY="" -TRACETEST_API_TOKEN="" +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" + +# https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ +GRAFANA_AUTH_READ_HASH="" +GRAFANA_AUTH_WRITE_HASH="" diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/.gitignore b/examples/quick-start-grafana-cloud-tempo-nodejs/.gitignore index d8f337266f..e34636b928 100644 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/.gitignore +++ b/examples/quick-start-grafana-cloud-tempo-nodejs/.gitignore @@ -1,3 +1,4 @@ node_modules .DS_Store .env +/resources/datastore.yaml \ No newline at end of file diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/Dockerfile.tracetest b/examples/quick-start-grafana-cloud-tempo-nodejs/Dockerfile.tracetest new file mode 100644 index 0000000000..883f239155 --- /dev/null +++ b/examples/quick-start-grafana-cloud-tempo-nodejs/Dockerfile.tracetest @@ -0,0 +1,11 @@ +FROM alpine + +WORKDIR /app +ARG TRACETEST_IMAGE_VERSION=v1.4.0 + +RUN apk --update add bash jq curl +RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION + +WORKDIR /resources + +ENTRYPOINT ["echo", "Tracetest CLI installed"] diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/collector.config.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/collector.config.yaml index 4c415a7bbc..027ea4f23b 100644 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/collector.config.yaml +++ b/examples/quick-start-grafana-cloud-tempo-nodejs/collector.config.yaml @@ -2,18 +2,26 @@ receivers: otlp: protocols: grpc: + endpoint: 0.0.0.0:4317 http: + endpoint: 0.0.0.0:4318 + +processors: + batch: + timeout: 100ms exporters: logging: - verbosity: detailed + loglevel: debug otlp: endpoint: tempo-us-central1.grafana.net:443 headers: - authorization: Basic + authorization: Basic ${env:GRAFANA_AUTH_WRITE_HASH} + # https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ service: pipelines: traces: receivers: [otlp] + processors: [batch] exporters: [logging, otlp] diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.agent.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.agent.yaml deleted file mode 100644 index b10263ddb5..0000000000 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.agent.yaml +++ /dev/null @@ -1,18 +0,0 @@ -version: '3' -services: - # Cloud-based Managed Tracetest - tracetest-agent: - image: kubeshop/tracetest-agent:latest - command: - - "--mode=verbose" - environment: - # Find the Agent API Key here: https://docs.tracetest.io/configuration/agent - - TRACETEST_API_KEY=${TRACETEST_API_KEY} - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.100.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./collector.config.yaml:/otel-local-config.yaml diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.yaml index d415e83d4f..6cc4f39914 100644 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.yaml +++ b/examples/quick-start-grafana-cloud-tempo-nodejs/docker-compose.yaml @@ -1,7 +1,66 @@ -version: '3' +version: "3" + services: app: image: quick-start-nodejs build: . ports: - "8080:8080" + depends_on: + otel-collector: + condition: service_started + + otel-collector: + image: otel/opentelemetry-collector-contrib:0.105.0 + command: + - "--config" + - "/otel-local-config.yaml" + environment: + - GRAFANA_AUTH_WRITE_HASH + volumes: + - ./collector.config.yaml:/otel-local-config.yaml + + # Cloud-based Managed Tracetest + tracetest-agent: + image: kubeshop/tracetest-agent:latest + environment: + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} + + tracetest-apply: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + GRAFANA_AUTH_READ_HASH: ${GRAFANA_AUTH_READ_HASH} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null + depends_on: + app: + condition: service_started + tracetest-agent: + condition: service_started + + tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/resources/apply.sh b/examples/quick-start-grafana-cloud-tempo-nodejs/resources/apply.sh new file mode 100644 index 0000000000..edc769ab6b --- /dev/null +++ b/examples/quick-start-grafana-cloud-tempo-nodejs/resources/apply.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID +GRAFANA_HASH=$GRAFANA_AUTH_READ_HASH + +apply() { + echo "Configuring TraceTest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Applying Resources" + echo " +type: DataStore +spec: + id: current + name: Grafana Tempo Cloud + type: tempo + tempo: + type: http + http: + url: https://tempo-us-central1.grafana.net/tempo + headers: + Authorization: Basic ${GRAFANA_HASH} +" > /resources/datastore.yaml + + tracetest apply datastore -f /resources/datastore.yaml + tracetest apply test -f /resources/test.yaml +} + +apply diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/resources/run.sh b/examples/quick-start-grafana-cloud-tempo-nodejs/resources/run.sh new file mode 100644 index 0000000000..05d0f41724 --- /dev/null +++ b/examples/quick-start-grafana-cloud-tempo-nodejs/resources/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +run() { + echo "Configuring Tracetest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Running Trace-Based Tests..." + tracetest run test -f /resources/test.yaml +} + +run diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/test-api.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/resources/test.yaml similarity index 100% rename from examples/quick-start-grafana-cloud-tempo-nodejs/test-api.yaml rename to examples/quick-start-grafana-cloud-tempo-nodejs/resources/test.yaml diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest-tracing-backend.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest-tracing-backend.yaml deleted file mode 100644 index 6422deb6f8..0000000000 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest-tracing-backend.yaml +++ /dev/null @@ -1,12 +0,0 @@ -type: DataStore -spec: - id: tempo-cloud - name: Tempo - type: tempo - tempo: - type: http - http: - url: https://tempo-us-central1.grafana.net/tempo - headers: - authorization: Basic - tls: {} diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/collector.config.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/collector.config.yaml deleted file mode 100644 index ee7f117abd..0000000000 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/collector.config.yaml +++ /dev/null @@ -1,27 +0,0 @@ -receivers: - otlp: - protocols: - grpc: - http: - -processors: - batch: - timeout: 100ms - -exporters: - logging: - loglevel: debug - otlp: - endpoint: tempo-us-central1.grafana.net:443 - headers: - authorization: Basic - # https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ - tls: - insecure: false - -service: - pipelines: - traces: - receivers: [otlp] - processors: [batch] - exporters: [otlp] diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/docker-compose.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/docker-compose.yaml deleted file mode 100644 index 5deaed4052..0000000000 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/docker-compose.yaml +++ /dev/null @@ -1,46 +0,0 @@ -version: "3" -services: - tracetest: - image: kubeshop/tracetest:${TAG:-latest} - platform: linux/amd64 - volumes: - - type: bind - source: ./tracetest/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./tracetest/tracetest-provision.yaml - target: /app/provisioning.yaml - ports: - - 11633:11633 - command: --provisioning-file /app/provisioning.yaml - depends_on: - postgres: - condition: service_healthy - otel-collector: - condition: service_started - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:11633"] - interval: 1s - timeout: 3s - retries: 60 - environment: - TRACETEST_DEV: ${TRACETEST_DEV} - - postgres: - image: postgres:14 - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.73.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./tracetest/collector.config.yaml:/otel-local-config.yaml diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-config.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-config.yaml deleted file mode 100644 index 5e732f6d38..0000000000 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable diff --git a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-provision.yaml b/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-provision.yaml deleted file mode 100644 index bc4053fc65..0000000000 --- a/examples/quick-start-grafana-cloud-tempo-nodejs/tracetest/tracetest-provision.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -type: DataStore -spec: - name: Grafana Tempo Cloud - type: tempo - tempo: - type: http - http: - url: https://tempo-us-central1.grafana.net/tempo - headers: - Authorization: Basic - # https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ diff --git a/examples/quick-start-tempo-nodejs/.env.template b/examples/quick-start-tempo-nodejs/.env.template index d780ddb12c..c0437a9d95 100644 --- a/examples/quick-start-tempo-nodejs/.env.template +++ b/examples/quick-start-tempo-nodejs/.env.template @@ -1,2 +1,4 @@ -TRACETEST_API_KEY="" -TRACETEST_API_TOKEN="" +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" diff --git a/examples/quick-start-tempo-nodejs/Dockerfile.tracetest b/examples/quick-start-tempo-nodejs/Dockerfile.tracetest new file mode 100644 index 0000000000..883f239155 --- /dev/null +++ b/examples/quick-start-tempo-nodejs/Dockerfile.tracetest @@ -0,0 +1,11 @@ +FROM alpine + +WORKDIR /app +ARG TRACETEST_IMAGE_VERSION=v1.4.0 + +RUN apk --update add bash jq curl +RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION + +WORKDIR /resources + +ENTRYPOINT ["echo", "Tracetest CLI installed"] diff --git a/examples/quick-start-tempo-nodejs/app.js b/examples/quick-start-tempo-nodejs/app.js index 279dbe1a13..34ae262e57 100644 --- a/examples/quick-start-tempo-nodejs/app.js +++ b/examples/quick-start-tempo-nodejs/app.js @@ -1,8 +1,10 @@ -const express = require("express") -const app = express() +const express = require("express"); +const app = express(); + app.get("/", (req, res) => { - res.send("Hello World") -}) + res.send("Hello World"); +}); + app.listen(8080, () => { - console.log(`Listening for requests on http://localhost:8080`) -}) + console.log(`Listening for requests on http://localhost:8080`); +}); diff --git a/examples/quick-start-tempo-nodejs/docker-compose.agent.yaml b/examples/quick-start-tempo-nodejs/docker-compose.agent.yaml deleted file mode 100644 index a2ee6d7bea..0000000000 --- a/examples/quick-start-tempo-nodejs/docker-compose.agent.yaml +++ /dev/null @@ -1,22 +0,0 @@ -version: '3' -services: - # Cloud-based Managed Tracetest - tracetest-agent: - image: kubeshop/tracetest-agent:latest - environment: - # Find the Agent API Key here: https://docs.tracetest.io/configuration/agent - - TRACETEST_API_KEY=${TRACETEST_API_KEY} - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.100.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./collector.config.yaml:/otel-local-config.yaml - - tempo: - image: grafana/tempo:2.4.2 - command: ["-config.file=/etc/tempo.yaml"] - volumes: - - ./tracetest/tempo.config.yaml:/etc/tempo.yaml diff --git a/examples/quick-start-tempo-nodejs/docker-compose.yaml b/examples/quick-start-tempo-nodejs/docker-compose.yaml index d415e83d4f..75b2e0da9c 100644 --- a/examples/quick-start-tempo-nodejs/docker-compose.yaml +++ b/examples/quick-start-tempo-nodejs/docker-compose.yaml @@ -5,3 +5,67 @@ services: build: . ports: - "8080:8080" + depends_on: + tempo: + condition: service_started + + otel-collector: + image: otel/opentelemetry-collector-contrib:0.100.0 + command: + - "--config" + - "/otel-local-config.yaml" + volumes: + - ./collector.config.yaml:/otel-local-config.yaml + + tempo: + image: grafana/tempo:2.4.2 + command: ["-config.file=/etc/tempo.yaml"] + volumes: + - ./tempo.config.yaml:/etc/tempo.yaml + depends_on: + otel-collector: + condition: service_started + + # Cloud-based Managed Tracetest + tracetest-agent: + image: kubeshop/tracetest-agent:latest + environment: + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} + + tracetest-apply: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null + depends_on: + app: + condition: service_started + tracetest-agent: + condition: service_started + + tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully diff --git a/examples/quick-start-tempo-nodejs/resources/apply.sh b/examples/quick-start-tempo-nodejs/resources/apply.sh new file mode 100644 index 0000000000..13b878ba47 --- /dev/null +++ b/examples/quick-start-tempo-nodejs/resources/apply.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +apply() { + echo "Configuring TraceTest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Applying Resources" + tracetest apply datastore -f /resources/datastore.yaml + tracetest apply test -f /resources/test.yaml +} + +apply diff --git a/examples/quick-start-tempo-nodejs/tracetest-tracing-backend.yaml b/examples/quick-start-tempo-nodejs/resources/datastore.yaml similarity index 100% rename from examples/quick-start-tempo-nodejs/tracetest-tracing-backend.yaml rename to examples/quick-start-tempo-nodejs/resources/datastore.yaml diff --git a/examples/quick-start-tempo-nodejs/resources/run.sh b/examples/quick-start-tempo-nodejs/resources/run.sh new file mode 100644 index 0000000000..05d0f41724 --- /dev/null +++ b/examples/quick-start-tempo-nodejs/resources/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +run() { + echo "Configuring Tracetest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Running Trace-Based Tests..." + tracetest run test -f /resources/test.yaml +} + +run diff --git a/examples/quick-start-tempo-nodejs/test-api.yaml b/examples/quick-start-tempo-nodejs/resources/test.yaml similarity index 100% rename from examples/quick-start-tempo-nodejs/test-api.yaml rename to examples/quick-start-tempo-nodejs/resources/test.yaml diff --git a/examples/quick-start-tempo-nodejs/tempo.config.yaml b/examples/quick-start-tempo-nodejs/tempo.config.yaml new file mode 100644 index 0000000000..70df8bdd72 --- /dev/null +++ b/examples/quick-start-tempo-nodejs/tempo.config.yaml @@ -0,0 +1,46 @@ +auth_enabled: false + +server: + http_listen_port: 3100 + grpc_listen_port: 9095 + +distributor: + receivers: # this configuration will listen on all ports and protocols that tempo is capable of. + jaeger: # the receives all come from the OpenTelemetry collector. more configuration information can + protocols: # be found there: https://github.com/open-telemetry/opentelemetry-collector/tree/master/receiver + thrift_http: # + grpc: # for a production deployment you should only enable the receivers you need! + thrift_binary: + thrift_compact: + zipkin: + otlp: + protocols: + http: + grpc: + opencensus: + +ingester: + trace_idle_period: 10s # the length of time after a trace has not received spans to consider it complete and flush it + max_block_bytes: 1_000_000 # cut the head block when it hits this size or ... + #traces_per_block: 1_000_000 + max_block_duration: 5m # this much time passes + +compactor: + compaction: + compaction_window: 1h # blocks in this time window will be compacted together + max_compaction_objects: 1000000 # maximum size of compacted blocks + block_retention: 1h + compacted_block_retention: 10m + +storage: + trace: + backend: local # backend configuration to use + wal: + path: /tmp/tempo/wal # where to store the the wal locally + #bloom_filter_false_positive: .05 # bloom filter false positive rate. lower values create larger filters but fewer false positives + #index_downsample: 10 # number of traces per index record + local: + path: /tmp/tempo/blocks + pool: + max_workers: 100 # the worker pool mainly drives querying, but is also used for polling the blocklist + queue_depth: 10000 diff --git a/examples/quick-start-tempo-nodejs/tracetest/docker-compose.yaml b/examples/quick-start-tempo-nodejs/tracetest/docker-compose.yaml deleted file mode 100644 index 5f732b20a4..0000000000 --- a/examples/quick-start-tempo-nodejs/tracetest/docker-compose.yaml +++ /dev/null @@ -1,56 +0,0 @@ -version: "3" -services: - tracetest: - image: kubeshop/tracetest:${TAG:-latest} - platform: linux/amd64 - volumes: - - type: bind - source: ./tracetest/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./tracetest/tracetest-provision.yaml - target: /app/provisioning.yaml - ports: - - 11633:11633 - command: --provisioning-file /app/provisioning.yaml - depends_on: - postgres: - condition: service_healthy - tempo: - condition: service_started - otel-collector: - condition: service_started - healthcheck: - test: ["CMD", "wget", "--spider", "localhost:11633"] - interval: 1s - timeout: 3s - retries: 60 - environment: - TRACETEST_DEV: ${TRACETEST_DEV} - - postgres: - image: postgres:14 - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.100.0 - command: - - "--config" - - "/otel-local-config.yaml" - volumes: - - ./collector.config.yaml:/otel-local-config.yaml - depends_on: - - tempo - - tempo: - image: grafana/tempo:2.4.2 - command: ["-config.file=/etc/tempo.yaml"] - volumes: - - ./tracetest/tempo.config.yaml:/etc/tempo.yaml diff --git a/examples/quick-start-tempo-nodejs/tracetest/tempo.config.yaml b/examples/quick-start-tempo-nodejs/tracetest/tempo.config.yaml deleted file mode 100644 index 76b0ac3e5b..0000000000 --- a/examples/quick-start-tempo-nodejs/tracetest/tempo.config.yaml +++ /dev/null @@ -1,46 +0,0 @@ -auth_enabled: false - -server: - http_listen_port: 3100 - grpc_listen_port: 9095 - -distributor: - receivers: # this configuration will listen on all ports and protocols that tempo is capable of. - jaeger: # the receives all come from the OpenTelemetry collector. more configuration information can - protocols: # be found there: https://github.com/open-telemetry/opentelemetry-collector/tree/master/receiver - thrift_http: # - grpc: # for a production deployment you should only enable the receivers you need! - thrift_binary: - thrift_compact: - zipkin: - otlp: - protocols: - http: - grpc: - opencensus: - -ingester: - trace_idle_period: 10s # the length of time after a trace has not received spans to consider it complete and flush it - max_block_bytes: 1_000_000 # cut the head block when it hits this size or ... - #traces_per_block: 1_000_000 - max_block_duration: 5m # this much time passes - -compactor: - compaction: - compaction_window: 1h # blocks in this time window will be compacted together - max_compaction_objects: 1000000 # maximum size of compacted blocks - block_retention: 1h - compacted_block_retention: 10m - -storage: - trace: - backend: local # backend configuration to use - wal: - path: /tmp/tempo/wal # where to store the the wal locally - #bloom_filter_false_positive: .05 # bloom filter false positive rate. lower values create larger filters but fewer false positives - #index_downsample: 10 # number of traces per index record - local: - path: /tmp/tempo/blocks - pool: - max_workers: 100 # the worker pool mainly drives querying, but is also used for polling the blocklist - queue_depth: 10000 diff --git a/examples/quick-start-tempo-nodejs/tracetest/tracetest-config.yaml b/examples/quick-start-tempo-nodejs/tracetest/tracetest-config.yaml deleted file mode 100644 index 5e732f6d38..0000000000 --- a/examples/quick-start-tempo-nodejs/tracetest/tracetest-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/.env.template b/examples/tracetest-grafana-cloud-tempo-pokeshop/.env.template index d780ddb12c..4f29f672ec 100644 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/.env.template +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/.env.template @@ -1,2 +1,8 @@ -TRACETEST_API_KEY="" -TRACETEST_API_TOKEN="" +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" + +# https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ +GRAFANA_AUTH_READ_HASH="" +GRAFANA_AUTH_WRITE_HASH="" diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/Dockerfile.tracetest b/examples/tracetest-grafana-cloud-tempo-pokeshop/Dockerfile.tracetest new file mode 100644 index 0000000000..883f239155 --- /dev/null +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/Dockerfile.tracetest @@ -0,0 +1,11 @@ +FROM alpine + +WORKDIR /app +ARG TRACETEST_IMAGE_VERSION=v1.4.0 + +RUN apk --update add bash jq curl +RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION + +WORKDIR /resources + +ENTRYPOINT ["echo", "Tracetest CLI installed"] diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/collector.config.yaml b/examples/tracetest-grafana-cloud-tempo-pokeshop/collector.config.yaml index 4c415a7bbc..027ea4f23b 100644 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/collector.config.yaml +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/collector.config.yaml @@ -2,18 +2,26 @@ receivers: otlp: protocols: grpc: + endpoint: 0.0.0.0:4317 http: + endpoint: 0.0.0.0:4318 + +processors: + batch: + timeout: 100ms exporters: logging: - verbosity: detailed + loglevel: debug otlp: endpoint: tempo-us-central1.grafana.net:443 headers: - authorization: Basic + authorization: Basic ${env:GRAFANA_AUTH_WRITE_HASH} + # https://grafana.com/blog/2021/04/13/how-to-send-traces-to-grafana-clouds-tempo-service-with-opentelemetry-collector/ service: pipelines: traces: receivers: [otlp] + processors: [batch] exporters: [logging, otlp] diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/docker-compose.yml b/examples/tracetest-grafana-cloud-tempo-pokeshop/docker-compose.yml index 6fcd539f66..6c38d372e6 100644 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/docker-compose.yml +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/docker-compose.yml @@ -1,25 +1,60 @@ version: "3" services: + otel-collector: + image: otel/opentelemetry-collector-contrib:0.105.0 + command: + - "--config" + - "/otel-local-config.yaml" + environment: + - GRAFANA_AUTH_WRITE_HASH + volumes: + - ./collector.config.yaml:/otel-local-config.yaml # Cloud-based Managed Tracetest tracetest-agent: image: kubeshop/tracetest-agent:latest - command: - - "--mode=verbose" environment: - # Find the Agent API Key here: https://docs.tracetest.io/configuration/agent - - TRACETEST_API_KEY=${TRACETEST_API_KEY} - # Tracetest End + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} - # OpenTelemetry - otel-collector: - image: otel/opentelemetry-collector-contrib:0.101.0 - command: - - "--config" - - "/otel-local-config.yaml" + tracetest-apply: + build: + dockerfile: Dockerfile.tracetest volumes: - - ./collector.config.yaml:/otel-local-config.yaml - # OpenTelemetry End + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + GRAFANA_AUTH_READ_HASH: ${GRAFANA_AUTH_READ_HASH} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null + depends_on: + demo-api: + condition: service_started + tracetest-agent: + condition: service_started + + tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully + # Tracetest end # Demo postgres: @@ -72,6 +107,10 @@ services: timeout: 3s retries: 60 depends_on: + otel-collector: + condition: service_started + demo-worker: + condition: service_started postgres: condition: service_healthy demo-cache: diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/apply.sh b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/apply.sh new file mode 100644 index 0000000000..edc769ab6b --- /dev/null +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/apply.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID +GRAFANA_HASH=$GRAFANA_AUTH_READ_HASH + +apply() { + echo "Configuring TraceTest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Applying Resources" + echo " +type: DataStore +spec: + id: current + name: Grafana Tempo Cloud + type: tempo + tempo: + type: http + http: + url: https://tempo-us-central1.grafana.net/tempo + headers: + Authorization: Basic ${GRAFANA_HASH} +" > /resources/datastore.yaml + + tracetest apply datastore -f /resources/datastore.yaml + tracetest apply test -f /resources/test.yaml +} + +apply diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/datastore.yaml b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/datastore.yaml new file mode 100644 index 0000000000..1c4bff5a26 --- /dev/null +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/datastore.yaml @@ -0,0 +1,13 @@ + +type: DataStore +spec: + id: current + name: Grafana Tempo Cloud + type: tempo + tempo: + type: http + http: + url: https://tempo-us-central1.grafana.net/tempo + headers: + Authorization: Basic Mzc0OTIzOmdsY19leUp2SWpvaU56ZzROVEV3SWl3aWJpSTZJbk4wWVdOckxUVXlPVEF6TWkxb2RDMXlaV0ZrTFcxNUxYUnZhMlZ1SWl3aWF5STZJbmszUzFOSk0wZHBUREl4TmpkcE1FWkxORFphTUdsVGFpSXNJbTBpT25zaWNpSTZJblZ6SW4xOQ== + diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/run.sh b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/run.sh new file mode 100644 index 0000000000..05d0f41724 --- /dev/null +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +run() { + echo "Configuring Tracetest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Running Trace-Based Tests..." + tracetest run test -f /resources/test.yaml +} + +run diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/test.yaml b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/test.yaml similarity index 96% rename from examples/tracetest-grafana-cloud-tempo-pokeshop/tests/test.yaml rename to examples/tracetest-grafana-cloud-tempo-pokeshop/resources/test.yaml index 45424e2412..891654fd79 100644 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/test.yaml +++ b/examples/tracetest-grafana-cloud-tempo-pokeshop/resources/test.yaml @@ -8,7 +8,7 @@ spec: httpRequest: method: POST url: http://demo-api:8081/pokemon/import - body: "{\"id\":837483}" + body: "{\"id\":6}" headers: - key: Content-Type value: application/json diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_get.sh b/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_get.sh deleted file mode 100644 index 4d5faaf1b1..0000000000 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_get.sh +++ /dev/null @@ -1 +0,0 @@ -curl -d '' -H "Content-Type: application/json" -X GET http://localhost:8081/pokemon \ No newline at end of file diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_post.sh b/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_post.sh deleted file mode 100644 index cdffda742f..0000000000 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/curl_post.sh +++ /dev/null @@ -1 +0,0 @@ -curl -d '{"id":6}' -H "Content-Type: application/json" -X POST http://localhost:8081/pokemon/import \ No newline at end of file diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/post-mortem.yaml b/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/post-mortem.yaml deleted file mode 100644 index 94c884cb46..0000000000 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/tests/post-mortem.yaml +++ /dev/null @@ -1,13 +0,0 @@ -type: Test -spec: - id: rA8wtOjVR - name: post mortem pokemon import - trigger: - type: traceid - traceid: - id: ${var:traceId} - specs: - - selector: span[tracetest.span.type="general" name="import pokemon"] - name: Validate there are no exceptions when importing pokemon. - assertions: - - attr:span.events not-contains "exception" diff --git a/examples/tracetest-grafana-cloud-tempo-pokeshop/tracetest-tracing-backend.yaml b/examples/tracetest-grafana-cloud-tempo-pokeshop/tracetest-tracing-backend.yaml deleted file mode 100644 index 6422deb6f8..0000000000 --- a/examples/tracetest-grafana-cloud-tempo-pokeshop/tracetest-tracing-backend.yaml +++ /dev/null @@ -1,12 +0,0 @@ -type: DataStore -spec: - id: tempo-cloud - name: Tempo - type: tempo - tempo: - type: http - http: - url: https://tempo-us-central1.grafana.net/tempo - headers: - authorization: Basic - tls: {} diff --git a/examples/tracetest-grafana-tempo-pokeshop/.env.template b/examples/tracetest-grafana-tempo-pokeshop/.env.template new file mode 100644 index 0000000000..c0437a9d95 --- /dev/null +++ b/examples/tracetest-grafana-tempo-pokeshop/.env.template @@ -0,0 +1,4 @@ +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" diff --git a/examples/tracetest-grafana-tempo-pokeshop/.gitignore b/examples/tracetest-grafana-tempo-pokeshop/.gitignore index 319a7df331..09981121a5 100644 --- a/examples/tracetest-grafana-tempo-pokeshop/.gitignore +++ b/examples/tracetest-grafana-tempo-pokeshop/.gitignore @@ -1,3 +1,4 @@ node_modules .DS_Store -tempo-data \ No newline at end of file +tempo-data +.env diff --git a/examples/tracetest-grafana-tempo-pokeshop/Dockerfile.tracetest b/examples/tracetest-grafana-tempo-pokeshop/Dockerfile.tracetest new file mode 100644 index 0000000000..883f239155 --- /dev/null +++ b/examples/tracetest-grafana-tempo-pokeshop/Dockerfile.tracetest @@ -0,0 +1,11 @@ +FROM alpine + +WORKDIR /app +ARG TRACETEST_IMAGE_VERSION=v1.4.0 + +RUN apk --update add bash jq curl +RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION + +WORKDIR /resources + +ENTRYPOINT ["echo", "Tracetest CLI installed"] diff --git a/examples/tracetest-grafana-tempo-pokeshop/docker-compose.yml b/examples/tracetest-grafana-tempo-pokeshop/docker-compose.yml index 71b74a5e9a..5c7c87aaa6 100644 --- a/examples/tracetest-grafana-tempo-pokeshop/docker-compose.yml +++ b/examples/tracetest-grafana-tempo-pokeshop/docker-compose.yml @@ -1,29 +1,52 @@ version: "3" services: - - # Tracetest - tracetest: - image: kubeshop/tracetest:v0.14.3 + # Cloud-based Managed Tracetest + tracetest-agent: + image: kubeshop/tracetest-agent:latest + environment: + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} + tracetest-apply: + build: + dockerfile: Dockerfile.tracetest volumes: - - ./tracetest.config.yaml:/app/tracetest.yaml - - ./tracetest.provision.yaml:/app/provisioning.yaml - ports: - - 11633:11633 - command: --provisioning-file /app/provisioning.yaml - extra_hosts: - - "host.docker.internal:host-gateway" + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null depends_on: - postgres: - condition: service_healthy - otel-collector: + demo-api: + condition: service_started + tracetest-agent: condition: service_started + + tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources environment: - TRACETEST_DEV: ${TRACETEST_DEV} + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully # Tracetest End # Grafana otel-collector: - image: otel/opentelemetry-collector-contrib:0.59.0 + image: otel/opentelemetry-collector-contrib:0.100.0 command: - "--config" - "/otel-local-config.yaml" @@ -33,15 +56,15 @@ services: - tempo tempo: image: grafana/tempo:latest - command: [ "-config.file=/etc/tempo.yaml" ] + command: ["-config.file=/etc/tempo.yaml"] volumes: - ./tempo.config.yaml:/etc/tempo.yaml - ./tempo-data:/tmp/tempo ports: - - "3200:3200" # tempo http - - "9095:9095" # tempo grpc - - "4317" # otlp grpc - - "4318" # otlp http + - "3200:3200" # tempo http + - "9095:9095" # tempo grpc + - "4317" # otlp grpc + - "4318" # otlp http grafana: image: grafana/grafana:9.4.3 volumes: @@ -106,6 +129,12 @@ services: timeout: 3s retries: 60 depends_on: + demo-worker: + condition: service_started + grafana: + condition: service_started + otel-collector: + condition: service_started postgres: condition: service_healthy demo-cache: diff --git a/examples/tracetest-grafana-tempo-pokeshop/resources/apply.sh b/examples/tracetest-grafana-tempo-pokeshop/resources/apply.sh new file mode 100644 index 0000000000..13b878ba47 --- /dev/null +++ b/examples/tracetest-grafana-tempo-pokeshop/resources/apply.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +apply() { + echo "Configuring TraceTest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Applying Resources" + tracetest apply datastore -f /resources/datastore.yaml + tracetest apply test -f /resources/test.yaml +} + +apply diff --git a/examples/quick-start-tempo-nodejs/tracetest/tracetest-provision.yaml b/examples/tracetest-grafana-tempo-pokeshop/resources/datastore.yaml similarity index 51% rename from examples/quick-start-tempo-nodejs/tracetest/tracetest-provision.yaml rename to examples/tracetest-grafana-tempo-pokeshop/resources/datastore.yaml index 34202f9a26..51177cab93 100644 --- a/examples/quick-start-tempo-nodejs/tracetest/tracetest-provision.yaml +++ b/examples/tracetest-grafana-tempo-pokeshop/resources/datastore.yaml @@ -1,16 +1,6 @@ ---- -type: PollingProfile -spec: - name: Default - strategy: periodic - default: true - periodic: - retryDelay: 5s - timeout: 10m - ---- type: DataStore spec: + id: current name: Tempo type: tempo tempo: diff --git a/examples/tracetest-grafana-tempo-pokeshop/resources/run.sh b/examples/tracetest-grafana-tempo-pokeshop/resources/run.sh new file mode 100644 index 0000000000..05d0f41724 --- /dev/null +++ b/examples/tracetest-grafana-tempo-pokeshop/resources/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +run() { + echo "Configuring Tracetest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Running Trace-Based Tests..." + tracetest run test -f /resources/test.yaml +} + +run diff --git a/examples/tracetest-grafana-tempo-pokeshop/resources/test.yaml b/examples/tracetest-grafana-tempo-pokeshop/resources/test.yaml new file mode 100644 index 0000000000..c64b462f4c --- /dev/null +++ b/examples/tracetest-grafana-tempo-pokeshop/resources/test.yaml @@ -0,0 +1,32 @@ +type: Test +spec: + id: ZVJwkpC4g + name: Pokeshop - Import + description: Import a Pokemon + trigger: + type: http + httpRequest: + method: POST + url: http://demo-api:8081/pokemon/import + body: '{"id":6}' + headers: + - key: Content-Type + value: application/json + specs: + - selector: span[tracetest.span.type="http"] + name: "All HTTP Spans: Status code is 200" + assertions: + - attr:http.status_code = 200 + - selector: span[tracetest.span.type="general" name="import pokemon"] + name: Validate that this span always exists after the message queue + assertions: + - attr:tracetest.selected_spans.count = 1 + - attr:span.events not-contains "exception" + - selector: span[tracetest.span.type="database" name="get pokemon_6" db.system="redis" db.operation="get" db.redis.database_index="0"] + name: Validate that Redis is using Charizard. + assertions: + - attr:db.payload = '{"key":"pokemon_6"}' + - selector: span[tracetest.span.type="database" name="create postgres.pokemon" db.system="postgres" db.name="postgres" db.user="postgres" db.operation="create" db.sql.table="pokemon"] + name: Validate that the Postgres has Charizard. + assertions: + - attr:db.result contains "charizard" diff --git a/examples/tracetest-grafana-tempo-pokeshop/tests/curl_get.sh b/examples/tracetest-grafana-tempo-pokeshop/tests/curl_get.sh deleted file mode 100644 index 4d5faaf1b1..0000000000 --- a/examples/tracetest-grafana-tempo-pokeshop/tests/curl_get.sh +++ /dev/null @@ -1 +0,0 @@ -curl -d '' -H "Content-Type: application/json" -X GET http://localhost:8081/pokemon \ No newline at end of file diff --git a/examples/tracetest-grafana-tempo-pokeshop/tests/curl_post.sh b/examples/tracetest-grafana-tempo-pokeshop/tests/curl_post.sh deleted file mode 100644 index cdffda742f..0000000000 --- a/examples/tracetest-grafana-tempo-pokeshop/tests/curl_post.sh +++ /dev/null @@ -1 +0,0 @@ -curl -d '{"id":6}' -H "Content-Type: application/json" -X POST http://localhost:8081/pokemon/import \ No newline at end of file diff --git a/examples/tracetest-grafana-tempo-pokeshop/tests/post-mortem.yaml b/examples/tracetest-grafana-tempo-pokeshop/tests/post-mortem.yaml deleted file mode 100644 index 94c884cb46..0000000000 --- a/examples/tracetest-grafana-tempo-pokeshop/tests/post-mortem.yaml +++ /dev/null @@ -1,13 +0,0 @@ -type: Test -spec: - id: rA8wtOjVR - name: post mortem pokemon import - trigger: - type: traceid - traceid: - id: ${var:traceId} - specs: - - selector: span[tracetest.span.type="general" name="import pokemon"] - name: Validate there are no exceptions when importing pokemon. - assertions: - - attr:span.events not-contains "exception" diff --git a/examples/tracetest-grafana-tempo-pokeshop/tests/test.yaml b/examples/tracetest-grafana-tempo-pokeshop/tests/test.yaml deleted file mode 100644 index 45424e2412..0000000000 --- a/examples/tracetest-grafana-tempo-pokeshop/tests/test.yaml +++ /dev/null @@ -1,27 +0,0 @@ -type: Test -spec: - id: MnZ_kD7Ig - name: Pokeshop - Import - description: Import a Pokemon - trigger: - type: http - httpRequest: - method: POST - url: http://demo-api:8081/pokemon/import - body: "{\"id\":837483}" - headers: - - key: Content-Type - value: application/json - specs: - - selector: span[tracetest.span.type="http" name="GET" http.method="GET"] - name: Validate that the external API does not contain an exception. - assertions: - - attr:span.events not-contains "exception" - - selector: span[tracetest.span.type="http"] - name: "All HTTP Spans: Status code is 200" - assertions: - - attr:http.status_code = 200 - - selector: span[tracetest.span.type="database"] - name: "All Database Spans: Processing time is less than 100ms" - assertions: - - attr:tracetest.span.duration < 100ms diff --git a/examples/tracetest-grafana-tempo-pokeshop/tracetest.config.yaml b/examples/tracetest-grafana-tempo-pokeshop/tracetest.config.yaml deleted file mode 100644 index f3116d864f..0000000000 --- a/examples/tracetest-grafana-tempo-pokeshop/tracetest.config.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -postgres: - host: postgres - user: postgres - password: postgres - port: 5432 - dbname: postgres - params: sslmode=disable - -telemetry: - exporters: - collector: - serviceName: tracetest - sampling: 100 - exporter: - type: collector - collector: - endpoint: otel-collector:4317 - -server: - telemetry: - exporter: collector - applicationExporter: collector diff --git a/examples/tracetest-grafana-tempo-pokeshop/tracetest.provision.yaml b/examples/tracetest-grafana-tempo-pokeshop/tracetest.provision.yaml deleted file mode 100644 index d25c7f09bf..0000000000 --- a/examples/tracetest-grafana-tempo-pokeshop/tracetest.provision.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -type: DataStore -spec: - name: Tempo - type: tempo - tempo: - type: grpc - grpc: - endpoint: tempo:9095 - tls: - insecure: true - ---- -type: Demo -spec: - type: pokeshop - enabled: true - name: pokeshop - opentelemetryStore: {} - pokeshop: - httpEndpoint: http://demo-api:8081 - grpcEndpoint: demo-rpc:8082