Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/opentracing-contrib/scala-akka
OpenTracing instrumentation for Scala Akka
https://github.com/opentracing-contrib/scala-akka
akka opentracing scala
Last synced: about 2 months ago
JSON representation
OpenTracing instrumentation for Scala Akka
- Host: GitHub
- URL: https://github.com/opentracing-contrib/scala-akka
- Owner: opentracing-contrib
- License: apache-2.0
- Created: 2018-02-16T13:22:21.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-30T17:20:16.000Z (over 2 years ago)
- Last Synced: 2024-04-15T23:00:01.707Z (9 months ago)
- Topics: akka, opentracing, scala
- Language: Scala
- Size: 73.2 KB
- Stars: 16
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Released Version][maven-img]][maven] [![Apache-2.0 license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
# OpenTracing Scala Akka instrumentation
OpenTracing instrumentation for Scala Akka.## Installation
build.sbt
```sbt
libraryDependencies += "io.opentracing.contrib" % "opentracing-scala-akka" % "VERSION"
```## Usage
### Tracer registration
Instantiate tracer and register it with `GlobalTracer`:
```scala
val tracer: Tracer = ???
GlobalTracer.register(tracer)
```### Actor's Span propagation
User is responsible for finishing the `Span`s. For this to work, classes must
inherit from `TracedAbstractActor` instead of `Actor`, and messages must be wrapped using
`TracedMessage.wrap()`:```scala
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`:```scala
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](./LICENSE).
[ci-img]: https://travis-ci.org/opentracing-contrib/scala-akka.svg?branch=master
[ci]: https://travis-ci.org/opentracing-contrib/scala-akka
[cov-img]: https://coveralls.io/repos/github/opentracing-contrib/scala-akka/badge.svg?branch=master
[cov]: https://coveralls.io/github/opentracing-contrib/scala-akka?branch=master
[maven-img]: https://img.shields.io/maven-central/v/io.opentracing.contrib/opentracing-scala-akka.svg
[maven]: http://search.maven.org/#search%7Cga%7C1%7Copentracing-scala-akka