Python APM
To get the most out of Middleware OpsAI for your Python application, Consider using Middleware Python SDK (version 2.4.0
or newer).
π Key Features
- See the exact code that caused your error: Whenever an exception happens, Middleware SDK automatically captures and sends the code of the function where the error occurred. This helps you quickly understand what went wrongβno more guessing from just a stack trace!
- Works with all OpenTelemetry-supported Python frameworks
π οΈ APM Setup
Install the Middleware package:
pip install middleware-io
Run your app with Middleware CLI:
The install adds a
middleware-run
CLI to your virtual environment. Use it to start your app:- Instead of:
flask run
- Use:
middleware-run flask run
- Instead of:
β‘ Exception Code Capturing
Middleware Python SDK automatically captures relevant code for real-time exceptions, without any additional configurations
βοΈ VCS Metadata Configuration (Recommended)
To help Middleware suggest fixes and even open GitHub pull requests for you, it's important to send version control (VCS) information along with your error data.
If your app has a
.git
directory:- The Middleware SDK will automatically detect your repository URL and commit SHA. You don't need to do anything extra!
If your app is running in a container or doesn't have a
.git
directory:Set these environment variables before starting your app:
MW_VCS_COMMIT_SHA=$(git rev-parse HEAD) MW_VCS_REPOSITORY_URL=$(git config --get remote.origin.url)
This lets Middleware know exactly which version of your code is running, so it can suggest the right fix and even create a solution PR for you.
π Resources
- OpenTelemetry Python Instrumentation β List of supported frameworks
- Middleware Python APM on PyPI β Package and release info
- Official Middleware Python APM Docs β Full documentation and advanced usage