diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/language/SourceLibraryDetector.java b/newrelic-agent/src/main/java/com/newrelic/agent/language/SourceLibraryDetector.java index e90a1bd640..248ebd1cf8 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/language/SourceLibraryDetector.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/language/SourceLibraryDetector.java @@ -59,6 +59,7 @@ public boolean isDone() { void detectSourceLanguages() { ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); detectJava(); + detectScala3(systemClassLoader); detectScala(systemClassLoader); detectKotlin(systemClassLoader); detectClojure(systemClassLoader); @@ -89,9 +90,25 @@ private void detectJava() { } } + private void detectScala3(ClassLoader systemClassLoader) { + try { + //scala3-library removed all methods referencing the version 3 number, so we only capture the major version + //by checking for a class introduced in the scala 3 API. + Class aClass = Class.forName("scala.deriving.Mirror", true, systemClassLoader); + if (aClass != null) { + recordSourceLanguageMetric("scala", "3.x"); + } + } catch (ClassNotFoundException cnfe){ + Agent.LOG.log(Level.FINEST, format("Class ''{0}'' was not found; scala3 is not present in the classpath", "scala.deriving.Mirror")); + } catch (Exception e) { + Agent.LOG.log(Level.FINEST, format("Exception occurred while trying to determine scala3 version", e.getMessage())); + } + } + private void detectScala(ClassLoader systemClassLoader) { try { - // Scala has a static versionNumberString method that can be invoked to get the version number + // Scala has a static versionNumberString method that can be invoked to get the version number. + // A scala 3 app will also capture this metric, because scala 3 includes the scala 2.13 library. Class aClass = Class.forName(SCALA_VERSION_CLASS, true, systemClassLoader); if (aClass != null) { String version = (String) aClass.getMethod(SCALA_VERSION_METHOD).invoke(null);