SDKs overview
New Relic provides a suite of Software Development Kits (SDKs) and libraries designed to facilitate interaction with its observability platform. These tools enable developers to instrument applications, collect performance data, query metrics, and manage New Relic configurations programmatically. The SDKs abstract the underlying API complexities, allowing for more straightforward integration of monitoring capabilities into various software projects. Official SDKs are maintained by New Relic, offering comprehensive support for popular programming languages and frameworks. Community-contributed libraries also exist, extending functionality or providing alternative integration methods.
The primary function of these SDKs is to simplify the process of sending data to New Relic's platform, whether it's application performance metrics, infrastructure logs, browser interaction data, or mobile app analytics. They also provide interfaces for retrieving and analyzing this data, supporting use cases from automated alerting to custom dashboard creation. For a general overview of the New Relic API capabilities, refer to the New Relic API introduction.
Official SDKs by language
New Relic maintains official SDKs, often referred to as 'agents,' for a range of programming languages. These agents are designed to automatically collect performance data from applications and services, minimizing manual instrumentation efforts. Each agent is tailored to its respective language ecosystem, integrating with common frameworks and libraries to provide detailed insights into application behavior. The official documentation provides specific details for each agent, including supported versions and configuration options.
| Language | Package Name / Agent | Installation Command Example | Maturity / Support |
|---|---|---|---|
| Java | New Relic Java Agent | java -javaagent:/path/to/newrelic.jar -jar myapp.jar |
Fully supported, regularly updated |
| Node.js | newrelic |
npm install newrelic --save |
Fully supported, regularly updated |
| Python | newrelic |
pip install newrelic |
Fully supported, regularly updated |
| .NET | New Relic .NET Agent | Download and install via MSI/package | Fully supported, regularly updated |
| PHP | New Relic PHP Agent | Install via PECL or package manager | Fully supported, regularly updated |
| Ruby | newrelic_rpm |
gem install newrelic_rpm |
Fully supported, regularly updated |
| Go | github.com/newrelic/go-agent |
go get github.com/newrelic/go-agent |
Fully supported, regularly updated |
Installation
The installation process for New Relic SDKs, or agents, varies by language and environment. Generally, it involves adding the agent as a dependency to your project or installing it as a system-level component. Configuration typically requires setting your New Relic license key and application name, often through environment variables or a configuration file.
Java Agent Installation
For Java applications, the New Relic agent is installed by placing the newrelic.jar file in a known location and then adding a -javaagent argument to your Java Virtual Machine (JVM) startup command. This allows the agent to instrument your application at runtime. Detailed instructions are available in the New Relic Java agent installation guide.
java -javaagent:/path/to/newrelic.jar -Dnewrelic.environment=production -jar myapp.jar
Node.js Agent Installation
The Node.js agent is typically installed as an npm package. After installation, you must require the newrelic module as the very first line of your application's main file. Configuration is managed via a newrelic.js file or environment variables. Consult the New Relic Node.js agent installation documentation for complete steps.
npm install newrelic --save
// In your main application file (e.g., app.js)
require('newrelic');
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello New Relic!');
});
app.listen(3000, () => {
console.log('App listening on port 3000');
});
Python Agent Installation
The Python agent is installed using pip. After installation, you typically use a wrapper script or modify your application's entry point to initialize the agent. Configuration is often handled through a newrelic.ini file or environment variables. The New Relic Python agent installation instructions provide further details.
pip install newrelic
# Example: Using the newrelic-admin wrapper
# newrelic-admin run-program gunicorn myapp:app
# Example: Manual initialization (requires newrelic.ini)
import newrelic.agent
newrelic.agent.initialize('/path/to/newrelic.ini', 'production')
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, New Relic!'
if __name__ == '__main__':
app.run()
Quickstart example
This quickstart example demonstrates how to integrate the New Relic Node.js agent into a simple Express.js application. This setup will begin sending basic performance metrics to your New Relic account, allowing you to monitor response times, throughput, and error rates.
- Create a new Node.js project:
mkdir newrelic-express-app cd newrelic-express-app npm init -y npm install express - Install the New Relic Node.js agent:
npm install newrelic --save - Create a New Relic configuration file (
newrelic.js):
Populate this file with your New Relic license key and the desired application name. You can find your license key in your New Relic account settings./** * New Relic agent configuration. * * See lib/config.defaults.js in the agent distribution for a more complete * description of configuration variables and their potential values. */ exports.config = { /** * Array of application names. New Relic uses the first name to link your * application's data to a specific application in the New Relic UI. * The other names are used for cross-application linking. */ app_name: ['My Node.js App'], /** * Your New Relic license key. All transactions that your application * sends to New Relic are associated with this license key. */ license_key: 'YOUR_NEW_RELIC_LICENSE_KEY', logging: { /** * Level at which to log. 'trace' is most useful for debugging, * but can produce a lot of output. 'info' is a good balance. */ level: 'info' }, /** * When true, all request headers except for those listed in * attributes.exclude will be captured. These can be viewed in Traces * and Errors and Defects events. */ allow_all_request_headers: true, attributes: { /** * Prefix of attributes to exclude from all destinations. * Allows for control over data security and privacy. */ exclude: [ 'request.headers.cookie', 'request.headers.authorization', 'request.headers.proxyAuthorization', 'request.headers.setCookie', 'request.headers.xForwardedFor' ] } }; - Create your application file (
app.js): Ensurerequire('newrelic');is the very first line.require('newrelic'); // Must be the first line const express = require('express'); const app = express(); const port = 3000; app.get('/', (req, res) => { res.send('Hello from New Relic monitored app!'); }); app.listen(port, () => { console.log(`App listening at http://localhost:${port}`); }); - Run your application:
node app.js
After running your application for a few minutes, data should begin appearing in your New Relic account under the application name 'My Node.js App'. You can then explore your application's performance metrics, transaction traces, and error details in the New Relic UI.
Community libraries
Beyond the official agents, the New Relic ecosystem benefits from community-contributed libraries and integrations. These often provide support for niche frameworks, specific data sources, or custom reporting needs not covered by the official offerings. While New Relic does not officially support these, they can be valuable resources for developers seeking extended functionality.
Examples of community contributions might include:
- Custom metric reporters: Libraries that simplify sending custom metrics from applications or scripts that don't fit the standard APM agent model.
- Integrations with less common databases or message queues: Community-driven instrumentation for technologies that might not have first-party agent support.
- CLI tools for API interaction: Command-line interfaces built on top of New Relic's REST APIs for scripting management tasks.
Developers can often find these community projects on platforms like GitHub by searching for newrelic alongside their specific technology or use case. It is important to review the project's documentation, activity, and community support before relying on a third-party library. The open-source software development model encourages such contributions and peer review.