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 0.16b1 with OpenTelemetry Protocol Exporter.
1. Mandatory packages installation
Installation of the package listed below is required to start the instrumentation.
$ pip install opentelemetry-instrumentation==0.16b1
2. 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).
3. Exporters configuration
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==0.16b1
A few things have to be configured:
- SERVICE_NAME - insert there application service name
- ENDPOINT_ADDRESS - OTLP collector endpoint address (default Sumo Logic endpoint address: "collection-sumologic-otelcol.sumologic:55680")
- INSECURE_FLAG - if security certificates are not used for spans transfer between exporter and collector then the flag has to be set as True
All of them can be configure by environment variables specific for the exporter. For OTLP Exporter these are:
4. Application execution
When everything is configured it is very simple to run an instrumented application.
$ opentelemetry-instrument python3 SCRIPT_NAME.py