Troubleshooting issues with the Python APM agent
Telemetry-related troubleshooting and debugging
To help troubleshoot and debug issues with your application's telemetry, you can enable specific settings in the mw_tracker
function or use environment variables. These settings allow you to export telemetry data to the console, save them to log files, or debug basic information logs.
Toggling Basic Information Logs
Toggle info logs on or off to focus on debugging specific issues:
#in the `mw_tracker` function from middleware log_level = "DEBUG" #as an env variable MW_LOG_LEVEL = "DEBUG"
Exporting Telemetry Data to the Console
When debugging in a dev environment, it helps to view the telemetry data directly in the console. Setting the console_exporter
to true
will print telemetry data like traces, metrics, and logs in your terminal or console.
#in the `mw_tracker` function from middleware console_exporter = true #as an env variable MW_CONSOLE_EXPORTER = true
Saving Telemetry Data to Log Files
Save telemetry data to log files by enabling the debug_log_file
setting. The logs will be written to corresponding files such as mw-traces.log
, mw-metrics.log
, and mw-logs.log
.
#in the `mw_tracker` function from middleware debug_log_file = true #as an env variable MW_DEBUG_LOG_FILE = true
Python package installation failure
The Python package installs require gcc
and gcc-c++
, which you may need to install if you’re running a slim version of Linux, such as CentOS.
yum -y install python3-devel yum -y install gcc-c++
apt install -y python3-dev apt install -y build-essential
apk add python3-dev apk add build-base
Missing Parent Span
Try tunning batch export interval using OTel Environment variable
OTEL_BSP_SCHEDULE_DELAY = 100
Check the OTel guide on the Batch Span Processor for more details.
Data isn't appearing in Middleware dashboard
If you don't see data appearing in your Middleware.io dashboard, here are common troubleshooting steps.
Check Environment Variables:
- Verify that
MW_TRACKER
isTrue
if you used the function-based instrumentation method. - Confirm
MW_API_KEY
andMW_TARGET
are exactly correct (no typos, extra spaces). - Ensure variables are properly exported in your shell, Dockerfile, or Kubernetes manifest.
- Verify that
Verify
middleware-run
Usage:- Crucially, confirm your application is started using the
middleware-run
wrapper (e.g.,middleware-run python your_app.py
). Starting directly (python your_app.py
) will prevent proper agent initialization.
- Crucially, confirm your application is started using the
Inspect
middleware-bootstrap
Results:- Run
pip list | grep opentelemetry
to check ifopentelemetry-instrumentation-
packages (likeopentelemetry-instrumentation-flask
) are installed for your dependencies. - If any are missing, re-run
middleware-bootstrap -a install
and ensure it has access to yourrequirements.txt
or installed packages.
- Run
Increase Agent Logging Level:
- Set
MW_LOG_LEVEL=DEBUG
in your environment variables before running your application. - Examine your application's console output for
opentelemetry
ormiddleware-io
messages, especiallyERROR
orWARNING
messages, or lines indicating "Middleware Agent initialized successfully."
- Set
Network Connectivity:
- From your application's host/container, try to
ping
orcurl
yourMW_TARGET
URL to confirm network reachability. - Check firewall rules, security groups, or proxy configurations that might be blocking outbound traffic on port 443.
- From your application's host/container, try to
Application Activity:
- Ensure your application is actively receiving traffic or performing operations that generate telemetry data. If your web app isn't getting requests, there won't be any traces or request metrics. Manually make some requests to test.
Resource Limits (Kubernetes/Containers):
- In containerized environments, confirm your pods have sufficient CPU and memory resources. A resource-starved agent may fail to process and export data.
Time Synchronization:
- Ensure the system clock on your application host is synchronized. Significant clock drift can lead to issues with timestamping and data correlation in observability platforms.
Need further assistance even after following these steps? Contact our support team at [email protected].