{"id":3478,"library":"elastic-apm","title":"Elastic APM Python Agent","description":"The official Python module for Elastic APM. It provides full out-of-the-box support for many popular frameworks, including Django and Flask, and can be adapted for most WSGI-compatible web applications or used in any standalone Python application. It monitors applications in real-time, collecting performance metrics, tracing transactions, and capturing errors. Currently at version 6.25.0, it sees regular updates focusing on framework compatibility and performance.","status":"active","version":"6.25.0","language":"en","source_language":"en","source_url":"https://github.com/elastic/apm-agent-python","tags":["apm","monitoring","observability","elastic","tracing","performance"],"install":[{"cmd":"pip install elastic-apm","lang":"bash","label":"Install core package"},{"cmd":"pip install elastic-apm[flask]","lang":"bash","label":"Install with Flask support"},{"cmd":"pip install elastic-apm[django]","lang":"bash","label":"Install with Django support"}],"dependencies":[{"reason":"Required runtime environment.","package":"Python","version":">=3.6, <4"}],"imports":[{"note":"For general-purpose APM client initialization outside of framework integrations.","symbol":"Client","correct":"from elasticapm import Client"},{"note":"For integrating with Flask applications. Similar imports exist for other frameworks like Django.","symbol":"ElasticAPM","correct":"from elasticapm.contrib.flask import ElasticAPM"},{"note":"Decorator for manually creating spans around functions.","symbol":"capture_span","correct":"from elasticapm import capture_span"}],"quickstart":{"code":"import os\nfrom flask import Flask\nfrom elasticapm.contrib.flask import ElasticAPM\n\napp = Flask(__name__)\n\napp.config['ELASTIC_APM'] = {\n    'SERVICE_NAME': os.environ.get('ELASTIC_APM_SERVICE_NAME', 'my-flask-app'),\n    'SERVER_URL': os.environ.get('ELASTIC_APM_SERVER_URL', 'http://localhost:8200'),\n    'ENVIRONMENT': os.environ.get('ELASTIC_APM_ENVIRONMENT', 'development'),\n    'CAPTURE_HEADERS': True,\n    'TRANSACTIONS_IGNORE_PATTERNS': ['^/healthcheck']\n}\n\napm = ElasticAPM(app)\n\n@app.route('/')\ndef hello_world():\n    apm.client.capture_message('Hello World request received!')\n    try:\n        1 / 0\n    except ZeroDivisionError:\n        apm.client.capture_exception()\n    return 'Hello, World!'\n\n@app.route('/healthcheck')\ndef healthcheck():\n    return 'OK'\n\nif __name__ == '__main__':\n    # Set environment variables or ensure APM server is running at localhost:8200\n    # For example: ELASTIC_APM_SERVICE_NAME=my-service ELASTIC_APM_SERVER_URL=http://localhost:8200 python your_app.py\n    app.run(debug=True)\n","lang":"python","description":"This Flask example demonstrates basic setup with environment variable configuration, capturing a custom message, and an exception. It also shows how to ignore specific routes from tracing using `TRANSACTIONS_IGNORE_PATTERNS`. Ensure an Elastic APM Server is running and accessible at the configured `SERVER_URL`."},"warnings":[{"fix":"Upgrade your Python environment to 3.7 or higher.","message":"Python 3.6 support will be removed in version 7.0.0 of the agent. Projects using Python 3.6 must upgrade to Python 3.7+ before upgrading to agent version 7.0.0 or later.","severity":"breaking","affected_versions":">=6.23.0 (upcoming v7.0.0)"},{"fix":"Migrate to using the `logging` parameter in the `ElasticAPM` constructor (e.g., `ElasticAPM(app, logging='WARNING')`) or use an external log shipper like Filebeat.","message":"The log shipping `LoggingHandler` will be removed in version 7.0.0. Consider using built-in log shipping via `logging=LEVEL` in the `ElasticAPM` constructor or filebeat for less urgent logs.","severity":"deprecated","affected_versions":">=6.23.0 (upcoming v7.0.0)"},{"fix":"Add `--enable-threads` or `threads = <num_threads>` to your uWSGI configuration.","message":"When integrating with Flask and uWSGI, ensure that threads are explicitly enabled in your uWSGI configuration, as the APM agent relies on background threads for metrics collection and other operations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your `elastic-apm` agent to version 2.0 or higher if using APM Server 6.2+.","message":"Compatibility with APM Server versions is crucial. For APM Server 6.2 and higher, ensure you are using `elastic-apm` agent version 2.0 or higher.","severity":"gotcha","affected_versions":"<2.0 (agent) with >=6.2 (server)"},{"fix":"Upgrade `elastic-apm` to version 6.25.0 or later if using Tornado 6.5.3.","message":"In `v6.25.0`, a change in Tornado 6.5.3's `HttpHeaders` `in` operator behavior was handled. If using Tornado and upgrading it, ensure you are on `elastic-apm` v6.25.0+ to avoid potential issues.","severity":"gotcha","affected_versions":"Tornado 6.5.3 with elastic-apm <6.25.0"},{"fix":"Ensure your APM Server has a valid, verifiable TLS certificate, or configure `ELASTIC_APM_SERVER_CA_CERT` if using a custom CA.","message":"When running in FIPS mode (Federal Information Processing Standard), server certificate verification becomes mandatory for secure communication with the APM Server.","severity":"gotcha","affected_versions":">=6.24.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}