Grails Programmer : How to install new Relic in a Grails 3 app?

Recently I wanted to install new relic in a Grails 3 app which I distribute through Elastic Beanstalk.

One of the steps described in the new relic documentation is:

In your WAR file, add the newrelic.jar and newrelic.yml files to WEB-INF/lib/.

How to do that in a Grails 3 application?

  • Create a folder in the root folder of your application called newrelic
  • Copy both files (newrelic.jar and newrelic.yml) to the previously created newrelic folder.
  • Add the next snippet to your build.gradle file:
war {
    from('newrelic') {
        into 'WEB-INF/lib'
        include 'newrelic.*'

Additionally you would probably want to add to the dependencies block in build.gradle the next line:

compile "org.grails.plugins:newrelic:3.19.2"

This will install the Grails newrelic Plugin to your grails app.

Among other things the plugin will insert an interceptor which names transactions based on your controller/action information.

NewRelicInterceptor – An interceptor matching all requests to automatically name transactions as {controllerName}/{actionName}.

We are done in the grails side, complete the installation guide and you will have new relic configured.

Do you like to read about Groovy/Grails development? Yes, then Subscribe to Groovy Calamari a weekly curated email newsletter about the Groovy ecosystem which I happen to write 

2 thoughts on “Grails Programmer : How to install new Relic in a Grails 3 app?

  1. Benoit Hediard

    Thanks for the shoutout!

    For the newrelic.jar and newrelic.yml here is another option that we use.
    It will install/configure NewRelic app AND server monitoring on AWS ElasticBeanstalk.
    It will also call the NewRelic deployment API each time you start a new env.

    1- create a folder src/main/webapp/.ebextensions, a folder src/main/webapp/.ebextensions/files and add the newrelic.jar in it.

    2- create a file src/main/webapp/.ebextensions/app.config
    command: “bash -x .ebextensions/”

    3- create a file src/main/webapp/.ebextensions/
    # New Relic (Application monitoring)
    mkdir /var/lib/newrelic
    mv ./.ebextensions/files/newrelic*.jar /var/lib/newrelic/
    bash ./.ebextensions/files/ > /var/lib/newrelic/newrelic.yml

    # New Relic Agent (Server monitoring)
    rpm -Uvh
    yum -y install newrelic-sysmond
    /usr/sbin/nrsysmond-config –set license_key=$NR_LICENSE
    /etc/init.d/newrelic-sysmond start

    # New Relic deployment event
    export AP_VERSION=`cat ./META-INF/ | grep | cut -d= -f2`
    java -jar /var/lib/newrelic/newrelic.jar deployment –revision=$AP_VERSION

    4- create a file src/main/webapp/.ebextensions/files/ (to dynamically generate newrelic.yml based on env var)
    cat << EOF
    common: &default_settings
    license_key: '$NR_LICENSE'
    enable_auto_transaction_naming: false
    app_name: $NR_APPNAME

    Then, in your Beanstalk app config options, add "-javaagent:/var/lib/newrelic/newrelic.jar" to the JVM command line parameter and set NR_LICENSE and NR_APPNAME env properties.

    Note: maybe, this is something I should add in the Grails Newrelic plugin README on Github :).

  2. Daniel Hammer


    Is this approach still relevant for Grails v3.3.9 and “org.grails.plugins:newrelic:4.9.0” (New Relic Java Agent v4.8.0)?

    Or is there more steps involved?

    Best regards,


Leave a Reply

Your email address will not be published. Required fields are marked *