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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docker-compose-services/newrelic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# New Relic

This recipe adds a New Relic daemon service and PHP agent to the `web` container.

Once configured it will begin reporting data to New Relic. Your DDEV project name will be the app name reported in your New Relic APM list.

## Configuration

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.

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?

20 changes: 20 additions & 0 deletions docker-compose-services/newrelic/docker-compose.newrelic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# Adds New Relic support for performance profiling.
version: '3.6'
services:
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.

labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT

web:
build:
args:
NEW_RELIC_AGENT_VERSION: "9.2.0.247"
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.

2 changes: 2 additions & 0 deletions docker-compose-services/newrelic/php/newrelic-ddev.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
newrelic.distributed_tracing_enabled=true
newrelic.daemon.address="newrelic:31339"
21 changes: 21 additions & 0 deletions docker-compose-services/newrelic/web-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 \
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.

&& 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}\"/" \
/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
Comment on lines +16 to +21
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?)