OpenTracing Java Bridge for Zipkin
This library is a Java bridge between the Brave/Zipkin Api and OpenTracing. It allows its users to write portable (in the OpenTracing sense) instrumentation that's translated into Brave instrumentation transparently.
opentracing-api has broken compatibility on most releases, which limits the ability for this project to provide a large version range.
Here are the versions currently available, noting only the latest version of opentracing-api is likely to have new work in this repository.
Firstly, you need a Tracer, configured to report to Zipkin.
// Configure a reporter, which controls how often spans are sent // (the dependency is io.zipkin.reporter2:zipkin-sender-okhttp3) sender = OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans"); 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" propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY) .addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id")) .build(); // Now, create a Brave tracing component with the service name you want to see in Zipkin. // (the dependency is io.zipkin.brave:brave) braveTracing = Tracing.newBuilder() .localServiceName("my-service") .propagationFactory(propagationFactory) .spanReporter(spanReporter) .build(); // use this to create an OpenTracing Tracer tracer = BraveTracer.create(braveTracing); // You can later unwrap the underlying Brave Api as needed braveTracing = tracer.unwrap();
Note: If you haven't updated to a server running the Zipkin v2 api, you can use the old Zipkin format like this:
sender = OkHttpSender.json("http://127.0.0.1:9411/api/v1/spans"); spanReporter = AsyncReporter.builder(sender).build(SpanEncoder.JSON_V1);
The artifact published is
brave-opentracing under the group ID
Snapshots are uploaded to JFrog after commits to maste r.