This document details how to install the Python APM Profiler in your Python application running on Kubernetes.
Prerequisite
Follow the Retrace Kubernetes Install Guide.
Python Kubernetes Setup
Django
-
Check that your setup meets our system requirements.
- Python Versions (2.7 - 3.7)
- Django Versions (1.7 - 2)
-
Install the Stackify Python APM agent using pip:
$ pip install stackify-python-apmYou may install your stackify-python-apm by adding it to your project's
requirements.txtfile. -
Add
stackifyapm.contrib.djangotoINSTALLED_APPSin yoursettings.py:INSTALLED_APPS = ( # ... 'stackifyapm.contrib.django', ) -
Add our tracing middleware to
MIDDLEWAREin yoursettings.py:MIDDLEWARE = ( 'stackifyapm.contrib.django.middleware.TracingMiddleware', # ... ) -
Customize Application Name and Environment configuration in your
settings.py:APPLICATION_NAME = 'Python Application' ENVIRONMENT = 'Production'
Flask
-
Check that your setup meets our system requirements.
- Python Versions (2.7 - 3.7)
- Flask Versions (0.7 - 1.0)
-
Install the Stackify Python APM agent using pip:
$ pip install stackify-python-apmYou may install your stackify-python-apm by adding it to your project's
requirements.txtfile. -
Update and insert the apm settings to your application:
from stackifyapm.contrib.flask import StackifyAPM app = Flask(...) StackifyAPM(app) -
Customize Application Name and Environment configuration:
app.config['APPLICATION_NAME'] = 'Python Application' app.config['ENVIRONMENT'] = 'Production' StackifyAPM(app)
Pyramid
-
Check that your setup meets our system requirements.
- Python Versions (2.7 - 3.7)
- Pyramid Versions (1.4 - 1.10)
-
Install the Stackify Python APM agent using pip:
$ pip install stackify-python-apmYou may install your stackify-python-apm by adding it to your project's
requirements.txtfile. -
Update and insert the apm settings to your application:
Include our pyramid tween integration:with Configurator() as config: config.include('stackifyapm.contrib.pyramid')Or explicit tween configuration:
with Configurator({ 'pyramid.tweens': ['stackifyapm.contrib.pyramid.stackifyapm_tween_factory']. }) as config: ... -
Customize Application Name and Environment configuration:
with Configurator({ 'APPLICATION_NAME': 'Python Application', 'ENVIRONMENT': 'Production', }) as config: config.include('stackifyapm.contrib.pyramid')
Pod Configuration
Application containers are required to have the stackify volume mount configured in Retrace Kubernetes Install.
Example Application Pod YAML:
apiVersion: v1
kind: ReplicationController
metadata:
name: pod-name
spec:
replicas: 1
selector:
app: app-name
template:
metadata:
name: template-name
labels:
app: app-name
spec:
containers:
- name: container-name
image: application-image
volumeMounts:
- mountPath: /usr/local/stackify
name: stackify
volumes:
- name: stackify
hostPath:
path: /var/stackify
type: DirectoryOrCreate
Verify
Make application requests, you can then verify results in the Retrace dashboard.