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

Add recipe for New Relic, fixes #102 #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mglaman
Copy link
Collaborator

@mglaman mglaman commented Dec 2, 2020

Fixes #102

@rfay rfay changed the title Add recipe for New Relic Add recipe for New Relic, fixes #102 Dec 29, 2020
Copy link
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice setup, and I know it's been useful for you.

I wasn't successful getting it going by just following the instructions. It's been a number of years since I've used newrelic, so don't even remember what it's best for. Like blackfire?

Anyway, I guess I need more coaching to get it going. I tried with php7.4. Oh... there's a bug. You used PHP_DEFAULT_VERSION instead of DDEV_PHP_VERSION

There are two configuration items in `docker-compose.newrelic.yaml`.

* `NEW_RELIC_LICENSE_KEY`: You must specify your license key.
* `NEW_RELIC_AGENT_VERSION`: Specify the New Relic agent version.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that NEW_RELIC_AGENT_VERSION is specified, and not actually a configuration item? Or at least we can use it as-is for now, because it's wired in elsewhere.

Comment on lines +16 to +21
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put the newrelic.ini in .ddev/php ? It's easy to capture it using your technique , use docker cp to grab it. Instructions would have to change to have them change the appname there in the .ddev/php/newrelic.ini

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The technique used here copies only into /etc/php/${PHP_DEFAULT_VERSION}//conf.d - which means (currently) /etc/php/7.3//conf.d. But we might want php7.4 or something else.

We can't use DDEV_PHP_VERSION here because it's determined at container start time.

So that makes the previous suggestion more important. If you just put it in .ddev/php, it will go in the right place.

Alternately, copy into all the places (5.6/7.0/7.1/7.2/7.3/7.4/8.0) (I don't think 8.0 works yet?)

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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I note that this looks cleaner to do with DEBIAN_FRONTEND=noninteractive apt-get -y install newrelic-php5 and perhaps using the technique in https://docs.newrelic.com/docs/agents/php-agent/installation/php-agent-installation-ubuntu-debian - it still requires a Dockerfile because of the custom repo though.

newrelic:
image: newrelic/php-daemon
container_name: ddev-${DDEV_SITENAME}-newrelic
ports: ['31339']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting to where I like expose a lot more than ports these days, because a statement like this just does an expose and exposes an ephemeral port that's hard to find out.

NEW_RELIC_LICENSE_KEY: ""
NEW_RELIC_APPNAME: ${DDEV_SITENAME}
links:
- newrelic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be

Suggested change
- newrelic
- newrelic:newrelic

Maybe they're the same.

There are two configuration items in `docker-compose.newrelic.yaml`.

* `NEW_RELIC_LICENSE_KEY`: You must specify your license key.
* `NEW_RELIC_AGENT_VERSION`: Specify the New Relic agent version.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of ends abruptly. Now what do you do when you've done these things? What do I have to set up on NewRelic? How do I know if it's working?

Comment on lines +16 to +21
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The technique used here copies only into /etc/php/${PHP_DEFAULT_VERSION}//conf.d - which means (currently) /etc/php/7.3//conf.d. But we might want php7.4 or something else.

We can't use DDEV_PHP_VERSION here because it's determined at container start time.

So that makes the previous suggestion more important. If you just put it in .ddev/php, it will go in the right place.

Alternately, copy into all the places (5.6/7.0/7.1/7.2/7.3/7.4/8.0) (I don't think 8.0 works yet?)

@rfay
Copy link
Member

rfay commented Dec 29, 2020

I unfortunately tried this on a Drupal 9 project, so when I switched to PHP7.3 it failed. But then I tried on a D8 project, finally found some data that I didn't know how to use on Dashboards->Browser

@mglaman
Copy link
Collaborator Author

mglaman commented Jan 4, 2021

Thanks for the review @rfay, I've got this on my list to update

@rfay
Copy link
Member

rfay commented Jan 24, 2021

Looking forward to seeing this get in @mglaman - thanks for the contribution!

@rfay
Copy link
Member

rfay commented Apr 20, 2021

I'm sure this will be useful to people, so hope you can return to it.

@rfay
Copy link
Member

rfay commented Jun 4, 2021

@mglaman you have lots to do, but please push this up to the top of your priority list and get it finished, thanks!

@rfay
Copy link
Member

rfay commented Jan 15, 2022

It's been more than a year @mglaman - maybe you can fit this in with your 20% if you get it!

@jeremysimmons
Copy link

@mglaman I would love to see this finished!

@Gonzalo2683
Copy link

Het @mglaman, I know it's been a long time, maybe you can help us on how to configure this service, thank you very much in advance

@Gonzalo2683
Copy link

Gonzalo2683 commented Jun 24, 2023

Hello everyone, I have an example that is working decently, I'm not sure if it's the recommended way to do it. I have tried to follow the comments left by @rfay . I'm not an expert in Docker, so if you see any improvements, feel free to add them, and perhaps this recipe can become available.

docker-compose.newrelic.yaml

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:
    environment:
      IMAGE_NAME: newrelic/php-daemon
      NEW_RELIC_AGENT_VERSION: "9.2.0.247"
      NEW_RELIC_LICENSE_KEY: "YOUR_API_KEY_HERE"
      NEW_RELIC_APPNAME: ${DDEV_SITENAME}
      NEW_RELIC_DAEMON_ADDRESS: "newrelic:31339"
    links:
      - newrelic:$DDEV_HOSTNAME

.ddev/php/newrelic.ini

[newrelic]
newrelic.license = "YOUR_API_KEY_HERE"
newrelic.appname = "THE_SAME_NAME_OF_NEW_RELIC_APPNAME_VAR"
newrelic.distributed_tracing_enabled = true
newrelic.transaction_tracer.enabled = true

newrelic.application_logging.enabled = true
newrelic.application_logging.metrics.enabled = true
newrelic.application_logging.forwarding.enabled = true

.ddev/web-build/Dockerfile.newrelic

FROM $BASE_IMAGE

ARG NEW_RELIC_AGENT_VERSION
ARG NEW_RELIC_LICENSE_KEY
ARG NEW_RELIC_APPNAME

RUN wget -O - https://download.newrelic.com/548C16BF.gpg | apt-key add - && \
    sh -c 'echo "deb http://apt.newrelic.com/debian/ newrelic non-free" > /etc/apt/sources.list.d/newrelic.list' && \
    apt-get update

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install newrelic-php5

Run ddev restart, browse your ddev site to generate some data.
Go to newrelic page, find APM & Services.

Example
ddev_newrelic

@rfay
Copy link
Member

rfay commented Jun 24, 2023

@Gonzalo2683 you're doing great! Could you please create an add-on that implements this? It's super easy, and that's the maintainable way to handle these recipes.

I'm sure that after you do that (use a good README) then @tyler36 and I will be happy to try it out and offer suggestions/issues/PRs to your repo.

@lexsoft00
Copy link

Is there a way to run this on Apple M2 ARM64? Any installation guide or commands would helpful, thanks.

@rfay
Copy link
Member

rfay commented Jan 13, 2024

It looks like newrelic does not provide an arm64 image, https://hub.docker.com/r/newrelic/php-daemon/tags, even 3+ years after arm64 has arrived.

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 this pull request may close these issues.

New Relic service
5 participants