Search code examples
javaspring-bootcloud-foundrynewrelicbuildpack

Override NewRelic config file used by Cloud Foundry java build pack


I have a Spring Boot application deployed in Cloud Foundry, using the standard Java build pack. Since the app is bound to NewRelic, the build pack injects a NewRelic agent into the environment.

NewRelic documentation talks about adding a newrelic.yml file next to the agent jar location to customize instrumentation behavior. In the CF scenario, can it be located in the classpath of the deployed Spring Boot jar? How do I enable this behavior?


Solution

  • In the CF scenario, can it be located in the classpath of the deployed Spring Boot jar? How do I enable this behavior?

    I don't know about that, but two things you can do:

    1. Specify additional configuration options for the NewRelic agent through your bound user provided service.

      https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-new_relic_agent.md#user-provided-service-optional

      (Optional) Any additional entries will be applied as a system property appended to -Dnewrelic.config. to allow full configuration of the agent.

    2. If you were to fork the Java build pack, you could overlay your own configuration file.

      https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-new_relic_agent.md#additional-resources

      Your custom file would go here: https://github.com/cloudfoundry/java-buildpack/blob/master/resources/new_relic_agent/newrelic.yml

    You probably don't want to fork the build pack though as that creates a whole mess of other problems.

    I guess a third option might be to use a .profile.d script, but that's a pain with Java apps because you have to put the files at the root of your JAR file. It could work though.

    https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile

    Hope that helps!