Come join our live training webinar every other Wednesday at 11am PST and hear LogicMonitor experts explain best practices and answer common questions. We understand these are uncertain times, and we are here to help!
There are two ways to approach OpenTelemetry-facilitated instrumentation for a Python application:
In the end, you may need a combination of both manual and auto-instrumentation.
LogicMonitor provides a configuration wizard for automatic Instrumentation of Python applications.
1. At the top right of the Traces page, select Onboarding.
2. Select Python, and confirm automatic instrumentation.
The wizard will prompt you to specify the Python libraries that your application uses, such as requests of grpc, and then the UI will provide a pip install command for each library.
3. (Required) Install three client libraries generic to OpenTelemetry instrumentation and one instrumentation client library for each application library you specify.
4. Once you’ve installed the necessary libraries for instrumentation, you will see a script tracer.py on the next screen.
This script show how the tracer can be initialized for an app called “server”. You can use this script directly, customizing it with the values specific to your Python application.
5. Next, the wizard will prompt you for the following information:
Note: LogicMonitor requires the following custom tags to map traces to existing monitored resources: ip, resource.type (which should be set to kubernetes-pod, cloud, or host), and host.name (which should be the pod name for Kubernetes). We recommend using these custom tags when possible to ensure that traces can be shown in the context of logs, metrics, and alerts.
6. Based on what you entered in the three fields, an opentelemetry-instrument command for instrumenting the application in tracer.py will be generated. Copy and run this command on the server where your application is running to start your application.
(Recommended) When instrumenting your application in Kubernetes, extend your Docker image to incorporate the instrumentation steps. For example, you may add the following to your dockerfile:
#add OpenTelemetry instrumentation packages and set env vars (alternatively can be done in Kube YAML)
RUN pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-grpc opentelemetry-instrumentation-grpc
Change the entrypoint to start your application with the instrumentation:
ENTRYPOINT ["opentelemetry-instrument", "python", "tracer.py"]
You may need to manually instrument some or all of your Python applications if (1) you are using applications that aren’t supported for the OpenTelemetry auto-instrumentation; or (2) you want to customize how traces are generated by auto-instrumentation (e.g. how operations are named).
The best source of instruction for manually instrumenting your Python application is the official OpenTelemetry documentation. This documentation will guide you through instantiating the OpenTelemetry SDK and a tracer, creating traces, and enriching them.
In This Article