{"id":9297,"library":"scout-apm","title":"Scout APM Python Agent","description":"Scout APM is an Application Performance Monitoring (APM) agent for Python that provides detailed performance metrics and transaction traces for web applications (Django, Flask, FastAPI, etc.) and background jobs (Celery, RQ). It helps identify performance bottlenecks, monitor errors, manage logs, and track external services. The current stable version is 3.5.3, with regular updates to support new Python versions and frameworks.","status":"active","version":"3.5.3","language":"en","source_language":"en","source_url":"https://github.com/scoutapp/scout_apm_python","tags":["APM","monitoring","performance","Django","Flask","FastAPI","Celery","observability","metrics","tracing","errors"],"install":[{"cmd":"pip install scout-apm","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Used for global configuration via API.","symbol":"Config","correct":"from scout_apm.api import Config"},{"note":"Used for custom web transaction instrumentation.","symbol":"WebTransaction","correct":"from scout_apm.api import WebTransaction"},{"note":"Used for custom background job instrumentation.","symbol":"BackgroundTransaction","correct":"from scout_apm.api import BackgroundTransaction"},{"note":"Used for custom timing instrumentation within a transaction.","symbol":"instrument","correct":"from scout_apm.api import instrument"},{"note":"Specific Flask integration class.","symbol":"ScoutApm (Flask)","correct":"from scout_apm.flask import ScoutApm"},{"note":"Django integration is typically configured via INSTALLED_APPS, not direct import and instantiation.","wrong":"from scout_apm.django import ScoutApm","symbol":"Django integration","correct":"INSTALLED_APPS = ['scout_apm.django', ...]"}],"quickstart":{"code":"import os\nfrom scout_apm.api import Config, install\n\n# Configure Scout APM (often done via environment variables in production)\n# For local testing, ensure these are set in your environment or replace os.environ.get with actual values.\nConfig.set(key=os.environ.get('SCOUT_KEY', 'YOUR_SCOUT_KEY'),\n           name=os.environ.get('SCOUT_NAME', 'My Python App'),\n           monitor=os.environ.get('SCOUT_MONITOR', 'True').lower() == 'true')\n\n# Install the agent (should be called early in your application startup)\ninstall()\n\n# Example of custom instrumentation (e.g., in a non-web script or job)\nfrom scout_apm.api import WebTransaction, instrument\n\ndef my_complex_function():\n    with instrument('MyCustomOperation'):\n        # Simulate some work\n        sum(range(1000000))\n    return 'Operation complete'\n\nif __name__ == '__main__':\n    # In a web framework, transactions are typically auto-instrumented.\n    # For custom scripts or background jobs:\n    with WebTransaction('MyScriptExecution'):\n        print(my_complex_function())\n","lang":"python","description":"The quickstart demonstrates global configuration via `scout_apm.api.Config.set()` and agent installation via `scout_apm.api.install()`. It also includes an example of custom instrumentation using `WebTransaction` and `instrument` for non-framework specific code. In production, `SCOUT_KEY`, `SCOUT_NAME`, and `SCOUT_MONITOR` are commonly set via environment variables."},"warnings":[{"fix":"Upgrade your Python environment to 3.8 or newer. If stuck on legacy Python, pin `scout-apm` to version `<=2.26.1`.","message":"Python 2.7 and early Python 3 versions (prior to 3.8) are no longer supported by recent `scout-apm` versions. Attempts to run with unsupported Python versions will fail or result in incomplete monitoring.","severity":"breaking","affected_versions":"3.0.0+"},{"fix":"Use a limited set of descriptive transaction names. For high-dimensionality data, add it as context to the transaction instead of making it part of the transaction name. Example: `api.Context.set(user_id=user.id)`.","message":"Avoid dynamically generating high-cardinality transaction names (e.g., including user IDs or highly variable data). This can lead to excessive unique transactions, impact UI performance, and may result in rate limiting of data.","severity":"gotcha","affected_versions":"All"},{"fix":"Use the new configuration names (`core_agent_log_level`, `core_agent_config_file`, `ignored_endpoints`). Old names might still work as aliases but are not recommended for new configurations.","message":"Several configuration options were renamed in previous major versions. `log_level` was renamed to `core_agent_log_level` (pre 2.6.0) and `config_file` to `core_agent_config_file` (pre 2.13.0). The `ignore` configuration for URL paths was replaced by `ignored_endpoints`.","severity":"deprecated","affected_versions":"<2.13.0, <2.6.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"1. Verify `SCOUT_KEY` and `SCOUT_NAME` are correct. 2. Ensure `SCOUT_MONITOR` is set to `True` (or 'true' via env var). 3. Enable debug logging (`logging.getLogger(\"scout_apm\").setLevel(logging.DEBUG)`) and check logs for errors or connection issues. 4. Ensure `install()` is called at application startup. 5. Confirm your Python version is 3.8+.","cause":"Common causes include incorrect API key or application name, `monitor` flag set to `False`, network issues preventing connection to the Scout APM collector, or the agent not being installed or initialized early enough in the application lifecycle. Python version incompatibility with `scout-apm` is also a possibility.","error":"Not seeing data in Scout APM UI after installation."},{"fix":"For Django applications, add `'scout_apm.django'` to the `INSTALLED_APPS` list in your `settings.py` file. No direct import statement for `scout_apm.django` is typically needed in your code.","cause":"This error often occurs when trying to directly `import scout_apm.django` or use it as a class, while Django integration primarily relies on adding `'scout_apm.django'` to your `INSTALLED_APPS` in `settings.py`.","error":"ModuleNotFoundError: No module named 'scout_apm.django'"}]}