Skip to content
On this page

Mappia ❤️ New Relic

We love New Relic. It is an incredibly useful monitoring and observability platform that can:

  • Help you debug your Magento store in production
  • Discover performance problems as they're happen
  • Alert on events as they occur in your application

This guide will walk you through installing and configuring New Relic for Magento 2 stores running with Mappia.

Container Image Preperation

Assuming that you have already been through containerizing your application, getting your store wired up to New Relic is only a little more configuration.

To start, add the following to your Dockerfile:

bash
RUN curl -L https://download.newrelic.com/php_agent/archive/11.1.0.14/newrelic-php5-11.1.0.14-linux-musl.tar.gz | tar -C /tmp -zx \
    && export NR_INSTALL_USE_CP_NOT_LN=1 \
    && export NR_INSTALL_SILENT=1 \
    && /tmp/newrelic-php5-11.1.0.14-linux-musl/newrelic-install install \
    && rm -rf /tmp/newrelic-php5-* /tmp/nrinstall* \
    && sed -i -e '$anewrelic.distributed_tracing_enabled=true' $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini

RUN sed -i -e "s/REPLACE_WITH_REAL_KEY/\$\{NEW_RELIC_LICENSE_KEY\}/" \
    -e "s/newrelic.appname[[:space:]]=[[:space:]].*/newrelic.appname=\"\$\{NEW_RELIC_APPNAME\}\"/" \
    -e '$anewrelic.distributed_tracing_enabled=true' \
    -e '$anewrelic.daemon.address=\"${NEW_RELIC_DAEMON_ADDRESS}\"' \
    $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini

Ideally, this should be placed fairly early in the Dockerfile to leverage build caching in your CI pipeline. Your Dockerfile could look something like this:

bash
FROM ${BASE_IMAGE}

WORKDIR /var/www/html

RUN curl -L https://download.newrelic.com/php_agent...

RUN sed -i -e "s/REPLACE_WITH_REAL_KEY/\$\{NEW_RELIC_LICENSE_KEY\}/"...

...

Now, publish the container. If you are using our documented CI pipelines, you can do this by submitting and merging a pull request!

Chart Installation

INFO

The newrelic-php-daemon Helm chart is only available through the private registry available to Mappia license holders.

New Relic does not provide a Helm Chart for their PHP Daemon so we made our own!

bash
helm install newrelic-php-daemon \
    --namespace newrelic --create-namespace \
    oci://mappia.azurecr.io/helm/newrelic-php-daemon \
    --version 0.3.8-alpha.0 # x-release-please-version

Configure and Upgrade Mappia

Now that we have configured your store's image, all that is left to do is configure Mappia with the license key and app name, and deploy your new image and configuration into your cluster by upgrade the chart.

First, we start by creating a secret that contains the New Relic license key.

INFO

You can find your license key on New Relic.

bash
kubectl create secret generic newrelic-secret --from-literal=newrelic-key=YOUR_LiCENSE_KEY

INFO

If you use terraform-azure you can use the pre-installed akvaks chart that comes out of the box to pull a new secret from your key vault.

yaml
secretProvider:
  secretObjects:
  - secretName: newrelic-secret
    type: Opaque
    data:
    - key: newrelic-license-key
      objectName: newrelic-license-key
hcl
module "my-terraform-project" {
  ...
  # Keyvault Settings
  helm_akvaks_values     = "./akvaks/values.yaml"
}

Then, you can configure the Mappia chart's values using the extraEnv key.

yaml
magento:
  extraEnv: 
  - name: NEW_RELIC_APPNAME
    value: "my-app"
  - name: NEW_RELIC_DAEMON_ADDRESS
    value: newrelic-php-daemon.newrelic.svc.cluster.local:31339
  - name: NEW_RELIC_LICENSE_KEY  
    valueFrom:
      secretKeyRef:
        name: newrelic-secret
        key: newrelic-license-key

After this is complete, simply upgrade your chart, wait a few minutes and you should be able to see your Magento store's application data in New Relic!

bash
helm upgrade zaney-zebras-and-zephyrs-llc oci://mappia.azurecr.io/helm/mappia --atomic