Monitoring your application locally with NewReclic

The New Relic Digital Intelligence Platform provides actionable insights to drive digital business results. You can monitor your application and infrastructure performance so you can quickly resolve issues and improve digital customer experiences.

Following instruction should help you to connect your application to NewRelic platform and customize application events sent to the platform.

Add Newrelic API classess to your project’s pom.xml:

xml
1 <dependency>
2    <groupId>com.newrelic.agent.java</groupId>
3    <artifactId>newrelic-api</artifactId>
4    <version>3.47.0</version>
5    <scope>provided</scope>
6</dependency>

If you want to run your application without newrelic agent, then use compile scope.

Download java agent:

bash
1NEWRELIC_VERSION=3.47.0
2
3if [ ! -d bin/newrelic ]; then
4    echo "NewRelic agent binary not found. Downloading one"
5    mkdir -p bin/newrelic
6    mvn dependency:get -Dartifact=com.newrelic.agent.java:newrelic-java:${NEWRELIC_VERSION}:zip
7    unzip ~/.m2/repository/com/newrelic/agent/java/newrelic-java/${NEWRELIC_VERSION}/newrelic-java-${NEWRELIC_VERSION}.zip -d ./bin
8fi

Run your application

bash
1NEW_RELIC_NO_CONFIG_FILE=true
2NEW_RELIC_APP_NAME="My App Local"
3NEW_RELIC_LICENSE_KEY=XXXXXXXXXXXX
4NEW_RELIC_LOG=stdout
5
6java -jar -server -javaagent:./bin/newrelic/newrelic.jar myapp.jar

Now you can publish custom error events to NewRelic using Java API:

java
1NewRelic.noticeError("Something really scary has happened...", false); // unexpected condition
2
3NewRelic.noticeError(new RuntimeException("my exception"), true); // expected exception
4
5NewRelic.addCustomParameter("customString", "bar");
6
7NewRelic.addCustomParameter("customNumber", 1);

References:

Konstantin Pavlov

Konstantin Pavlov

Software Engineer working with Java, Kotlin, Swift, and AI. Focusing on software architecture and building AI-infused apps. Passionate about testing and Open-Source projects.