Traces | Metrics | App Logs | Custom Logs | Profiling |
---|---|---|---|---|
Prerequisites
- To monitor APM data on dashboard, Middleware Host agent needs to be installed.
- You can refer this demo project to refer use cases of APM.
Getting Started
Step 1: Install MW’s APM Package
Run the following command in your terminal:Step 2: Auto-install Required Packages
Themiddleware-bootstrap -a install
command reads through the list of packages installed in your active site-packages folder, and installs the corresponding instrumentation libraries for these packages, if applicable.
Step 3: Import the Tracker
Add the following lines at the very start of your project:You can find your {YOUR-ACCESS_TOKEN} on the Installation screen for Python.
Enable MW’s APM functionalities
1. Enable Distributed Tracing
Distributed-tracing is a default functionality of MW’s APM. This will be auto-enabled when you execute the command mentioned in Run Your Application section.2. Enable Metrics
You can enable metrics by writing the following line just after the tracker initialization.3. Enable Logs
Similar to metrics, you can enable logs by writing the following line.4. Enable Profiling
For the Profiling feature, you need to write the following line.Your Code will look like this
After adding all the above steps, your code will look like this:For additional information and in-depth guidance, you can clone the sample project from the GitHub repository to explore further.
Run Your Application
To run your application, you need to execute the following command:You need to replace {APM-PROJECT-NAME} and {APM-SERVICE-NAME} with your project name and service name respectively.
For APM inside Kubernetes
If you are using APM in a Kubernetes cluster make sure to follow these two steps:Step 1: Find your Middleware Service namespace
For older setup, your “mw-service” can be insidemw-agent-ns-{FIRST-5-LETTERS-OF-API-KEY}
namespace
For newer setup, we simplified the namespace name to mw-agent-ns
Step 2: Set this ENV variable in your application deployment YAML
Please replace “NAMESPACE” with the correct value that you found from Step 1.
Troubleshoot:
If you receive a warning similar to the following:WARNING: The scripts middleware-bootstrap and middleware-instrument are installed in ‘/home/…/.local/bin’ which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use —no-warn-script-location
Error Handling :
If you want to record exception in traces then, you can usetracker.record_error(e)
method.