New to Observability? Let's fix that! New to Observability? Let's fix that right away!

You are viewing documentation for an outdated version. Do you wish to see documentation for the latest version?

Instrumentation/Available Instrumentation

Context Propagation with Futures #

The kamon-futures module provides bytecode instrumentation for Scala, Twitter and Scalaz Futures that automatically propagates the current Context across the asynchronous operations that might be scheduled for a given Future.

The following artifacts are published, pick the ones that match the libraries you are using in your services:

  • kamon-scala-future for Scala 2.10, 2.11 and 2.12.
  • kamon-twitter-future for util-core 6.34 in Scala 2.10 and util-core 6.40 for Scala 2.11 and 2.12.
  • kamon-scalaz-future for scalaz-concurrent 7.2.8 with Scala 2.10, 2.11 and 2.12.

Dependency Installation #

libraryDependencies += "io.kamon" %% "kamon-scala-future" % "1.0.0"


implementation 'io.kamon:kamon-scala-future_2.13:1.0.0'

You must start your application with the instrumentation agent for this module to work properly.

Future’s Body and Callbacks #

In the following piece of code, the body of the future will be executed asynchronously on a thread provided by the ExecutionContext available in implicit scope, but Kamon will capture the current Context available when the future was created and make it available while executing the future’s body.

  Kamon.withContextKey(userID, Some("1234")) {
    // The Context is available here,

    Future {
      // is available here as well.
      "Hello Kamon"

      .flatMap(len => Future(len.toString))
      .map(s => Kamon.currentContext().get(userID))
      // And through all async callbacks, even while
      // they are executed at different threads!

Also, when you transform a future by using map/flatMap/filter and friends or you directly register a callback on a future (onComplete/onSuccess/onFailure), Kamon will capture the current Context available when transforming the future and make it available when executing the given callback. The code snippet above would print the same userID that was available when creating the future, during its body execution and during the execution of all the asynchronous operations scheduled on it.

On this article
Not sure where to analyze your Telemetry data?
Create alerts, analyze metrics, and find slow & failed traces in Kamon APM
Kamon APM Heatmap Try Kamon APM
Start with a Free account - Learn more