diff --git a/build.sbt b/build.sbt index ac33e64f9..8f7045aea 100644 --- a/build.sbt +++ b/build.sbt @@ -339,9 +339,11 @@ lazy val `kamon-annotation` = (project in file("instrumentation/kamon-annotation assemblyShadeRules in assembly := Seq( ShadeRule.rename("javax.el.**" -> "kamon.lib.@0").inAll, ShadeRule.rename("com.sun.el.**" -> "kamon.lib.@0").inAll, + ShadeRule.rename("com.github.ben-manes.**" -> "kamon.lib.@0").inAll, ), libraryDependencies ++= Seq( kanelaAgent % "provided", + "com.github.ben-manes.caffeine" % "caffeine" % "2.8.5" % "provided,shaded", // provided? no? "org.glassfish" % "javax.el" % "3.0.1-b11" % "provided,shaded", scalatest % "test", logbackClassic % "test", @@ -637,4 +639,4 @@ val `kamon-bundle` = (project in file("bundle/kamon-bundle")) `kamon-akka-http` % "shaded", `kamon-play` % "shaded", `kamon-okhttp` % "shaded", - ) \ No newline at end of file + ) diff --git a/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java b/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java index 66d273ec8..668ff4e4a 100644 --- a/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java +++ b/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java @@ -16,6 +16,8 @@ package kamon.annotation.instrumentation.cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.RemovalListener; import kamon.Kamon; import kamon.annotation.api.Time; import kamon.annotation.api.TrackConcurrency; @@ -24,9 +26,6 @@ import kamon.metric.*; import kamon.tag.TagSet; import kamon.trace.SpanBuilder; -import kanela.agent.libs.net.jodah.expiringmap.ExpirationListener; -import kanela.agent.libs.net.jodah.expiringmap.ExpirationPolicy; -import kanela.agent.libs.net.jodah.expiringmap.ExpiringMap; import kanela.agent.util.log.Logger; import java.lang.reflect.Method; @@ -34,6 +33,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; public final class AnnotationCache { @@ -41,12 +41,11 @@ public final class AnnotationCache { private static Map metrics = buildCache(); private static Map buildCache() { - return ExpiringMap - .builder() - .expiration(1, TimeUnit.MINUTES) - .expirationPolicy(ExpirationPolicy.ACCESSED) - .asyncExpirationListener(ExpirationListener()) - .build(); + return Caffeine.newBuilder() + .expireAfterAccess(1, TimeUnit.MINUTES) + .removalListener(LogExpirationListener()) + .build() + .asMap(); } public static Gauge getGauge(Method method, Object obj, Class clazz, String className, String methodName) { @@ -193,8 +192,8 @@ private static String getOperationName(String name, Object obj, Class clazz, return (evaluatedString.isEmpty() || evaluatedString.equals("unknown")) ? className + "." + methodName: evaluatedString; } - private static ExpirationListener ExpirationListener() { - return (key, value) -> { + private static RemovalListener LogExpirationListener() { + return (key, value, cause) -> { if(value instanceof Instrument) ((Instrument) value).remove(); Logger.debug(() -> "Expiring key: " + key + "with value" + value); };