Skip to content

CircleCI: New Relic

Skpr provides developers with a simple, easy-to-use integration for configuring New Relic APM.

This document demonstrates how developers can implement CircleCI workflows to complement the existing APM integration.

Authentication

CircleCI administrators will need to setup a New Relic API Key.

Instructions on how to get an API key can be found here.

All the examples below use the NEW_RELIC_TOKEN environment variable when configuring access to New Relic.

Examples

Record Deployments

When deploying to production, it's important to understand how new code performs in real-time, especially if error rates increase or performance degrades. New Relic allows you to do this and has support for creating deployment markers that appear in APM charts.

To read more see the official documentation.

The following example demonstrates how development teams can record deployments with their existing Skpr workflow.

Workflow Outline

  • When pushing to main branch, deploy to dev environment
  • After a successful deployment to dev environment, record deployment with New Relic
version: 2.1

orbs:
  new-relic: configure/new-relic@0.1.4
  skpr: skpr/skpr@1.2

commands:
  skpr-pre-package:
    steps:
      - run:
          name: Pull Base Images
          command: |
            docker pull skpr/php-cli:8.1-v2-latest
            docker pull skpr/php-fpm:8.1-v2-latest
            docker pull skpr/nginx-drupal:v2-latest

  skpr-post-deploy:
    parameters:
      env:
        type: string
    steps:
      - run:
          name: Skpr Post-Deploy
          command: skpr exec << parameters.env >> -- make deploy

workflows:
  deploy:
    jobs:
      - skpr/deploy:
          name: deploy_dev
          env: dev
          pre-package: [ skpr-pre-package ]
          post-deploy:
            - skpr-post-deploy: { env: dev }
          filters:
            branches:
              only: [ main ]

      - new_relic_deploy:
          name: new_relic_deploy_dev
          # Application name MUST match name configured for Skpr environment.
          app_name: "My Application: Dev"
          requires:
            - deploy_dev

jobs:
  new_relic_deploy:
    parameters:
      app_name:
        type: string
        default: ""
    docker:
      - image: circleci/node
    steps:
      - checkout
      - run:
          name: Generate Version
          command: |
            VERSION=$(git describe --tags --always)
            echo "Generated version: $VERSION"
            echo "export VERSION=$VERSION" >> $BASH_ENV
      - new-relic/deployment:
          app-name: <<parameters.app_name>>
          api-key: '${NEW_RELIC_TOKEN}'
          user: '${CIRCLE_USERNAME}'
          revision: '${VERSION}'