Giter Club home page Giter Club logo

kamon-futures's Introduction

Futures Instrumentation

Build Status Gitter Maven Central

Getting Started

The Futures instrumentation is currently available for Scala 2.10, 2.11 and 2.12.

Supported releases and dependencies are shown below.

kamon-futures status jdk scala
1.0.0 stable 1.7+, 1.8+ 2.10, 2.11, 2.12

To get started with SBT, simply add the following to your build.sbt file:

resolvers += Resolver.bintrayRepo("kamon-io", "snapshots")

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

Automatic TraceContext Propagation with Futures

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

All modules in the kamon-futures project module require you to start your application using the AspectJ Weaver Agent.

Instrumenting Future's Body and Callbacks

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

  val context = contextWithLocal("in-future-transformations")
        val baggageAfterTransformations = Kamon.withContext(context) {
            Future("Hello Kamon!")
              // The active span is expected to be available during all intermediate processing.
              .map(_.length)
              .flatMap(len => Future(len.toString))
              .map(_ => Kamon.currentContext().get(StringKey))
          }

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.