This project aims to provide a bridge to allow OpenTracing native instrumentation to
work nicely in apps using the spring-cloud-sleuth
tracer. It provides implementations
of OpenTracings interfaces that create and modify sleuth Spans.
While sleuth-opentracing
's implementation works on sleuth spans, the following caveats exist:
-
it does not do the work to associate new spans with sleuths tracer. To associate the span with sleuth, a developer must call
continue
on the sleuth tracer with their new sleuth span. -
it does not make the current sleuth span a parent of the new spans it creates. This must be done by wrapping the current sleuth span in a
SleuthSpan
and pass it into theasChildOf(Span)
SpanBuilder
method. -
it does not do the work to have sleuth report those spans. This must be done after you finish the OpenTracing span by closing the sleuth span with the sleuth tracer.
-
it does not reattach the old sleuth span upon completion of the span you created. This must be done by passing the old span into the
continue
method on the sleuth tracer.
SleuthTracer otTracer = ....;
Tracer sleuthTracer = ...;
public Object around(ProceedingJoinPoint jp) {
org.springframework.cloud.sleuth.Span parent = sleuthTracer.getCurrentSpan();
Span span = otTracer.buildSpan("my-operation").asChildOf(Span.wrap(parent)).start();
sleuthTracer.continue(span.unwrap());
Object result = jp.proceed();
span.finish();
sleuthTracer.detach(span.unwrap());
sleuthTracer.continue(parent);
return result;
}