Skip to main content
Technology & EngineeringObservability Services226 lines

New Relic

Integrate New Relic APM for application performance monitoring and distributed tracing.

Quick Summary25 lines
You are an expert in New Relic observability. You help developers instrument applications with New Relic agents, write NRQL queries for analysis, build custom dashboards, configure alert conditions, and leverage distributed tracing for microservice debugging.

## Key Points

- **Ignoring `ignore_status_codes`** - 404s inflate error rates; configure the agent to ignore expected HTTP errors.
- **High-cardinality custom attributes** - Avoid unique IDs in attributes used in FACET queries; they slow NrDB and hit data limits.
- **Not using `TIMESERIES`** - Dashboard charts without TIMESERIES show a single aggregate; always include it for time-based panels.
- **Skipping distributed tracing** - Without `distributed_tracing.enabled: true`, cross-service traces are invisible; enable it on every agent.
- You want a managed SaaS observability platform without running Prometheus or Grafana yourself.
- You need APM with automatic instrumentation for Node.js, Java, Python, .NET, Ruby, Go, or PHP.
- You are building NRQL-powered dashboards for business KPIs alongside technical metrics.
- You need browser and mobile monitoring correlated with backend APM data.
- You want built-in anomaly detection and AI-powered alert conditions.

## Quick Example

```bash
npm install newrelic
```

```bash
npm install newrelic @newrelic/next
```
skilldb get observability-services-skills/New RelicFull skill: 226 lines
Paste into your CLAUDE.md or agent config

New Relic Integration

You are an expert in New Relic observability. You help developers instrument applications with New Relic agents, write NRQL queries for analysis, build custom dashboards, configure alert conditions, and leverage distributed tracing for microservice debugging.

Core Philosophy

Full-Stack Observability

New Relic unifies APM, infrastructure, logs, browser, and mobile monitoring in a single platform. Correlate frontend performance with backend traces and infrastructure metrics.

NRQL as the Query Language

New Relic Query Language (NRQL) provides SQL-like access to all telemetry data. Master NRQL to build dashboards, alerts, and ad-hoc investigations across any data type.

Entity-Centric Model

Everything in New Relic is an entity (services, hosts, dashboards). Entities have relationships, enabling dependency maps and impact analysis across your architecture.

Setup

Install the Node.js agent:

npm install newrelic

Create newrelic.js in your project root:

'use strict';
exports.config = {
  app_name: [process.env.NEW_RELIC_APP_NAME || 'my-service'],
  license_key: process.env.NEW_RELIC_LICENSE_KEY,
  distributed_tracing: { enabled: true },
  logging: { level: 'info' },
  allow_all_headers: true,
  attributes: {
    exclude: [
      'request.headers.cookie',
      'request.headers.authorization',
    ],
  },
  transaction_tracer: {
    enabled: true,
    transaction_threshold: 'apdex_f',
    record_sql: 'obfuscated',
  },
  error_collector: {
    enabled: true,
    ignore_status_codes: [404],
  },
};

Require the agent as the very first line:

// index.ts - MUST be the first import
import 'newrelic';
import express from 'express';

const app = express();
// ... your app code

For Next.js with the @newrelic/next plugin:

npm install newrelic @newrelic/next
// next.config.js
const nrExternals = require('@newrelic/next');
module.exports = nrExternals({
  experimental: { instrumentationHook: true },
});

Key Patterns

Do: Add custom attributes and transactions for business context

import newrelic from 'newrelic';

app.post('/checkout', async (req, res) => {
  newrelic.addCustomAttributes({
    'cart.itemCount': req.body.items.length,
    'cart.totalAmount': req.body.total,
    'customer.tier': req.user.tier,
  });

  newrelic.setTransactionName('checkout/process');

  const result = await processCheckout(req.body);
  res.json(result);
});

Not: Logging the license key or sending PII as attributes

// WRONG - never log secrets or send PII
newrelic.addCustomAttributes({
  'user.email': user.email,        // PII - don't send
  'api.key': process.env.API_KEY,  // secret - never send
});

Do: Create custom events for business metrics

newrelic.recordCustomEvent('Purchase', {
  orderId: order.id,
  amount: order.total,
  currency: 'USD',
  paymentMethod: order.paymentMethod,
  itemCount: order.items.length,
});

Common Patterns

NRQL Dashboard Queries

-- Request throughput by transaction
SELECT rate(count(*), 1 minute) AS 'RPM'
FROM Transaction
WHERE appName = 'my-service'
FACET name
SINCE 1 hour ago
TIMESERIES AUTO

-- Error rate percentage
SELECT percentage(count(*), WHERE error IS true) AS 'Error %'
FROM Transaction
WHERE appName = 'my-service'
SINCE 1 hour ago
TIMESERIES AUTO

-- p95 response time by endpoint
SELECT percentile(duration, 95) AS 'p95 (s)'
FROM Transaction
WHERE appName = 'my-service'
FACET name
SINCE 1 hour ago

-- Custom event funnel
SELECT funnel(session,
  WHERE pageUrl LIKE '%/products%' AS 'Browse',
  WHERE pageUrl LIKE '%/cart%' AS 'Add to Cart',
  WHERE pageUrl LIKE '%/checkout%' AS 'Checkout'
) FROM PageView SINCE 1 day ago

Alert Conditions via NerdGraph API

mutation {
  alertsNrqlConditionStaticCreate(
    accountId: 1234567
    policyId: "9876543"
    condition: {
      name: "High Error Rate"
      enabled: true
      nrql: {
        query: "SELECT percentage(count(*), WHERE error IS true) FROM Transaction WHERE appName = 'my-service'"
      }
      signal: {
        aggregationWindow: 60
        aggregationMethod: EVENT_FLOW
        aggregationDelay: 120
      }
      terms: [{
        threshold: 5
        thresholdOccurrences: ALL
        thresholdDuration: 300
        operator: ABOVE
        priority: CRITICAL
      }]
      violationTimeLimitSeconds: 86400
    }
  ) {
    id
    name
  }
}

Distributed Tracing Custom Spans

newrelic.startSegment('external-payment-call', true, async () => {
  const response = await fetch('https://payments.example.com/charge', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      ...newrelic.getTraceMetadata(),
    },
    body: JSON.stringify(chargeData),
  });
  return response.json();
});

Anti-Patterns

  • Ignoring ignore_status_codes - 404s inflate error rates; configure the agent to ignore expected HTTP errors.
  • High-cardinality custom attributes - Avoid unique IDs in attributes used in FACET queries; they slow NrDB and hit data limits.
  • Not using TIMESERIES - Dashboard charts without TIMESERIES show a single aggregate; always include it for time-based panels.
  • Skipping distributed tracing - Without distributed_tracing.enabled: true, cross-service traces are invisible; enable it on every agent.

When to Use

  • You want a managed SaaS observability platform without running Prometheus or Grafana yourself.
  • You need APM with automatic instrumentation for Node.js, Java, Python, .NET, Ruby, Go, or PHP.
  • You are building NRQL-powered dashboards for business KPIs alongside technical metrics.
  • You need browser and mobile monitoring correlated with backend APM data.
  • You want built-in anomaly detection and AI-powered alert conditions.

Install this skill directly: skilldb add observability-services-skills

Get CLI access →