Monitoring Python - The Instana Python Package
TABLE OF CONTENTS
The Instana Python package: Python Distributed Tracing & Metrics Sensor.
What is Instana AutoTrace?
Instana AutoTrace™ is a next-generation distributed tracing and service discovery technology powering Instana’s fully automatic, no-effort, and instant observability experience.
The Instana Host agent automatically finds and instruments your running Python applications running on Linux x86 with no required user steps or restarts.
For more information, see the blog post on Python AutoTrace or the AutoTrace configuration documentation on how to modify AutoTrace behavior.
Usage
The Instana Python package is a zero-configuration tool that automatically collects key metrics and distributed traces from your Python processes.
Installing
Automatic installation
Instana remotely instruments your Python applications automatically by Instana AutoTrace™. However, if you prefer to install the package manually, see Manual Installation below.
Note: Instana AutoTrace™ support for Python requires the instrumenting machine to be able to reach pip
.
As such, it won't work in air-gapped environments or similar environments that restrict egress.
In such cases, use the Manual Installation method.
Manual Installation
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
From here there are two options available to choose from based on your organization's needs described below.
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:
export AUTOWRAPT_BOOTSTRAP=instana
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 becausegevent
must be activated andmonkey.patch_all()
called first.
Activating With Code Changes
Alternatively, to manually import the instana
package to inside your Python application code, add the following to your application code:
import instana
For additional information about Django, Flask, End-user Monitoring (EUM), and more, see the Frameworks section.
Configuration
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.
Kubernetes & OpenShift
For information on how to ensure that your instrumented applications can contact the Instana Host Agent, see the documentation.
Cloud Foundry
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
instana
Python package to therequirements.txt
file - Add an
AUTOWRAPT_BOOTSTRAP
environment variable with the valueinstana
to the application manifest as shown below cf push
the Cloud Foundry application
---
applications:
- name: test-python-flask
buildpacks:
- python_buildpack
env:
AUTOWRAPT_BOOTSTRAP: instana
Custom Tracing
The Instana Python package supports custom tracing via OpenTracing APIs. See the OpenTracing page for more information.
Troubleshooting
Please see our dedicated Troubleshooting documentation.
Releases
For the Instana Python package release history, including changes made to the package, see the Github Releases page.