The New Relic Ruby agent allows you to send information about application deployments by using the REST API or a Capistrano recipe (versions 2.x and 3.x) distributed with the Ruby agent. You can then view deployments in the New Relic UI. By default, all deployment information is recorded in your production environment. You can also customize the
rails_env variable for other environments, such as staging.
Assign an application name
To assign an application name:
- Download the latest version of the Ruby agent.
- Set the
newrelic.ymlfile to a meaningful name.
This will assign instances in the given environment the label given by
app_name when browsing your data in the New Relic user interface. The deployment upload script will use that label to associate an app with the deployment.
Add your user key
Optionally, you can record deployments via the New Relic REST API v2. To do this, provide your user key to the agent configuration using
api_key. When this configuration is present, the
newrelic deployments command automatically uses the REST API v2 deployment endpoint.
Record with the command line
If you installed the Ruby agent as a gem, you can record deployments directly by using the
Depending on your environment, you may need to run:
$bundle exec newrelic deployment
You can use several optional values with
description is short text.
deployments [OPTIONS] [description]OPTIONS:-a, --appname=name Set the application name.-i, --appid=ID Set the application IDIf not provided, will connect to the New Relic collector to get itDefault is app_name setting in newrelic.yml-e, --environment=name Override the (RAILS|RUBY)_ENV setting-u, --user=USER Specify the user deploying.-r, --revision=REV Specify the revision being deployed-c, --changes Read in a change log from the standard input-h Print this help
When using the
-c option, you can pipe the change log into the script. If not piping when using the
-c option, select
control-D to signify the end of file (EOF).
Record with Capistrano 3.x
The New Relic Ruby agent contains a Capistrano recipe that can record app deployments. After assigning your app name, edit your Capistrano files to communicate with the agent:
At the top of your Capfile, add the following line:require 'new_relic/recipes'
deploy.rbfile, include:after "deploy:updated", "newrelic:notice_deployment"
Record with Capistrano 2.x
You can record Capistrano 2.x deployments with the New Relic agent:
Tell Capistrano to load New Relic's recipes:
Add the following hooks to your
deploy.rbfile:# Notify New Relic of deployments.# This goes out even if the deploy fails, sadly.after "deploy", "newrelic:notice_deployment"after "deploy:migrations", "newrelic:notice_deployment"after "deploy:cold", "newrelic:notice_deployment"
The next time you run
cap deploy, the agent notifies New Relic of the deployment, and all time series charts will show the deployment event.
Customize your Capistrano configuration
If Capistrano is running the deployment notification recipe on a remote build machine,the build machine must have your . You can either copy a valid
newrelic.yml file to the build machine (possibly using a Capistrano Before Hook) or call
set :newrelic_license_key, 'YOUR_LICENSE_KEY' in your Capistrano configuration.
You can customize some deployment information by using Capistrano variables. If defined, these will override the defaults. These apply to both Capistrano 2 and 3.
Capistrano 2 and 3 variables
The app where the deployment will appear. By default this comes from the definition in the
If you set this value from the command line, you can only specify one application name. If you set this value in
The change log, which is determined by running the svn/git
Descriptive text that appears with the deployment. Default is empty.
The New Relic to use. By default this comes from the definition in the
The revision recorded for the deployment. Recommendation: If you are using Subversion, consider including the tag or branch name in addition to the revision.
The user to associate with the deployment.
Override Capistrano settings
In any version of Capistrano, you can override settings in your
set :newrelic_user, "username"
To override settings with Capistrano 2.x: From the command line:
$cap production deploy -Snewrelic_desc="Deploying beta Krakatau release"
This example will prompt for content that will appear in the deployment's change log:
set(:newrelic_changelog) doCapistrano::CLI.ui.ask "Enter a summary of changes: "end
Deploy to staging
By default, the
newrelic_rpm gem comes with Capistrano tasks to record all deployments in your production environment. If you have a separate staging application, you can change the
rails_env variable setting so that staging deployments are recorded in the staging app instead of the production app.
To identify deployments to your staging environment, use Capistrano or the command line.
Deploy to staging
If you are using Capistrano multistage, add this line to
If you are using Capistrano 2.x, add this information from the command line: