Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Commit

Permalink
fix the FastFuture instrumentation for Scala 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantopo committed Jul 17, 2019
1 parent 2b737eb commit c65e89f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
@@ -1,9 +1,12 @@
language: scala
script:
- sbt +test
scala:
- 2.12.6
- 2.12.8
jdk:
- oraclejdk8
- openjdk8
before_script:
- mkdir $TRAVIS_BUILD_DIR/tmp
- export SBT_OPTS="-Djava.io.tmpdir=$TRAVIS_BUILD_DIR/tmp"
sudo: false

2 changes: 1 addition & 1 deletion kamon-akka-http/src/main/resources/reference.conf
Expand Up @@ -239,7 +239,7 @@ kanela.modules {
]

within = [
".*"
"akka.http.*"
]
}
}
Expand Up @@ -18,7 +18,7 @@ import kanela.agent.api.instrumentation.InstrumentationBuilder
import kanela.agent.api.instrumentation.mixin.Initializer
import kanela.agent.libs.net.bytebuddy.implementation.bind.annotation._

import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.{ExecutionContext, Future, Promise, Batchable}
import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}

Expand Down Expand Up @@ -67,12 +67,12 @@ class AkkaHttpServerInstrumentation extends InstrumentationBuilder {
*/
onTypes("akka.http.scaladsl.util.FastFuture$FulfilledFuture", "akka.http.scaladsl.util.FastFuture$ErrorFuture")
.mixin(classOf[HasContext.MixinWithInitializer])
.advise(method("transform"), InvokeWithCapturedContext)
.advise(method("transformWith"), InvokeWithCapturedContext)
.advise(method("onComplete"), InvokeWithCapturedContext)
.advise(method("transform"), InvokeWithCapturedContext)
.advise(method("transformWith"), InvokeWithCapturedContext)
.advise(method("onComplete"), InvokeWithCapturedContext)

onType("akka.http.scaladsl.util.FastFuture$")
.intercept(method("transformWith$extension"), FastFutureTransformWithAdvice)
.intercept(method("transformWith$extension").and(takesArguments(4)), FastFutureTransformWithAdvice)
}

trait HasMatchingContext {
Expand Down Expand Up @@ -243,9 +243,15 @@ object FastFutureTransformWithAdvice {
try f(x)
catch { case NonFatal(e) => FastFuture.failed(e) }

// If we get a FulfilledFuture or ErrorFuture, those will have the HasContext mixin,
// otherwise we are getting a regular Future which has the context mixed into its value.
if(future.isInstanceOf[HasContext])
// If we get a FulfilledFuture or ErrorFuture, those will have the HasContext mixin but since Scala 2.13 the
// "future" will also have a HasContext mixin (its actually a Transformation instance) and since we can't directly
// access FulfilledFuture or ErrorFuture, we are assuming that if it got to this point, it HasContext and it is not
// a Batchable (i.e. a Transformation) then we can do the same we were doing for previous Scala versions.
//
// When we get a regular Future the path is a bit different because the actual Context is not stored in the Future
// but in the value itself via HasContext instrumentation on scala.util.Try
//
if(future.isInstanceOf[HasContext] && !future.isInstanceOf[Batchable])
zuper.call()
else {
future.value match {
Expand Down
17 changes: 0 additions & 17 deletions kamon-akka-http/src/test/resources/application.conf
Expand Up @@ -4,21 +4,4 @@ kamon {
}

trace.sampler = "always"
}

kanela.log-level = INFO
//kanela.debug-mode = yes


kanela {
class-dumper {
# Enables the class dumper.
enabled = true
# Default dir.
dir = ${user.home}"/kanela-agent/dump/akka-http"
# By default build a jar containing all instrumented classes.
create-jar = false
# Default jar name.
jar-name = "instrumented-classes-akka-http"
}
}

0 comments on commit c65e89f

Please sign in to comment.