The guided instrucions for new relic with spring-boot tell you to:
Unfortunately, this does not work. We put our modified newrelic.yml into our src/main/resources/newrelic/newrelic.yml as instructed.
When we build and run the app, maven dowloads not only the jar file, it also downloads another copy of the newrelic.yml without any licence key. It puts the jar and the yml file into target/newrelic/ The problem is that when we start newrelic, it always picks up the yml file downloaded into target/newrelic.
If we edited this file, it would get lost when we do clean, and also other developers would have to manually edit the file.
How is it supposed to work?
Note, they dont give any guiance on where we are supposed to find the /full/path/to in the command line, so we guessed it should be this:
java -javaagent:C:\Users\me\dev\myproject\mymodule\target\newrelic\newrelic.jar -jar app.jar
This starts up, but gets the wrong yml config file.
We cant put the jar somewhere like /opt as we dont have access to the target servers file system directly we just deploy our self contained app.
We dont have any jars in our app - its all build using maven, which produces our single application jar which gets deployed.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>unpack-newrelic</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.newrelic.agent.java</includeGroupIds>
<includeArtifactIds>newrelic-java</includeArtifactIds>
<!-- you can optionally exclude files -->
<!-- <excludes>**/newrelic.yml</excludes> -->
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
:
<dependency>
<groupId>com.newrelic.agent.java</groupId>
<artifactId>newrelic-java</artifactId>
<version>8.12.0</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
By default, the New Relic Java agent will read the config file in the same folder the agent is in.
That file contains only agent default configurations. So to work around that you could:
newrelic.config.file
. eg: java -Dnewrelic.config.file=path/to/newrelic.yml ...
java -Dnewrelic.config.license_key=MY_KEY ...