Skip to content

APM agent install patterns on PaaS (Datadog, New Relic, Elastic APM)

Three ways to land an APM agent inside a PaaS container — node-template vs runtime injection vs sidecar — and which one survives container restarts.

The instrumentation ticket has been open for a sprint. The developer wants a real APM agent on the staging environment by Tuesday so they can see the slow trace they keep hearing about in support. You’re on a managed PaaS where you can’t just apt install datadog-agent on the host. You have three options and they fail in different ways: bake the agent into the node template, inject it at runtime via environment variables, or run it as a sidecar. Pick wrong and the next platform redeploy resets your work.

What’s happening

A PaaS container is rebuilt from a template every time the platform redeploys — and “redeploy” includes operator-initiated restarts, platform-initiated patching, scale-out events that spin up a new node, and most stack-version upgrades. Anything you change inside a running container with dnf install is lost. APM vendors document a “host install” path that assumes you own the box. On PaaS you do not. The three durable patterns are: node-template (build the agent into the stack image so every new node has it), runtime injection (drop the agent’s auto-instrumentation library into a path the runtime loads from on start, controlled by a few environment variables — works well for JVM, Node, Python, Ruby), and sidecar (run a second container in the same environment that the application reports to over the private network — used for the Datadog Agent’s trace + metrics pipeline). They have different blast radii, different update cadences, and different costs at scale.

How to verify

Confirm the runtime can load an agent before you commit to a pattern. For a JVM application, the right path is the -javaagent flag — list current JVM args:

# via platform web SSH or exec endpoint
ps -ef | grep java | tr ' ' '\n' | grep -E 'javaagent|-D'

For Node.js, the right path is NODE_OPTIONS=--require ...:

ps -ef | grep -E 'node|npm' | grep -v grep
env | grep -E 'NODE_OPTIONS|NEW_RELIC|DD_'

For Python, the right path is the OTEL_* / DD_* / ELASTIC_APM_* environment variables that the agent’s sitecustomize.py reads:

env | grep -E '^(OTEL|DD|NEW_RELIC|ELASTIC_APM)_'

If the variables are empty and the agent files aren’t on disk, none of the patterns are in place yet — pick one.

The fix

Match the pattern to your constraint:

Pattern 1 — Node-template (most durable, slowest to roll out). Edit the PaaS stack template (Jelastic JPS, custom Docker image, etc.) to install the agent at image build time and bind its config to the platform’s environment variables. Concrete JPS snippet for the Datadog Java tracer:

type: update
name: Add Datadog Java APM agent
nodes: [cp]
onInstall:
  cmd[cp]: |-
    mkdir -p /opt/datadog
    curl -sSL -o /opt/datadog/dd-java-agent.jar \
      'https://dtdg.co/latest-java-tracer'
    chown -R jelastic:jelastic /opt/datadog
    chmod 644 /opt/datadog/dd-java-agent.jar
  user: root

Then set the JVM start arguments to include -javaagent:/opt/datadog/dd-java-agent.jar and the platform environment variables for DD_API_KEY, DD_SERVICE, DD_ENV, DD_TRACE_AGENT_URL=http://datadog-agent.prod-api:8126. Survives every redeploy because the template owns it.

Pattern 2 — Runtime injection (fastest to roll out, dependency-tier on each restart). Use the platform’s environment variables and a startup hook to download the agent on container start. For a Node.js app with New Relic:

# In the platform's "before app start" hook:
mkdir -p /var/www/webroot/ROOT/node_modules
cd /var/www/webroot/ROOT
npm install --no-audit --no-fund newrelic@latest >/var/log/agent-install.log 2>&1

Set environment variables NEW_RELIC_LICENSE_KEY, NEW_RELIC_APP_NAME=api-prod, and NODE_OPTIONS="--require newrelic". Each new container will install the agent on first start. Risk: the npm registry is now a runtime dependency — pin versions and host a mirror if you care about uptime during npm outages.

Pattern 3 — Sidecar (best for trace volume + cost control). Add a second node to the PaaS environment running the vendor’s collector (Datadog Agent in this case) and point the application agents at it via DD_TRACE_AGENT_URL=http://datadog-agent.prod-api:8126. The application agents emit local traces; the sidecar batches, samples, and ships them. Two advantages: the sidecar holds the API key (so application containers don’t), and you can drop low-value traces in the sidecar’s rules rather than paying egress on them.

A Datadog Agent sidecar minimum config (/etc/datadog-agent/datadog.yaml):

api_key: <YOUR_KEY>
hostname: prod-api-sidecar
tags:
  - env:prod
  - service:api
apm_config:
  enabled: true
  apm_non_local_traffic: true
  receiver_port: 8126
logs_enabled: false

For Elastic APM, the sidecar is the APM Server itself talking to your Elastic cluster; for OpenTelemetry, see the distributed tracing with OpenTelemetry article — same pattern.

Decision rule. If the team is small and the agent rarely changes version, the node-template is the lowest-friction durable option — invest the half-day to bake it in. If you need to instrument a service before Tuesday and you accept dependency on the agent vendor’s package registry, runtime injection is fine. The sidecar pattern is what you graduate to when trace volume starts mattering for cost.

We stand up APM agents (Datadog, New Relic, Elastic) across managed PaaS environments and pick the install pattern that survives the next redeploy, as part of monitoring and support on managed PaaS — scope the rollout if you’d rather not eat the discovery cost.