Installing New Relic APM Agents for Python and Java

Different languages, same observability

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

  1. Download the Java agent zip and extract newrelic.jar and newrelic.yml
  2. Set your license key and app name in newrelic.yml
  3. 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.

Arivanandhan Chitheshwaran