This repository contains the sample application which is used in the Grafana webinar How to get started with OpenTelemetry and Grafana. It consists of a minimal Python Flask web application and is based on the OpenTelemetry Getting Started guide for Python.
You can find instructions of how to run the sample application application locally or via Docker.
-
Set up a local project directory:
mkdir otel-getting-started cd otel-getting-started python3 -m venv venv source ./venv/bin/activate
See Creating Virtual Environments in the official Python documentation for more information.
-
Install Flask:
pip install flask
-
Copy the file
app.py
from this repository into your project directory. -
From your project directory, run the application:
flask run -p 8080
With the application running, you should be able to see random dice rolls at http://localhost:8080/rolldice.
-
Install the OpenTelemetry distro and instrumentation:
pip install opentelemetry-distro opentelemetry-bootstrap -a install
-
Run the instrumented application with telemetry exported to the console:
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true opentelemetry-instrument \ --traces_exporter console \ --metrics_exporter console \ --logs_exporter console \ --service_name dice-server \ flask run -p 8080
With the application running, you should be able to see random dice rolls at http://localhost:8080/rolldice. On the console, you will see telemetry (metrics, logs, and traces) that is created by your application.
-
Install the OTLP exporter:
pip install opentelemetry-exporter-otlp-proto-http
-
Obtain and set up environment variables to send telemetry data to Grafana Cloud via OTLP.
Follow the steps below to obtain the environment variable values necessary to send data to your Grafana Cloud stack:
-
Navigate to the Grafana Cloud Portal page.
-
Click Configure in the OpenTelemetry section.
-
Click Generate to generate a new API token.
-
Copy the pre-set environment variables to the console:
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-us-east-0.grafana.net/otlp" export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20..."
-
-
Run the instrumented application with telemetry exported to Grafana Cloud:
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true export OTEL_LOGS_EXPORTER=otlp opentelemetry-instrument \ --service_name dice-server \ flask run -p 8080
After doing some dice rolls via http://localhost:8080/rolldice, metrics, logs, and traces should be visible in Grafana Cloud.
-
Clone this repository, and from its root directory build the included
Dockerfile
:docker build --tag grafana-otel-webinar .
-
Run the Docker image with OTLP environment variables set:
docker run \ -e OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \ -e OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-us-east-0.grafana.net/otlp" -e OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20..." \ -p 8080:8080 \ grafana-otel-webinar
Follow the steps below to obtain the environment variable values necessary to send data to your Grafana Cloud stack:
- Navigate to the Grafana Cloud Portal page.
- Click Configure in the OpenTelemetry section.
- Click Generate to generate a new API token.
- Use the pre-set environment variables in the command above.
After doing some dice rolls via http://localhost:8080/rolldice, metrics, logs, and traces should be visible in Grafana Cloud.