Opentracing backend

To use, add the following dependency to your project:

"com.softwaremill.sttp.client" %% "opentracing-backend" % "2.0.0-M7"

This backend depends on opentracing, a standardized set of api for distributed tracing.

The opentracing backend wraps any other backend, but it’s useless without a concrete distributed tracing implementation. To obtain instance of opentracing backend:

OpenTracingBackend(wrappedBackend, tracer)

Where tracer is an interface which can be implemented by any compatible library. See examples below.

The backend obtains the current trace context using default spans’s propagation mechanisms. There is an additional method exposed to override default operation id:

import sttp.client.brave.OpenTracingBackend._


Integration with jaeger

Using with jaeger tracing

Add following dependency:

libraryDependencies += "io.jaegertracing" % "jaeger-client" % "1.0.0"

Create an instance of tracer:

import io.jaegertracing.Configuration
import io.jaegertracing.Configuration.ReporterConfiguration
import io.jaegertracing.Configuration.SamplerConfiguration
import io.jaegertracing.internal.JaegerTracer

def initTracer(serviceName: String ): Tracer = {
  val samplerConfig = SamplerConfiguration.fromEnv().withType("const").withParam(1)
  val reporterConfig = ReporterConfiguration.fromEnv().withLogSpans(true)
  val config = new Configuration(serviceName).withSampler(samplerConfig)

For more details about integration with jaeger click here

Integration with brave

Using with brave tracing

Add following dependency:

libraryDependencies += "io.opentracing.brave" % "brave-opentracing" % "0.34.2"

Create instance of tracer:

def initTracer(zipkinUrl: String, serviceName: String): Tracer = {
    // Configure a reporter, which controls how often spans are sent
    //   (the dependency is io.zipkin.reporter2:zipkin-sender-okhttp3)
    val sender = OkHttpSender.create(zipkinUrl)
    val spanReporter = AsyncReporter.create(sender)

    // If you want to support baggage, indicate the fields you'd like to
    // whitelist, in this case "country-code" and "user-id". On the wire,
    // they will be prefixed like "baggage-country-code"
    val propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
                                            Arrays.asList("country-code", "user-id"))

    // Now, create a Brave tracing component with the service name you want to see in
    // Zipkin (the dependency is io.zipkin.brave:brave).
    val braveTracing = Tracing.newBuilder()

    // use this to create an OpenTracing Tracer

For more details about integration with brave click here