Checkout https://github.com/trutzio/devops-infrastructure and execute:
docker compose up -dInstall a virtual environment for Python, install all dependencies and run the Flask server with OTEL instrumentation:
python3 -m venv venv
source ./venv/bin/activate
pip install flask
pip install opentelemetry-distro
pip install opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
opentelemetry-instrument \
--traces_exporter otlp \
--metrics_exporter otlp \
--logs_exporter otlp \
--service_name dice-server \
flask run -p 8081In the above example, you can also use console instead of otlp as exporter.
Tutorial for getting started with OTEL in Python:
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-exporter-{exporter}
pip install opentelemetry-instrumentation-{instrumentation}where instrumentation exists for these frameworks and these exporters can be used to store logs, metrics and traces.
pip install opentelemetry-distro
opentelemetry-bootstrap -a installinstall the instrumentation for the frameworks used in the project.
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
opentelemetry-instrument \
--traces_exporter otlp \
--metrics_exporter otlp \
--logs_exporter otlp \
--service_name dice-server \
flask run -p 8081starts a Python program (here flask server) with instrumentation turned on. Please note that Flask must be installed beforehand using this command:
pip install flasksource ./venv/bin/activate
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
opentelemetry-instrument --traces_exporter otlp --metrics_exporter otlp --logs_exporter otlp --service_name dice-server flask run -p 8081