Date Published: March 14, 2022
Setting up New Relic deployment markers
New Relic's monitoring tool offers deployment markers, a feature to accept a POST request to mark the deployment of code.
Below are the steps required to enable automated deployment markers using Acquia Cloud Hooks and New Relic's API. Note that these all happen in your repository and need to be pushed to Acquia Cloud.
-
Create hooks/prod/post-code-deploy/newrelic.sh
file with the following contents (see https://github.com/acquia/cloud-hooks/blob/master/samples/newrelic/newrelic.sh ):
#!/bin/sh
#
# This sample a Cloud Hook script to update New Relic whenever there is a new code deployment
site=$1 # The site name. This is the same as the Acquia Cloud username for the site.
targetenv=$2 # The environment to which code was just deployed.
sourcebranch=$3 # The code branch or tag being deployed.
deployedtag=$4 # The code branch or tag being deployed.
repourl=$5 # The URL of your code repository.
repotype=$6 # The version control system your site is using; "git" or "svn".
#Load the New Relic APPID and APPKEY variables.
. $HOME/newrelic_settings
#https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/recording-deployments#post-deployment
curl -X POST "https://api.newrelic.com/v2/applications/$APPID/deployments.json" \
-H "X-Api-Key:$APIKEY" -i \
-H "Content-Type: application/json" \
-d \
"{
\"deployment\": {
\"revision\": \"$deployedtag\",
\"changelog\": \"$deployedtag deployed to $site.$targetenv\",
\"description\": \"$deployedtag deployed to $site.$targetenv\",
\"user\": \"$username\"
}
}"
-
Create hooks/prod/post-code-deploy/newrelic_settings
with the following contents:
(see https://github.com/acquia/cloud-hooks/blob/master/samples/newrelic/newrelic_settings)
APIKEY='123456abcdefgh1234567890abcdefgh1234567890a bc1234567890'
APPID='123456'
username='[email protected]'
-
Replace application_id
and x-api-key
with the values from New Relic. From the instructions at https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/ get your application_id and your x-api-key. Store these variables and a username you wish to send to New Relic in $HOME/newrelic_settings
file.
-
Make newrelic_settings executable
run chmod a+x hooks/prod/post-code-deploy/newrelic.sh
For more information on Acquia Cloud Hooks, see https://docs.acquia.com/cloud-platform/develop/api/cloud-hooks/
Let us know if you get stuck on any of those points by getting in touch with Support.
Did not find what you were looking for?
If this content did not answer your questions, try searching or contacting our support team for further assistance.