OpenTracing instrumentation for Scala Akka
Switch branches/tags
Nothing to show
Clone or download
malafeev add license to README
Signed-off-by: Sergei Malafeev <sergeymalafeev@gmail.com>
Latest commit 4192a6a Jul 26, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.mvn/wrapper initial implementation based on opentracing java-akka instrumentation Feb 16, 2018
src
travis initial implementation based on opentracing java-akka instrumentation Feb 16, 2018
.gitignore initial implementation based on opentracing java-akka instrumentation Feb 16, 2018
.settings.xml initial implementation based on opentracing java-akka instrumentation Feb 16, 2018
.travis.yml add test coverage Jun 29, 2018
LICENSE Initial commit Feb 16, 2018
README.md
RELEASE.md
header.txt
mvnw initial implementation based on opentracing java-akka instrumentation Feb 16, 2018
mvnw.cmd initial implementation based on opentracing java-akka instrumentation Feb 16, 2018
pom.xml add source dir to coveralls Jun 29, 2018

README.md

Build Status Coverage Status Released Version

OpenTracing Scala Akka instrumentation

OpenTracing instrumentation for Scala Akka.

Installation

build.sbt

libraryDependencies += "io.opentracing.contrib" % "opentracing-scala-akka" % "VERSION"

Usage

Tracer registration

Instantiate tracer and register it with GlobalTracer:

val tracer: Tracer = ???
GlobalTracer.register(tracer)

Actor's Span propagation

User is responsible for finishing the Spans. For this to work, classes must inherit from TracedAbstractActor instead of Actor, and messages must be wrapped using TracedMessage.wrap():

class MyActor extends TracedAbstractActor {
  override def receive(): Receive = {
    case _: String =>
      sender().tell("ciao", self)
  }
}

val scope =  tracer.buildSpan("foo").startActive(true)

// scope.span() will be captured as part of TracedMessage.wrap(),
// and MyActor will receive the original 'myMessageObj` instance.
val future = ask(myActorRef, TracedMessage.wrap("hello"), timeout)
...
    
scope.close()
    
}

By default, TracedAbstractActor/TracedMessage use io.opentracing.util.GlobalTracer to activate and fetch the Span respectively, but it's possible to manually specify both the Tracer used to activate and the captured Span:

class MyActor(myTracer: Tracer) extends TracedAbstractActor {
  override def receive(): Receive = {
    case _: String =>
      // TracedAbstractActor.tracer() returns the Tracer being used,
      // either GlobalTracer 
      if (tracer().activeSpan() != null) {
        // Use the active Span, to set tags, create children, finish it, etc.
        tracer().activeSpan.finish()
      }
      ...
  }

  override def tracer(): Tracer = myTracer
}

val span = tracer.buildSpan("foo").start()
val future = ask(myActorRef, TracedMessage.wrap(span, "hello"), timeout);

License

Apache 2.0 License.