Skip to main content
  1. Posts/

Monitoring your application locally with NewReclic

Table of Contents

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:

 <dependency>
    <groupId>com.newrelic.agent.java</groupId>
    <artifactId>newrelic-api</artifactId>
    <version>3.47.0</version>
    <scope>provided</scope>
</dependency>

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

Download java agent:

NEWRELIC_VERSION=3.47.0

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

Run your application

NEW_RELIC_NO_CONFIG_FILE=true
NEW_RELIC_APP_NAME="My App Local"
NEW_RELIC_LICENSE_KEY=XXXXXXXXXXXX
NEW_RELIC_LOG=stdout

java -jar -server -javaagent:./bin/newrelic/newrelic.jar myapp.jar

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

NewRelic.noticeError("Something really scary has happened...", false); // unexpected condition

NewRelic.noticeError(new RuntimeException("my exception"), true); // expected exception

NewRelic.addCustomParameter("customString", "bar");

NewRelic.addCustomParameter("customNumber", 1);

References: #