Show Navigation


Grails NewRelic plugin

Owner: agorapulse | 5.2.0 | Jul 16, 2019 | Package | Issues | Source | License: Apache-2.0

dependencies {
    compile 'org.grails.plugins:newrelic:5.2.0'


NewRelic Grails Plugin

Build Status Download


IMPORTANT: Project retirement

This project is retired. As Micronaut become core of the Grails starting at Grails 4, please, use Micronaut AWS SDK instead.

This plugin will make New Relic instrumentation available to a Grails project.
It is a port to Grails 3.X of the original NewRelic Grails Plugin, originally written by CP Lim. Starting with version 5.2.0 the plugin is compatibile with Grails 4.

Grails NewRelic Plugin provides the following Grails artefacts:

  • NewRelicInterceptor - An interceptor matching all requests to automatically name transactions as {controllerName}/{actionName}.
  • NewRelicService - A client to call NewRelic Java agent API, which is a wrapper around NewRelic API java library.
  • NewRelicTagLib - A collection of tags to easily integrate NewRelic Browser in your GSPs for Real User Monitoring (RUM).

New Relic needs to be installed on the running application server in order for the plugin to work. This is extensively documented by the New Relic team. Once installed, New Relic Browser will need to be configured for manual instrumentation .


Declare the plugin dependency in the build.gradle file, as shown here:

repositories {
    maven { url "" }
dependencies {
    compile "org.grails.plugins:newrelic:5.2.0"

Thanks to binary incompability of trait between the different Groovy version, current version can be used with Grails 3.2.11 and newer. Try older versions of this plugin if you need to use it with older version of Grails.


By default the New Relic RUM code will only be enabled for Production environments. If you need it to be enabled for other environments, make sure that it is explicitly enabled in your configs

    enabled: true


Once New Relic and this plugin has been added to your web application, you are ready to add the tags to your page(s).
New Relic provides some best practices on when to all these tag methods.
Ideally, you would only need to add it to your layout page(s) as follows:

<!DOCTYPE html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <!-- other tags -->
    <!-- more tags -->

However, if there are more GSP that need these tags, then just make sure they are added at the appropriate locations in the DOM.

Enabling NewRelic for Development

NewRelic should be enabled in the production environment as per the instructions here, but if you need to enable this in other environments, make sure that the configs have enabled NewRelic for your environment, and add the following to your GRAILS_OPT environment

export GRAILS_OPTS="-javaagent:/path/to/newrelic.jar"

The next time you execute 'run-app' or 'run-war', NewRelic instrumentation code will be included in your generated HTML pages.

On newer versions of grails that use a forked jvm, you may need to include the java agent in your tomcat configuration. This is in BuildConfig.groovy.

grails.tomcat.jvmArgs = ["-javaagent:/path/to/newrelic.jar"]

BONUS - Installing and configuring NewRelic on AWS Elastic Beanstalk

Here are some instructions to 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/files/ (to dynamically generate newrelic.yml based on app env properties)

cat << EOF
common: &default_settings
license_key: '$NR_LICENSE'
enable_auto_transaction_naming: false
app_name: $NR_APPNAME

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/app.config

    command: "bash -x .ebextensions/"

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.


To report any bug, please use the project Issues section on GitHub.