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.7.1/0.26b1 with OpenTelemetry Protocol HTTP Exporter.
Mandatory packages installation
Installation of the package listed below is required to start the instrumentation. Run the following pip commands:
$ pip install opentelemetry-distro==0.26b1
$ pip install opentelemetry-instrumentation==0.26b1
If you use a pipfile, add these dependencies instead of using the pip commands. For example:
opentelemetry-distro = "0.26b1"
opentelemetry-instrumentation = "0.26b1"
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 HTTP Exporter.
# Exporter installation
$ pip install opentelemetry-exporter-otlp-proto-http==1.7.1
A few things have to be configured:
- SERVICE_NAME - insert the application service name
- APPLICATION_NAME - insert the application name
- ENDPOINT_ADDRESS - OTLP HTTP collector endpoint address (default Sumo Logic endpoint address for Kubernetes deployment: "http://collection-sumologic-otelcol.sumologic:55681/v1/traces") recommended for production usage or Sumo Logic HTTP Traces URL.
All of them can be configured by environment variables specific for the exporter. For OTLP HTTP Exporter these are:
When everything is configured it is very simple to run an instrumented application.
$ opentelemetry-instrument python3 SCRIPT_NAME.py