Skip to content

trutzio/otel-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Quick start

Checkout https://github.com/trutzio/devops-infrastructure and execute:

docker compose up -d

Install 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 8081

In the above example, you can also use console instead of otlp as exporter.

OTEL in Python

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 install

install 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 8081

starts a Python program (here flask server) with instrumentation turned on. Please note that Flask must be installed beforehand using this command:

pip install flask

Start

source ./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

About

No description or website provided.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages