OpenTelemetry Python instrumentation gives the possibility to capture telemetry data from the python written code applications. The best way to start it is to incorporate OpenTelemetry-Python. See a list of the supported libraries under OpenTelemetry Instrumentations.
How to instrument your app?
The best way to instrument Python applications is to use OpenTelemetry-Python automatic instrumentation. This approach is simple, easy, and does not require many code changes. Only a few Python packages have to be installed to successfully instrument the code of the application. Instruction below applies to OpenTelemetry-Python instrumentation in version 1.3.0/0.22b0 with OpenTelemetry Protocol Exporter.
Mandatory packages installation
Installation of the package listed below is required to start the instrumentation.
$ pip install opentelemetry-distro==0.22b0
$ pip install opentelemetry-instrumentation==0.22b0
Application specific packages installation
The next step is related to the installation of the instrumented packages used in the application. This step can be done by one simple command in the root directory of your Python application. Execution of the command below will install corresponding instrumented packages used by the application. This solution is recommended.
$ opentelemetry-bootstrap --action=install
It is possible to install instrumented packages manually but it will require from the use to find libraries used in the code and then installation of their instrumented counterparts (e.g. Flask -> opentelemetry-instrumentation-flask).
After successful installation of the instrumented packages it is important to install and configure a span exporter. The most commonly used exporters are OTLP, Jaeger, and Zipkin. We recommend to use OpenTelemetry-Protocol Exporter.
# Exporter installation
$ pip install opentelemetry-exporter-otlp==1.3.0
A few things have to be configured:
- SERVICE_NAME - insert there application service name
- ENDPOINT_ADDRESS - OTLP gRPC collector endpoint address (default Sumo Logic endpoint address: "http://collection-sumologic-otelcol.sumologic:4317")
All of them can be configure by environment variables specific for the exporter. For OTLP gRPC Exporter these are:
When everything is configured it is very simple to run an instrumented application.
$ opentelemetry-instrument python3 SCRIPT_NAME.py