New Relic Python Agent
Official APM agent for Python applications. Auto-instruments web frameworks (FastAPI, Django, Flask), databases (SQLAlchemy, psycopg, asyncpg), Redis, external HTTP calls, and AI/LLM libraries. Current version is 11.4.0 (Jan 2026). v12.0.0 released March 2026 with breaking removals.
Warnings
- breaking initialize() must be called before ALL other imports. Placing it after framework or library imports silently disables instrumentation — no exception is raised, agent appears to load but instruments nothing.
- breaking Cross Application Tracing (CAT) fully removed in v12.0.0. Was deprecated since v7.0.0. Old tutorials and LLM-generated code using cross_application_tracer config keys will silently do nothing.
- breaking Python 3.8 support dropped in v12.0.0 (Python 3.8 EOL was Oct 2024).
- deprecated aioredis instrumentation deprecated. The aioredis package itself is abandoned. New Relic will remove this instrumentation in a future release.
- deprecated Configuring agent via WSGI environ dictionary is deprecated.
- gotcha SSL certificates no longer bundled in v12.0.0. Environments without system CA certs (minimal Docker images) will fail to connect to New Relic.
Install
-
pip install newrelic -
newrelic-admin generate-config YOUR_LICENSE_KEY newrelic.ini -
pip install newrelic[certificates]
Imports
- agent initialize
import newrelic.agent newrelic.agent.initialize('newrelic.ini') # MUST be first lines before any framework imports - CLI runner (recommended)
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program gunicorn myapp.wsgi
Quickstart
# Option 1: CLI wrapper (recommended — handles ordering automatically)
# NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program gunicorn myapp.wsgi
# Option 2: Manual init — must be absolute first lines of entry point
import newrelic.agent
newrelic.agent.initialize('newrelic.ini')
# Framework imports AFTER initialize()
from fastapi import FastAPI
app = FastAPI()