Installing New Relic APM Agents for Python and Java
Node.js gets a lot of attention, but most enterprises run Python and Java services too. Here's how to instrument both.
Python
pip install newrelic
newrelic-admin generate-config $NEW_RELIC_LICENSE_KEY newrelic.ini
Run your app through the agent:
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program gunicorn app:app
Supports Django, Flask, FastAPI, Celery, and common database and HTTP libraries automatically.
Custom Attributes
import newrelic.agent
newrelic.agent.add_custom_attribute('customer_tier', 'gold')
Java
- Download the Java agent zip and extract
newrelic.jarandnewrelic.yml - Set your license key and app name in
newrelic.yml - Start the JVM with the agent:
java -javaagent:/opt/newrelic/newrelic.jar -jar app.jar
Supports Spring Boot, Tomcat, JDBC, Kafka, and many more frameworks.
Custom Attributes
NewRelic.addCustomParameter("customer_tier", "gold");
Containers
Bake the agent into your Docker image and configure with environment variables (NEW_RELIC_LICENSE_KEY, NEW_RELIC_APP_NAME). Never hardcode the key.
Verify
Generate some traffic and look for the service in APM within a few minutes. Check the agent logs if it doesn't appear.
Naming Conventions
Use consistent app names like orders-api-prod and tags for team and environment.
Same principles in every language: install, name consistently, tag, add business attributes.