Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(examples/docs): Updating jaeger x node.js example to be the initial template #3958

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ This is a simple quick start on how to configure a Node.js app to use OpenTeleme
**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.

Expand All @@ -64,10 +62,9 @@ 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 Jaeger Tracing Backend. Ensure the environment you're using to run this example is configured to use the Jaeger Tracing Backend by clicking on Settings, Tracing Backend, Jaeger, 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/`.
3. Fill out the [token](https://app.tracetest.io/retrieve-token) details by editing your `.env` file.
4. Run `docker compose run tracetest-run`.
5. Follow the links in the output to view the test results.

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

Expand All @@ -84,12 +81,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="<YOUR_TRACETEST_API_KEY>"
# Get the required information here: https://app.tracetest.io/retrieve-token

TRACETEST_TOKEN="<YOUR_TRACETEST_TOKEN>"
TRACETEST_ENVIRONMENT_ID="<YOUR_ENV_ID>"
```

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Choosing [the `tracing.otel.grpc.js` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-jaeger-nodejs/tracing.otel.grpc.js) will send traces to OpenTelemetry Collector's `GRPC` endpoint.
Choosing the [`tracing.otel.grpc.js` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-jaeger-nodejs/tracing.otel.grpc.js) will send traces to OpenTelemetry Collector's `GRPC` endpoint.

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

Expand All @@ -99,55 +99,23 @@ Enabling the tracer is done by preloading the trace file. As seen in the `packag
},
```

## Configuring Jaeger

Configure Jaeger as a Tracing Backend:

```yaml title=tracetest-tracing-backend.yaml
---
type: DataStore
spec:
name: Jaeger
type: jaeger
default: true
jaeger:
endpoint: jaeger:16685
tls:
insecure: true
```

```bash
tracetest config -t <YOUR_API_TOKEN>
tracetest apply datastore -f ./tracetest-tracing-backend.yaml
```

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

The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-jaeger-nodejs/docker-compose.yaml) and [`Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-jaeger-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-jaeger-nodejs/docker-compose.agent.yaml) is for the Tracetest Agent, Jaeger, and OpenTelemetry Collector.
The [`docker-compose.yaml` file](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-jaeger-nodejs/docker-compose.yaml) and [`Dockerfile`](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-jaeger-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, Jaeger, and OpenTelemetry Collector.

[The `collector.config.yaml` configures the OpenTelemetry Collector](https://github.com/kubeshop/tracetest/blob/main/examples/quick-start-jaeger-nodejs/collector.config.yaml). It receives traces via either `grpc` or `http`. Then, exports them to Jaeger 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 Jaeger.

## Run Tracetest Tests

1. Open [Tracetest](https://app.tracetest.io/)
2. [Configure Jaeger as a tracing backend](/configuration/connecting-to-data-stores/jaeger) 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 <YOUR_API_TOKEN>
tracetest run test -f ./test-api.yaml
```
This will:
1. Start the Node.js app the OpenTelemetry Collector and send the traces to Jaeger.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Start the Node.js app the OpenTelemetry Collector and send the traces to Jaeger.
1. Start the Node.js app, the OpenTelemetry Collector, and send the traces to Jaeger.

2. Start the Tracetest Agent.
3. Configure the tracing backend and create the Tests in your environment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. Configure the tracing backend and create the Tests in your environment.
3. Configure the tracing backend and create tests in your environment.

4. Run the tests.

```mdx-code-block
</TabItem>
Expand Down
6 changes: 4 additions & 2 deletions examples/quick-start-jaeger-nodejs/.env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
TRACETEST_API_KEY="<YOUR_TRACETEST_API_KEY>"
TRACETEST_API_TOKEN="<YOUR_TRACETEST_TOKEN>"
# Get the required information here: https://app.tracetest.io/retrieve-token

TRACETEST_TOKEN="<YOUR_TRACETEST_TOKEN>"
TRACETEST_ENVIRONMENT_ID="<YOUR_ENV_ID>"
11 changes: 11 additions & 0 deletions examples/quick-start-jaeger-nodejs/Dockerfile.tracetest
Original file line number Diff line number Diff line change
@@ -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"]
28 changes: 0 additions & 28 deletions examples/quick-start-jaeger-nodejs/docker-compose.agent.yaml

This file was deleted.

72 changes: 72 additions & 0 deletions examples/quick-start-jaeger-nodejs/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,75 @@ services:
build: .
ports:
- "8080:8080"
depends_on:
jaeger:
condition: service_healthy
otel-collector:
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
depends_on:
jaeger:
condition: service_healthy

jaeger:
image: jaegertracing/all-in-one:latest
ports:
- 14250:14250
- 16685:16685
- 16686:16686
healthcheck:
test: ["CMD", "wget", "--spider", "localhost:16686"]
interval: 1s
timeout: 3s
retries: 60

# 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
17 changes: 17 additions & 0 deletions examples/quick-start-jaeger-nodejs/resources/apply.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions examples/quick-start-jaeger-nodejs/resources/datastore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: DataStore
spec:
id: current
name: jaeger
type: jaeger
default: true
jaeger:
endpoint: jaeger:16685
headers:
"": ""
tls:
insecure: true
16 changes: 16 additions & 0 deletions examples/quick-start-jaeger-nodejs/resources/run.sh
Original file line number Diff line number Diff line change
@@ -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
62 changes: 0 additions & 62 deletions examples/quick-start-jaeger-nodejs/tracetest/docker-compose.yaml

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions examples/quick-start-jaeger-nodejs/tracetest/tracetest.config.yaml

This file was deleted.

Loading