OpenTracing instrumentation for Finagle.
build.sbt
libraryDependencies += "io.opentracing.contrib" % "opentracing-finagle" % "0.0.2"
// Instantiate tracer
val tracer: Tracer = ...
// Apply OpenTracingHttpFilter to Finagle service to serve HTTP requests
val service = new OpenTracingHttpFilter(tracer, true) andThen new Service[http.Request, http.Response] {
def apply(req: http.Request): Future[http.Response] =
Future.value(
http.Response(req.version, http.Status.Ok)
)
}
// Create server
val server = Http.server.serve(":8080", service)
Await.ready(server)
// Apply OpenTracingHttpFilter to Finagle client service
val client = new OpenTracingHttpFilter(tracer, false) andThen Http.client.newService(":8080")
// Build request
val request = http.Request(http.Method.Get, "/")
// Build response
val response: Future[http.Response] = client(request)
// Wait for result
val result = Await.result(response)