Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Latest commit

 

History

History

lab-2-collection

Lab 2. Collection

Contents

Preface

Lab 2 introduces the fundamentals of collecting and transporting data with OpenTelemetry. You will see how to collect and ship data to an external destination.

2.1 - OpenTelemetry Collector

First let's see how to collect traces, metrics, and logs with the OpenTelemetry Collector. We won't ship the data to an external destination yet. Instead the data will appear in the terminal under the container logs for the OpenTelemetry Collector.

Step 1. Review the OpenTelemetry Collector configuration: otel-collector/otel-collector-config.yaml

Step 2. Review docker-compose.yaml

Questions to explore:

  • How are the configurations managed with environment variables?

Step 3. Run the app: docker-compose --project-directory otel-collector up --build

Step 4. Open the app in a web browser and visit these endpoints to generate traces, metrics, and logs:

Step 5. Verify the presence of traces, metrics, and logs in the output of the otel-collector_1 container logs your terminal.

Step 6. Stop the app using Ctrl+C or ⌘-C.

2.2 - OpenTelemetry Collector to Grafana Stack

Note - This lab section requires the otel-collector-contrib distribution of the OpenTelemetry Collector.

Now let's see how the OpenTelemetry Collector ships data to an external destination. This example ships data to the Grafana Stack that includes Tempo for traces, Mimir for metrics, and Loki for logs.

Step 1. Compare the code of the app with no instrumentation to the code of the app with traces instrumentation: git diff --no-index otel-collector otel-collector-grafana-stack

Questions to explore:

Step 2. Run the app: docker-compose --project-directory otel-collector-grafana-stack --env-file ../env up --build

Step 3. Open the app in a web browser and visit these endpoints to generate traces, metrics, and logs:

Step 4. Verify the presence of traces, metrics, and logs in Grafana Cloud. Open Grafana, click Ctrl+C or ⌘-C, type explore and then press Enter.

  • Traces - Select "grafanacloud-orgname-traces" as the data source, "Last 15 minutes" as the time range, and click "Run query."
  • Metrics - Select "grafanacloud-orgname-prom" as the data source, "Last 15 minutes" as the time range, and run this query: {job="java-springboot"}
  • Logs - Select "grafanacloud-orgname-logs" as the data source, "Last 15 minutes" as the time range, and run this query: {job="java-springboot"} | json

Step 5. Stop the app using Ctrl+C or ⌘-C.

2.3 - Grafana Agent to Grafana Stack

Note - This lab section requires the otel-collector-contrib distribution of the OpenTelemetry Collector.

Now let's compare the OpenTelemetry Collector to the Grafana Agent.

Step 1. Compare the code of the app with no instrumentation to the code of the app with traces instrumentation: git diff --no-index otel-collector-grafana-stack grafana-agent-grafana-stack

Questions to explore:

Step 2. Review grafana-agent-config.river

Questions to explore:

  • How are traces, metrics, and logs collected, processed, and shipped?

Step 3. Run the app: docker-compose --project-directory grafana-agent-grafana-stack --env-file ../env up --build

Step 4. Open the app in a web browser and visit these endpoints to generate traces, metrics, and logs:

Step 5. Verify the presence of traces, metrics, and logs in Grafana Cloud. Open Grafana, click Ctrl+C or ⌘-C, type explore and then press Enter.

  • Traces - Select "grafanacloud-orgname-traces" as the data source, "Last 15 minutes" as the time range, and click "Run query."
  • Metrics - Select "grafanacloud-orgname-prom" as the data source, "Last 15 minutes" as the time range, and run this query: {job="java-springboot"}
  • Logs - Select "grafanacloud-orgname-logs" as the data source, "Last 15 minutes" as the time range, and run this query: {job="java-springboot"} | json

Step 6. Stop the app using Ctrl+C or ⌘-C.

2.4 - Grafana Agent to OTLP Gateway

The Grafana Cloud OTLP Gateway simplifies the configuration by requiring only one endpoint for traces, metrics, and logs. Let's see how this compares to shipping data to Tempo, Mimir, and Loki separately.

Step 1. Compare the code of the app with no instrumentation to the code of the app with traces instrumentation: git diff --no-index grafana-agent-grafana-stack grafana-agent-otlp-gateway

Questions to explore:

Step 2. Run the app: docker-compose --project-directory grafana-agent-otlp-gateway --env-file ../env up --build

Step 3. Open the app in a web browser and visit these endpoints to generate traces, metrics, and logs:

Step 4. Verify the presence of traces, metrics, and logs in Grafana Cloud. Open Grafana, click Ctrl+C or ⌘-C, type explore and then press Enter.

  • Traces - Select "grafanacloud-orgname-traces" as the data source, "Last 15 minutes" as the time range, and click "Run query."
  • Metrics - Select "grafanacloud-orgname-prom" as the data source, "Last 15 minutes" as the time range, and run this query: {job="java-springboot"}
  • Logs - Select "grafanacloud-orgname-logs" as the data source, "Last 15 minutes" as the time range, and run this query: {job="java-springboot"} | json

Step 5. Stop the app using Ctrl+C or ⌘-C.