Monitoring Python - The Instana Python Package
The Instana Python package: Python Distributed Tracing & Metrics Sensor.
- Cloud Foundry
- Custom Tracing
- See Also
The Instana Python package is a zero-configuration tool that automatically collects key metrics and distributed traces from your Python processes.
Instana remotely instruments your Python applications automatically by Instana AutoTrace™. However, if you prefer to install the package manually, see Manual Installation as follows.
The Instana AutoTrace WebHook is an implementation of a Kubernetes Mutating WebHook Admission Controller that automatically sets up everything that is required to monitor Python applications with Instana, across an entire Kubernetes cluster.
If you install the Instana AutoTrace WebHook on your Kubernetes clusters, you don't need to perform any manual steps to trace your Python applications that run in those clusters.
If your Python application and the Instana agent are managed by Kubernetes, check the documentation on Kubernetes network access for information about the required configuration in this setup.
Note: The Instana AutoTrace WebHook installs only Python sensor
2.0.0 and newer, and doesn't deliver support for legacy runtimes like Python 2.7. To check which versions of related components are supported,
see Supported Components & Versions. If you need to work with legacy runtimes, see the following Manual Installation section.
Deprecated: Legacy Python AutoTrace
The automatic installation of Python AutoTracing via the host agent mechanism is deprecated.
The preferred approach to monitor Python applications is the AutoTrace WebHook which provides increased stability and a future-proof solution. However, this approach only works on Kubernetes/OpenShift. If your applications are not on Kubernetes, you can do the following steps:
- Instrument the Python application manually.
- Temporarily enable the deprecated Legacy Auto Installation via Host Agent mechanism (Linux x86 only), until the manual instrumentation takes place.
Note: This requires that the instrumenting machine is able to reach
pip. Note: The steps don't work in the air-gapped environments or similar environments that restrict egress.
You can manually install the Instana Python package into the virtualenv, pipenv, or container (hosted on pypi) by running this command:
pip install instana
To update an existing installation, run this command:
pip install -U instana
To install an old version of the Instana Python package for legacy runtimes, run the following command:
pip install -U instana==1.38.0
Then, continue to complete the actions in either of the following two sections based on your organization's needs.
Activating Without Code Changes
Instana offers a way of activating the Instana Python package without modifying a single line of code in your application. This allows you to avoid many of the processes involved with application code changes such as pull-requests, quality assurance, staging and deployment to production.
To activate the Instana package without any code changes, simply set the following environment variable for your Python application:
The Instana Python package will automatically load on application boot and instrument your Python application.
- Note: This method of activation will not work with applications based on
gevent. This is because
geventmust be activated and
Activating With Code Changes
Alternatively, to manually import the
instana package to inside your Python application code, add the following to your application code:
For additional information about Django, Flask, End-user Monitoring (EUM), and more, see the Frameworks section.
For out of the box metrics and distributed tracing, no configuration is required. However, individual components are configurable. For more information, see the Python configuration.
Note: This section assumes that the Instana agent is running on the Diego cells of the Cloud Foundry foundation. Without an agent running on the underpinning Diego cell, monitoring Cloud Foundry applications is not supported.
Additionally, since the Tile version 1.177.0, the
instana_buildpack automates the setup of Python applications on Cloud Foundry. For more information, refer to the Instana Buildpack documentation.
For information on how to setup Instana agents and the related Cloud Foundry or Pivotal Platform functionality, see our Cloud Foundry and Pivotal Platform documentation.
Monitoring Python Cloud Foundry applications requires the following steps:
- Add the
instanaPython package to the
- Add an
AUTOWRAPT_BOOTSTRAPenvironment variable with the value
instanato the application manifest as shown as follows
cf pushthe Cloud Foundry application
applications: - name: test-python-flask buildpacks: - python_buildpack env: AUTOWRAPT_BOOTSTRAP: instana
The Instana Python package supports custom tracing via OpenTracing APIs. See the OpenTracing page for more information.
Please see our dedicated Troubleshooting documentation.
For the Instana Python package release history, including changes made to the package, see the Github Releases page.