Performance Monitoring with New Relic or Datadog

performance monitoring with new relic or datadog

Welcome dear reader, today you will learn how to keep an eye on your application’s performance with monitoring tools such as New Relic and Datadog. When a page takes five seconds to load, the question is always why — the database, the PHP code, or the web server? Monitoring tools answer that question with data instead of guesses.

At re:Software S.L., we create innovative solutions for businesses that aim to digitize their processes and routines, which also includes building high-throughput dashboards helping monitor performance!

Table of contents

What is APM and How Does It Work?

APM stands for Application Performance Monitoring. The idea is simple: a small agent — a PHP extension or a container sidecar — collects data about every request, and sends it to a dashboard where you see response times, error rates, database queries, and distributed traces.

A trace is the journey of one request through your stack. For example, a slow checkout page becomes a timeline: 40 ms in the web server, 2.8 s waiting for MySQL, 300 ms rendering. Instead of guessing, you see exactly which span eats the time. This pairs perfectly with the server-side fixes we covered, such as MySQL index optimization and connection pooling with PgBouncer.

How to Instrument a PHP Application

Both vendors distribute PHP agents. With New Relic, you install the extension and add your license key:

# Install the New Relic PHP agent
curl -Ls https://download.newrelic.com/php_agent/newrelic-php-agent.sh | bash

# Set your license key and app name
sudo sed -i 's/newrelic.license=.*/newrelic.license="YOUR_LICENSE_KEY"/' \
    /etc/php/8.2/conf.d/newrelic.ini
sudo sed -i 's/;/newrelic.appname = .*/newrelic.appname = "My Web App"/' \
    /etc/php/8.2/conf.d/newrelic.ini

Restart PHP-FPM, and transactions start appearing in the dashboard within minutes. Keep your license key private — treat it like a password.

With Datadog, you run their agent alongside your application — usually as a Docker container, which fits nicely if you already run your stack with Docker Compose:

services:
  datadog:
    image: gcr.io/datadoghq/agent:latest
    environment:
      DD_API_KEY: ${DD_API_KEY}
      DD_SITE: "datadoghq.com"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

The agent auto-discovers your containers, and the PHP tracing library (dd-trace-php) adds code-level traces.

Which Metrics Should You Watch?

Dashboards can overwhelm beginners, so start with these four metrics:

  • p95 latency: the response time 95% of users experience — averages hide outliers.
  • Error rate: the percentage of requests ending in HTTP 5xx errors.
  • Throughput: requests per second, to correlate load with slowdowns.
  • Database time: the share of request time spent in queries.

Set an alert when p95 latency crosses a threshold you consider unacceptable, and you have a production-safe starting point. Both platforms offer free tiers, so you can experiment before spending money.

Conclusion

That’s already it to get started with performance monitoring. Install an agent, watch p95 latency, error rate, throughput, and database time, and let traces show you exactly where slow requests burn their time. Leave a comment below with the monitoring tool your team prefers, and why!

By Editorial Team

A source code library for the open world! Find snippets and examples for popular programming languages including PHP, Javascript, Typescript, Node.js, Vue.js, and more.

Leave a Reply