Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

New Relic service #102

Open
mglaman opened this issue Dec 2, 2020 · 3 comments · May be fixed by #103
Open

New Relic service #102

mglaman opened this issue Dec 2, 2020 · 3 comments · May be fixed by #103

Comments

@mglaman
Copy link
Collaborator

mglaman commented Dec 2, 2020

I'll document adding New Relic as a service. So far I have this:

.ddev/docker-compose.newrelic.yaml:

---
# Adds New Relic support for performance profiling.
version: '3.6'
services:
  newrelic:
    image: newrelic/php-daemon
    container_name: ddev-${DDEV_SITENAME}-newrelic
    ports: ['31339']
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT

  web:
    args:
      NEW_RELIC_AGENT_VERSION: "9.2.0.247"
      NEW_RELIC_LICENSE_KEY: "NEW_RELIC_LICENSE_KEY"
      NEW_RELIC_APPNAME: ${DDEV_SITENAME}
      NEW_RELIC_DAEMON_ADDRESS: "newrelic:31339"
    links:
      - newrelic:$DDEV_HOSTNAME

And in .ddev/web-build/Dockerfile

ARG BASE_IMAGE
FROM $BASE_IMAGE

# Install New Relic
# @see https://docs.newrelic.com/docs/agents/php-agent/advanced-installation/docker-other-container-environments-install-php-agent
ARG NEW_RELIC_AGENT_VERSION
ARG NEW_RELIC_LICENSE_KEY
ARG NEW_RELIC_APPNAME

RUN curl -L https://download.newrelic.com/php_agent/archive/${NEW_RELIC_AGENT_VERSION}/newrelic-php5-${NEW_RELIC_AGENT_VERSION}-linux.tar.gz | tar -C /tmp -zx \
    && export NR_INSTALL_USE_CP_NOT_LN=1 \
    && export NR_INSTALL_SILENT=1 \
    && /tmp/newrelic-php5-${NEW_RELIC_AGENT_VERSION}-linux/newrelic-install install \
    && rm -rf /tmp/newrelic-php5-* /tmp/nrinstall*

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="newrelic-php-daemon:31339"' \
    $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini

Once I know it all works I'll open a PR

@mglaman
Copy link
Collaborator Author

mglaman commented Dec 2, 2020

Ope, copy and paste fail. The container name is newrelic not newrelic-php-daemon

    -e '$anewrelic.daemon.address="newrelic-php-daemon:31339"' \

This fails:

$(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini

It only configures New Relic for the CLI.

🤔 Need to get creative here and find a way to dynamically set the license in the configuration, properly.

@mglaman
Copy link
Collaborator Author

mglaman commented Dec 2, 2020

Borrowing from the start.sh

        cp /mnt/ddev_config/php/*.ini /etc/php/${DDEV_PHP_VERSION}/cli/conf.d/
        cp /mnt/ddev_config/php/*.ini /etc/php/${DDEV_PHP_VERSION}/fpm/conf.d/

Define standard items in a custom .ddev/php/newrelic.ini and then in the Dockerfile

RUN sed -i -e "s/REPLACE_WITH_REAL_KEY/${NEW_RELIC_LICENSE_KEY}/" \
    -e "s/newrelic.appname[[:space:]]=[[:space:]].*/newrelic.appname=\"${NEW_RELIC_APPNAME}\"/" \
    /etc/php/${PHP_DEFAULT_VERSION}/fpm/conf.d/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}\"/" \
    /etc/php/${PHP_DEFAULT_VERSION}/cli/conf.d/newrelic.ini

@mglaman
Copy link
Collaborator Author

mglaman commented Dec 2, 2020

Screen Shot 2020-12-01 at 9 09 52 PM

WOO! Well look at that!

mglaman added a commit to mglaman/ddev-contrib that referenced this issue Dec 2, 2020
@mglaman mglaman linked a pull request Dec 2, 2020 that will close this issue
mglaman added a commit to mglaman/ddev-contrib that referenced this issue Dec 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant