• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The New Relic Java agent

New Relic Open Source community plus project banner.

newrelic-java-agent

With New Relic's Java agent for bytecode instrumentation, you can track everything from performance issues to tiny errors within your code. Our Java agent monitors your Java app and provides visibility into the behavior of your JVM. After installing, you can quickly monitor transactions, dive deep into errors, and more.

Java agent releases follow semantic versioning conventions. See Java agent release notes for full details on releases and downloads. Java agent artifacts can also be found on Maven.

Installation

To install the Java agent you need to configure your JVM to load the agent during your application's premain start-up by passing the -javaagent:/full/path/to/newrelic.jar command-line argument. This process varies depending on your environment/application server.

For full details see:

Getting started

See the getting started guide as well as the compatibility and requirements documentation for an overview of what is supported by the Java agent.

Usage

See the following documentation for specific use cases of the Java agent:

Building

JDK requirements

The Java agent uses a variety of JDK versions when building and running tests. These need to be installed and configured for your environment.

Edit or create the ~/.gradle/gradle.properties file and add the following JDKs, ensuring that the vendors/versions match what is installed in your environment (Mac OS X examples shown).

JDK 8 is required to build the agent:

jdk8=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

Additionally, the -PtestN Gradle property can be used to run tests on a specific JDK version which may require further JDK configuration. To keep test times reasonable the project only allows testing against supported LTS Java releases as well as the latest non-LTS release of Java. For example to run tests with Java 17, the -Ptest17 Gradle property would cause the test to use jdk17 as configured below:

jdk17=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home

Gradle build

The Java agent requires JDK 8 to build; your JAVA_HOME must be set to this JDK version.

To build the agent jar, run the following command from the project root directory:
./gradlew clean jar --parallel

To build and run all checks:
./gradlew clean build --parallel

After building, Java agent artifacts are located here:

  • Agent: newrelic-agent/build/newrelicJar/newrelic.jar
  • Agent API: newrelic-api/build/libs/newrelic-api-*.jar

IntelliJ IDEA setup

We recommend using IntelliJ IDEA for development on this project. Configure as follows:

  1. Select File > Open and select newrelic-java-agent/build.gradle.
  2. Select Open as Project.
  3. Wait for the builds, imports, and indexing to finish. This may take a few minutes due to the project's size and complexity.
  4. Import Code Style: from dev-tools/code-style/java-agent-code-style.xml, select Preferences > Editor > Code Style > gear cog > Import Scheme > IntelliJ IDEA code style XML.
  5. Add Java 8 SDK: select File > Project Structure... > Platform Settings > SDKs > Add New SDK.
  6. Configure project SDK and target language level: select File > Project Structure... > Project Settings > Project.
    • Set Project SDK to JDK 1.8
    • Set Project language level to 8 IntelliJ screen shot for Project SDK and Language Level
  7. Increase Intellij memory heap if you encounter "Low Memory" issues. Recommended: 2048 MB. To do this, select Help > Change Memory Settings > Save and Restart.

Testing

The Java agent utilizes the following four distinct test suites, each of which is supported by a test framework. Each has specific strengths and weaknesses and each serves a particular purpose.

Conventional unit tests

The unit tests are conventional JUnit tests. The supporting framework is the industry-standard JUnit dependency. Unit tests rely on a variety of different mock object frameworks combined with complex test initialization patterns that simulate agent initialization. Scala test tasks are excluded by default. Including the -PincludeScala project property includes Scala test tasks.

Run all unit tests:

./gradlew -PnoInstrumentation clean test --continue --parallel

Run an individual unit test:

./gradlew -PnoInstrumentation clean newrelic-weaver:test --tests "com.newrelic.weave.LineNumberWeaveTest.testRemoveWeaveLineNumbers" --parallel

Run an individual unit test on a specific version of Java:

./gradlew -Ptest17 -PnoInstrumentation clean newrelic-weaver:test --tests "com.newrelic.weave.LineNumberWeaveTest.testRemoveWeaveLineNumbers" --parallel

Functional tests

The functional tests are JUnit tests for which Gradle ensures that each test class runs in a separate subprocess that initializes the agent. The test framework is a combination of industry-standard JUnit, Gradle, a small Gradle test executor task, and some special classes that address limitations of the base framework.

Note: Functional tests require that the Java agent jar artifact is present in the build directory.

Functional tests are located in newrelic-java-agent/functional_test/src/test/ and are run from the root newrelic-java-agent directory as follows:

Run all functional tests:

./gradlew functional_test:test --continue --parallel

Run an individual functional test:

./gradlew functional_test:test --tests test.newrelic.test.agent.AgentTest --parallel

Instrumentation module tests

The instrumentation module tests are also JUnit tests. The framework is the industry-standard JUnit dependency modified by a custom test runner and class loader that support bytecode weaving within the test without the need to fully initialize the agent. Note: fully initializing the agent is not possible when running in an uninstrumented reusable test process like an IntelliJ test subprocess or Gradle daemon. There is also an "introspector" (somewhat equivalent to a local mock collector) for test assertions.

Some of the instrumentation tests use Testcontainers so you might need to have Docker installed to run them locally.

Instrumentation tests are located in each instrumentation module at newrelic-java-agent/instrumentation/<INSTRUMENTATION MODULE>/src/test and are run from the root newrelic-java-agent directory as follows:

Run all instrumentation module tests:

./gradlew instrumentation:test --continue --parallel

Run all tests for a specific instrumentation module:

./gradlew instrumentation:akka-http-core-10.0.11:test --parallel

Run a single test for a specific instrumentation module:

./gradlew instrumentation:vertx-web-3.2.0:test --tests com.nr.vertx.instrumentation.RoutingTest --parallel

Run all tests for a specific Scala instrumentation module:

./gradlew -PincludeScala instrumentation:sttp-2.13_2.2.3:test --parallel

Code Quality

The agent utilizes Jacoco and Spotbugs to measure and improve code quality. We also use Codecov to report code coverage. Jacoco and Spotbug tools are configured through the gradle build system. Codecov is configured and uploaded through a GitHub Actions workflow.

Jacoco

The jacocoTestReport task depends on the unit test task. It uses data generated by the test task to create the coverage reports. jacocoTestReport task creates an html and xml file of the output. We store these files locally in the respective module's build/reports/jacoco folder. The html file can be opened normally in a browser. Some subprojects have not been configured to run because the code is either too trivial to test or it is code that is only compile time dependency and not necessary to test due to the nature of how the agent instruments customer code.

To run jacoco, execute unit tests in the usual ways given under the section Convential unit tests. The jacocoTestReport task will run automatically after the unit tests complete.

Codecov

We use a codecov github action to upload the jacoco coverage reports to codecov.io. Additionally, codecov will comment on pull requests (PRs) with a quick overview of how PRs (and relevant commits) will affect the code coverage as compared to the main branch.

Spotbugs

Spotbugs is a static code analysis tool to identify bugs in Java programs. It utilizes the Spotbugs gradle plugin. The projects that are scanned by Spotbugs are:

  • newrelic-agent
  • newrelic-weaver
  • agent-bridge
  • agent-model
  • newrelic-api

To run Spotbugs, execute the following command:

./gradlew spotbugsMain --parallel

The task will generate both XML and HTML files in the build/spotbugs folder underneath each subproject's top level folder. The HTML file can be opened normally in a browser. The XML files can be imported into the Spotbugs UI.

Support

Should you need assistance with New Relic products, you are in good hands with several diagnostic tools and support channels.

This troubleshooting framework steps you through common troubleshooting questions.

New Relic offers NRDiag, a client-side diagnostic utility that automatically detects common problems with New Relic agents. If NRDiag detects a problem, it suggests troubleshooting steps. NRDiag can also automatically attach troubleshooting data to a New Relic Support ticket.

If the issue has been confirmed as a bug or is a Feature request, please file a Github issue.

Support Channels

Privacy

At New Relic we take your privacy and the security of your information seriously, and are committed to protecting your information. We must emphasize the importance of not sharing personal data in public forums, and ask all users to scrub logs and diagnostic information for sensitive information, whether personal, proprietary, or otherwise.

We define β€œPersonal Data” as any information relating to an identified or identifiable individual, including, for example, your name, phone number, post code or zip code, Device ID, IP address and email address.

Please review New Relic’s General Data Privacy Notice for more information.

Contribute

We encourage your contributions to improve newrelic-java-agent. Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.

If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].

A note about vulnerabilities

As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.

License

newrelic-java-agent is licensed under the Apache 2.0 License.

The newrelic-java-agent also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document and our Java agent licenses public documentation.

More Repositories

1

centurion

A mass deployment tool for Docker fleets
Ruby
1,744
star
2

newrelic-ruby-agent

New Relic RPM Ruby Agent
Ruby
1,180
star
3

node-newrelic

New Relic Node.js agent code base. Developers are welcome to create pull requests here, please see our contributing guidelines. For New Relic technical support, please go to http://support.newrelic.com.
JavaScript
927
star
4

go-agent

New Relic Go Agent
Go
719
star
5

rusty-hog

A suite of secret scanners built in Rust for performance. Based on TruffleHog (https://github.com/dxa4481/truffleHog) which is written in Python.
Rust
447
star
6

sidecar

Gossip-based service discovery. Docker native, but supports static discovery, too.
Go
259
star
7

elixir_agent

New Relic's Open Source Elixir Agent
Elixir
253
star
8

terraform-provider-newrelic

Terraform provider for New Relic
Go
201
star
9

rpm_contrib

Extra Instrumentation for the New Relic RPM Gem
192
star
10

docs-website

Source code for @newrelic docs. We welcome pull requests and questions on our docs!
MDX
170
star
11

newrelic-python-agent

New Relic Python Agent
Python
156
star
12

newrelic_aws_cloudwatch_plugin

New Relic AWS Cloudwatch Plugin
Ruby
154
star
13

newrelic-cli

The New Relic Command Line Interface
Go
128
star
14

check_docker

A Go Nagios check for Docker
Go
126
star
15

newrelic_api

Documentation, Active Resource Helper, and test code for the RPM REST API
Ruby
119
star
16

newrelic-quickstarts

New Relic One quickstarts help accelerate your New Relic journey by providing immediate value for your specific use cases.
TypeScript
109
star
17

nri-flex

An application-agnostic, all-in-one New Relic integration integration
Go
107
star
18

opensource-website

Source code for New Relic's Opensource site.
JavaScript
105
star
19

newrelic-opentelemetry-examples

Examples for sending OpenTelemetry sourced data to New Relic.
Java
103
star
20

newrelic-php-agent

The New Relic PHP Agent
C
103
star
21

infrastructure-agent

New Relic Infrastructure Agent
Go
102
star
22

helm-charts

Helm charts for New Relic applications
Smarty
95
star
23

infrastructure-agent-ansible

Ansible role for installing New Relic Infrastructure agent
Python
95
star
24

nr1-workshop

Self-paced training workshop for the NR1 CLI/SDK
JavaScript
85
star
25

newrelic_mysql_java_plugin

MySQL Metrics Plugin
Java
79
star
26

newrelic-browser-agent

New Relic Browser Agent
HTML
75
star
27

newrelic-lambda-extension

An AWS Lambda Extension to collect, enhance and transport telemetry to New Relic for AWS Lambda functions without requiring an external transport such as CloudWatch Logs or Kinesis.
Go
74
star
28

newrelic-dotnet-agent

The New Relic .NET language agent.
C#
74
star
29

newrelic-node-nextjs

New Relic Next.js instrumentation for the Node Agent
JavaScript
73
star
30

newrelic-client-go

New Relic Client for the Go programming language
Go
68
star
31

entity-definitions

The definition files contained in this repository are mappings between the telemetry attributes NewRelic ingests, and the entities users can interact with. If you have telemetry from any source that is not supported out of the box, you can propose a mapping for it by opening a PR.
JavaScript
67
star
32

node-native-metrics

Optional native module for collecting low-level Node & V8 metrics
C++
58
star
33

k8s-webhook-cert-manager

Generate certificate suitable for use with any Kubernetes Mutating Webhook.
Shell
58
star
34

c-sdk

New Relic C SDK
C
57
star
35

serverless-newrelic-lambda-layers

A Serverless plugin to install New Relic's AWS Lambda layers without requiring a code change.
TypeScript
55
star
36

newrelic-node-apollo-server-plugin

JavaScript
53
star
37

deployment-marker-action

Github Action for recording a Deployment Marker in New Relic
Shell
50
star
38

aws-log-ingestion

AWS Serverless Application that sends log data from CloudWatch Logs to New Relic Infrastructure - Cloud Integrations.
Python
50
star
39

absinthe-schema-stitching-example

Absinthe Schema Stitching Example
Elixir
49
star
40

nr1-cloud-optimize

NR1 Cloud Optimize allows you to Identify right-sizing opportunities and potential savings of your AWS, GCP, and Azure instances across your cloud environment.
JavaScript
48
star
41

newrelic-lambda-cli

A CLI to install the New Relic AWS Lambda integration and layers.
Python
47
star
42

infra-integrations-sdk

New Relic Infrastructure Integrations SDK
Go
45
star
43

go_nagios

Go lang package for writing Nagios checks
Go
43
star
44

newrelic-kubernetes-operator

Operator to create New Relic configuration in Kubernetes
Go
42
star
45

dPerf

Distributed Mobile CPU Profiling
Objective-C
41
star
46

newrelic-telemetry-sdk-go

Go library for sending telemetry data to New Relic
Go
40
star
47

newrelic-diagnostics-cli

NrDiag is a command line diagnostics tool for New Relic Products that was created by and is maintained by New Relic Global Technical Support
Go
39
star
48

developer-website

Source code for the New Relic Developer Site.
MDX
39
star
49

newrelic-telemetry-sdk-java

Java library for sending telemetry data to New Relic
Java
39
star
50

el-dorado-ui

Graph db query and rendering suitable for visualization of complex process structures
Ruby
37
star
51

newrelic-ruby-kata

Using New Relic and Heroku, see how many things you can find and fix to make this app perform fast!
Ruby
35
star
52

micrometer-registry-newrelic

ARCHIVED. TO SEND MICROMETER METRICS TO NEW RELIC, FOLLOW THE DIRECTION IN THE README.md. Micrometer registry implementation that sends data to New Relic as dimensional metrics.
Java
35
star
53

newrelic-lambda-layers

Source code and utilities to build and publish New Relic's public AWS Lambda layers.
Shell
34
star
54

newrelic_microsoft_sqlserver_plugin

New Relic Microsoft SQL Server Plugin
C#
33
star
55

nri-prometheus

Fetch metrics in the Prometheus metrics inside or outside Kubernetes and send them to the New Relic Metrics platform.
Go
33
star
56

nr1-status-pages

NR1 Status Pages allows you to collect and display the statuses of key dependencies in one place.
JavaScript
33
star
57

nr-openai-observability

Easy to install OpenAI GPT monitoring tool.
Python
33
star
58

nri-kubernetes

New Relic integration for Kubernetes
Go
33
star
59

papers

Validates licenses of your Rails dependencies against a whitelist
Ruby
31
star
60

opentelemetry-exporter-go

New Relic's Golang OpenTelemetry Exporter
Go
30
star
61

newrelic-jfr-core

JFR library that adapts JFR events to the New Relic Telemetry SDK
Java
30
star
62

tutone

Generate Golang code from GraphQL schema introspection
Go
30
star
63

extends_newrelic_rpm

Gems that extend New Relic's Ruby agent (newrelic_rpm), linked via git submodules
Ruby
29
star
64

newrelic_plugin

New Relic Ruby Plugin Agent SDK
Ruby
29
star
65

newrelic-telemetry-sdk-python

A python library to send data to New Relic!
Python
29
star
66

infrastructure-agent-chef

Chef cookbook for installing New Relic Infrastructure agent
Ruby
28
star
67

nrjmx

Command line tool to connect to a JMX server and retrieve the MBeans it exposes.
Java
28
star
68

fluentd-examples

Sample FluentD configs
27
star
69

newrelic-fluent-bit-output

A Fluent Bit output plugin that sends logs to New Relic
Go
26
star
70

dkenv

A docker version switcher
Go
26
star
71

newrelic-unix-monitor

Monitoring service for Unix (AIX, Linux, HP-UX, MacOS, Solaris) systems
Java
26
star
72

marlowe

Experimental project for investigating interesting visualizations of APM data
JavaScript
25
star
73

wiki-sync-action

A GitHub Action that synchronizes the contents of a directory to the repository's Wiki.
Shell
25
star
74

futurestack14_badge

Source code for the badges from New Relic's FutureStack 2014 conference
Squirrel
24
star
75

nr-jenkins-plugin

Jenkins Plugin to send metrics to New Relic
Java
24
star
76

newrelic-telemetry-sdk-rust

Rust library for sending telemetry data to New Relic
Rust
23
star
77

quickstarts-synthetics-library

Repositories containing example/templated synthetic scripts for use in New Relic.
JavaScript
23
star
78

k8s-metadata-injection

Kubernetes metadata injection for New Relic APM to make a linkage between APM and Infrastructure data.
Go
23
star
79

newrelic-monolog-logenricher-php

Monolog components to enable New Relic Logs
PHP
22
star
80

agent_sdk_samples

Sample wrappers and code for the New Relic Agent SDK
C
22
star
81

nr1-learn-nrql

NR1 learn NRQL helps New Relic Customers quickly learn our custom query language - NRQL
JavaScript
21
star
82

nri-nginx

New Relic Infrastructure Nginx Integration
Go
21
star
83

nr1-slo-r

NR1 SLO-R allows you to define, calculate and report on service-level objective (SLO) attainment.
JavaScript
21
star
84

newrelic-airflow-plugin

Send airflow metrics to New Relic!
Python
20
star
85

newrelic-python-kata

Newrelic Python Kata
Python
20
star
86

newrelic_plugins_chef

Ruby
20
star
87

metrics_publish_java

New Relic Java Plugin Agent SDK
Java
20
star
88

newrelic-node-log-extensions

Source for the New Relic Node.js log framework extensions
JavaScript
20
star
89

newrelic-cordova-plugin

A Cordova plugin for the New Relic Mobile SDKs
JavaScript
19
star
90

newrelic-logenricher-dotnet

Extensions supporting New Relic Logging (Logs In Context)
C#
19
star
91

infrastructure-bundle

New Relic Infrastructure containerised agent bundle
Go
19
star
92

newrelic-cordova-ios

A PhoneGap / Cordova plugin for New Relic's iOS SDK
Objective-C
19
star
93

open-install-library

New Relic's open instrumentation installation recipe database and service
Shell
19
star
94

gatsby-theme-newrelic

Source code for New Relic's Gatsby site theme.
JavaScript
19
star
95

nr1-browser-analyzer

NR1 Browser Analyzer allows you to understand the impact and performance of your website.
JavaScript
18
star
96

nr1-quickstarts

[ARCHIVED] Community repository of New Relic dashboards, alerts, and installation instructions.
JavaScript
18
star
97

supervisor-remote-logging

Use supervisord to relay your application's stdout/stderr to syslog.
Python
18
star
98

webinar

Contains the sample code for the "Best Practices for Measuring Your Code Pipeline" webinar
18
star
99

video-agent-roku

New Relic Agent for Roku
Brightscript
16
star
100

ruby-metaprogramming-challenge

A fun metaprogramming challenge created at New Relic
Ruby
16
star