diff --git a/instrumentation/kamon-akka-http/src/main/scala/kamon/instrumentation/akka/http/VersionFiltering.scala b/instrumentation/kamon-akka-http/src/main/scala/kamon/instrumentation/akka/http/VersionFiltering.scala index db4a8be10..99863f72e 100644 --- a/instrumentation/kamon-akka-http/src/main/scala/kamon/instrumentation/akka/http/VersionFiltering.scala +++ b/instrumentation/kamon-akka-http/src/main/scala/kamon/instrumentation/akka/http/VersionFiltering.scala @@ -2,7 +2,17 @@ package kamon.instrumentation.akka.http trait VersionFiltering { def onAkkaHttp(version: String)(block: => Unit): Unit = { - if(akka.http.Version.current.startsWith(version)) + val akkaHttpVersion = getVersion + + if (akkaHttpVersion.exists(_.startsWith(version))) block } + + private def getVersion: Option[String] = { + try { + Option(akka.http.Version.current) + } catch { + case _: Throwable => None + } + } }