- 2 Minutes to read
- Print
- DarkLight
- PDF
Python APM with AWS Fargate
- 2 Minutes to read
- Print
- DarkLight
- PDF
This document details how to install the Python APM Profiler in your Python application running on AWS Fargate.
Stackify supports AWS Fargate by adding our Retrace Container to your AWS Fargate tasks.
The configuration is in two parts; adjusting your Dockerfile config to include the appropriate Stackify profiler and then adjusting task/container definition configuration in AWS Fargate. The configuration details are provided below in JSON samples.
Python Application 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-apm
You may install your stackify-python-apm by adding it to your project's
requirements.txt
file.Add
stackifyapm.contrib.django
toINSTALLED_APPS
in yoursettings.py
:INSTALLED_APPS = ( # ... 'stackifyapm.contrib.django', )
Add our tracing middleware to
MIDDLEWARE
in 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-apm
You may install your stackify-python-apm by adding it to your project's
requirements.txt
file.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-apm
You may install your stackify-python-apm by adding it to your project's
requirements.txt
file.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')
Task Configuration
- Add the stackify volume to the task definition:
{
"volumes": [
{
"name": "stackify"
}
]
}
- Add the stackify-retrace container to the task definition:
{
"containerDefinitions": [
{
"name": "stackify-retrace",
"image": "stackify/retrace:latest",
"memoryReservation": "512",
"essential": true,
"environment": [
{
"name": "STACKIFY_KEY",
"value": "[YOUR_ACTIVATION_KEY]"
},
{
"name": "STACKIFY_ENV",
"value": "[YOUR_ENVIRONMENT_NAME]"
},
{
"name": "STACKIFY_DEVICE_ALIAS",
"value": "AWS Fargate"
}
],
"mountPoints": [
{
"sourceVolume": "stackify",
"containerPath": "/var/stackify"
}
]
}
]
}
Note: Replace [YOUR_ACTIVATION_KEY]
and [YOUR_ENVIRONMENT_NAME]
.
Use Image stackify/retrace-arm64
if running on an ARM processor.
- Add stackify mount points to your application container definition:
{
"containerDefinitions": [
{
"mountPoints": [
{
"sourceVolume": "stackify",
"containerPath": "/usr/local/stackify"
}
]
}
]
}
Verify
Start up your Python application task and make requests. You can then verify results in the Retrace dashboard.