Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring New relic in Spring boot with insight key

Tags:

In my springboot application, I have put following in my application.properties:

management.metrics.export.newrelic.api-key=MY_INSIGHT_KEY

management.metrics.export.newrelic.account-id=MY_NEWRELIC_ACCOUNT_ID

And in pom file, I have inserted micrometer-newrelic dependency as:

<dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-new-relic</artifactId>
        <version>${micrometer.version}</version>
</dependency>

But I don't see any metrics at insight site.

What am I missing in configuration?

Edit:

This link documents configuring micrometer for new relic in spring boot 2.

It asks to implement NewRelicConfig interface and create NewRelicMeterRegistry with it.

But where do I need to place this code in springboot 2 application.

like image 507
Mandroid Avatar asked May 27 '18 11:05

Mandroid


People also ask

How do I activate new relic?

To enable server-side configuration settings for monitored apps from the UI: Go to one.newrelic.com > APM. Click on your app. Then click Settings > Application > Server-side agent configuration.


1 Answers

In addition to your (correct) Spring configuration you must also add:

management.metrics.export.newrelic.enabled=true

You also need a copy of the New Relic agent newrelic.jar and a newrelic.yml configuration file with your licence key in it.

To get it, log in to your New Relic account and go to Insights. The menu at the top of the page has a head and shoulders image and your account name on the right-hand side. Click that and in the drop down menu click Account Settings.

On the right hand side of the Account Settings page there is a section titled 'Update your New Relic agent'. Click on the version number for the Java SE agent to download the zip file. Unpack the zip file and newrelic.jar and the template newrelic.yml are the files you need, they are in the top level directory of the extract.

Edit newrelic.yml and find this line:

license_key: '<%= license_key %>'. 

Remove <%= license_key %> and replace it with the licence key shown on the Account Settings page (its just above the section titled 'Update your New Relic agent'). The line should now look something like this (this isn't a real licence key BTW):

license_key: 'aab23456cf2a09'

Now when you run your application you will need to add the following JVM arguments:

-javaagent:newrelic.jar 
-Dnewrelic.config.file=newrelic.yml 
-Dnewrelic.environment=DEV

If newrelic.jar or newrelic.yml are not in your working directory, adjust the paths in these arguments appropriately. If you don't provide newrelic.jar then a stub implementation of the API is used instead and nothing gets sent to New Relic.

If you want confirmation from your app that it is sending metrics to New Relic then turn on logging in your application properties file:

logging.level.io.micrometer.newrelic=TRACE

This will show details of what is being sent to New Relic.

like image 136
Phil Haigh Avatar answered Oct 11 '22 09:10

Phil Haigh