Scala installation for Java

These directions for Scala supplement New Relic's Java installation directions:

Compiling classes and methods

The New Relic Java agent instruments JVM bytecode rather than source code. Since Scala code compiles down to classes and methods, our agent will work fine with Scala code. However, in order to instrument properly you may need to understand how your code gets represented as bytecode classes and methods, especially when using a custom instrumentation file.

If the frameworks you use are not natively supported by New Relic, custom instrumentation is a great way to dig deeper into your application. Even with Scala code, New Relic API calls, annotations and custom instrumentation files are available. However, your class names may look different than you expect, particularly when anonymous functions are involved.

Tip: Printing this.getClass().getName() or using the javap command are helpful ways to figure out how Scala compiles your classes.

Once you have your Traces in place, you can also use the API to provide other details, such as naming your transaction, noticing errors, instrumenting page load timing (sometimes referred to as real user monitoring or RUM) in your HTML, and more.

Using the New Relic API

To use the New Relic API class or annotations, add this line (replacing x.x with the correct version) to the appDependencies method in your application's project/Build.scala file:

"" % "newrelic-api" % "3.x.x"

Or add the following line to your application's project/build.sbt file:

libraryDependencies += "" % "newrelic-api" % "3.x.x"

Then you can import the NewRelic class and use it in your application:

import com.newrelic.api.agent.NewRelic
NewRelic.setTransactionName(null, "/myTransaction");

Here is an example of how to record the response time for this method:

import com.newrelic.api.agent.Trace
def intensiveComputation = {

Note: Annotations work for Scala methods, but they may not persist for functions. This is because functions are compiled as a separate class and method. Since the Scala compiler can generate classes and methods, you may need to experiment with the combination of annotations and custom xml to find what works for you.

Through the API, you can also get your transaction to show up as a web transaction. This is especially helpful if you are using a framework that is not yet supported by New Relic.

For more help

Recommendations for learning more: