Python APM - Setup & Installation Docs | Middleware
Traces | Metrics | App Logs | Custom Logs | Profiling |
---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ |
This guide walks you through setting up Application Performance Monitoring (APM) on a Python application. These instructions can also be found on the Installation page in your Middleware Account. View example code here.
Infra Agent
Infrastructure Agent (Infra Agent). To install the Infra Agent, see our Installation Guide.
Python Version
Python 3 version 3.8
or above. Check your Python version with the following command:
Pip Version
pip version 23.1.2
or above. Check your pip version with the following command:
Python
APM PackageRun the following command in your terminal:
Check if the middleware-apm
has been installed with the following command:
Add the following lines to the beginning of your application:
Applications running in a container require an additional environment variable. If your application is not running in a container, move to Step 4.
Add the following environment variable to your application:
DOCKER_BRIDGE_GATEWAY_ADDRESS
is the IP address of the gateway between the Docker host and bridge network. This is 172.17.0.1
by default.
Learn more about Docker bridge networking here Add the following command to your Dockerfile
after the pip install
command:
Identify the namespace where the Infra Agent is running:
Then add the following environment variable to your application deployment YAML file:
middleware.ini
FileCreate a middleware.ini
file based on the features you want to observe and place it at the root of your app directory. Specify the location of the middleware.ini
file with the MIDDLEWARE_CONFIG_FILE
environment variable.
service_name
and access_token
are required for the tracker to send data to Middleware.To ingest custom logs, utilize the following functions based on desired log severity levels:
Use tracker.record_error()
method to record a stack trace when an error occurs:
Add the following to your main()
function in manage.py
:
Initialize your Django project with the following command:
After initializing your application, run the following command to start your project:
middleware.ini
file is not in your root directory, add MIDDLEWARE_CONFIG_FILE=./path/to/middleware.ini
to the below command After deploying your application, run the following command to start your project:
Continuous profiling captures real-time performance insights from your application to enable rapid identification of resource allocation, bottlenecks, and more. Navigate to the Continuous Profiling section to learn more about using Continuous Profiling with the Python APM.