Introducing New Relic to Java apps running on Heroku

I didn't find many articles in Japanese, so I worked while looking at New Relic's official documentation. It will be a memorandum.

Added New Relic APM

You can use the heroku command or the Configure Add-ons on the screen, so add the New Relic add-on. (Since I will go to the management screen of New Relic later, it may be easier from the screen ...?)

Introduced Java Agent

Normally, the key will load ** newrelic.yml ** in the same directory as the jar, but we will install a Java Agent to avoid git management of the key.

Register the app name

Register the app name in Config Vars on Heroku with the key ** NEW_RELIC_APP_NAME **. If it is settings.gradle or pom, I think that it should be described in artifactId.

heroku config:set NEW_RELIC_APP_NAME="APP_NAME"

Register key

You can get the key from New Relic's admin screen. スクリーンショット 2019-09-28 18.06.59.png Select APM スクリーンショット 2019-09-28 18.09.14.png When you select Java, this screen will appear, so press "Reveal license key" to get the key. Then register with the key ** NEW_RELIC_LICENSE_KEY **.

heroku config:set NEW_RELIC_LICENSE_KEY="LICENSE_KEY"

Gradle settings

In the case of Maven, it is as described on the official document side, and in the case of Gradle, the operation was confirmed as follows.

buld.gradle


dependencies {
  .....
  compileOnly 'com.newrelic.agent.java:newrelic-java:5.7.0'
}

(At the time of writing, 5.7.0 was the latest.)

Introduced newrelic.jar

The jar is obtained from the management screen of New Relic earlier. スクリーンショット 2019-09-28 18.09.14 2.png When you press the link, the zip will drop, so unzip it and place only "** newrelic.jar **" in the project doco. (Since it is described in the Procfile, I think it can be anywhere.)

Procfile changes

Finally, add the ** javaagent ** option to your Procfile. For example, in Springboot, if newrelic.jar is placed directly under the project

Procfile


web: java -jar build/libs/app-0.0.1-SNAPSHOT.jar

↓↓↓↓↓

Procfile


web: java -javaagent:newrelic.jar -jar build/libs/app-0.0.1-SNAPSHOT.jar

It will be.

deploy

After deploying, you will see a screen like this in 5 minutes at the longest, and you will be able to see Web transactions time etc. by selecting the application.

スクリーンショット 2019-09-28 18.32.12.png

Thank you for your hard work.

Digression

It seems to use more memory than I expected. .. .. In the case of my app, I gave up the operation because ** Error R14 (Memory quota exceeded) ** occurred probably because Spring Batch is also running. The memory used will increase with wrinkles.

Recommended Posts

Introducing New Relic to Java apps running on Heroku
Introducing New Relic to Rails apps on Heroku
Introducing Bugsnag on Heroku
How to deploy on heroku
How to deploy a simple Java Servlet app on Heroku
Catch up on new features from Java 7 to Java 9 at once
Links that I referred to before running Elasticsearch 7.7 on Java 11
How to check the database of apps deployed on Heroku
[Java] How to update Java on Windows
Introducing Java tips GreenMail to Junit5
My note: Introducing Java to Ubuntu
Deploy Rails on Docker to heroku
Ruby on Rails ✕ Docker ✕ MySQL Introducing Docker and docker-compose to apps under development
How to check Java installed on Mac
How to redo a deployment on Heroku
Introducing Basic Authentication on Heroku [Spring Framework]
I want to display background-ground-image on heroku.
Convert all Android apps (Java) to Kotlin
How to publish an application on Heroku
Deploy to Heroku [Ruby on Rails] Beginner
Deploy a Java web app on Heroku
Creating Java Web Applications to Azure Web Apps
Steps to register Java files on GitHub
Introduction to Java Web Apps Performance Troubleshooting
Error when running git push heroku master on Heroku
Try to build Java8 environment on Amazon Linux2
How to save images on Heroku to S3 on AWS
Ssh login to the app server on heroku
Note how to rollback Mysql deployed on Heroku
[Rails MySQL] How to reset DB on heroku
I touched on the new features of Java 15
Precautions when running apps including Jackson on Glassfish 4.1
[Java] 4 steps to implement splash screen on Android
[Java] Memo on how to write the source
I tried running Java on a Mac terminal
How to post images on Heroku + CarrierWave + S3
I want to implement it additionally while using kotlin on a site running Java