use of org.springframework.cloud.sleuth.instrument.async.TraceCallable in project spring-cloud-sleuth by spring-cloud.
the class SpringCloudSleuthDocTests method should_wrap_callable_in_its_sleuth_representative.
@Test
public void should_wrap_callable_in_its_sleuth_representative() {
SpanNamer spanNamer = new DefaultSpanNamer();
ErrorParser errorParser = new ExceptionMessageErrorParser();
// tag::trace_callable[]
Callable<String> callable = new Callable<String>() {
@Override
public String call() throws Exception {
return someLogic();
}
@Override
public String toString() {
return "spanNameFromToStringMethod";
}
};
// Manual `TraceCallable` creation with explicit "calculateTax" Span name
Callable<String> traceCallable = new TraceCallable<>(tracer, spanNamer, errorParser, callable, "calculateTax");
// Wrapping `Callable` with `Tracing`. That way the current span will be available
// in the thread of `Callable`
Callable<String> traceCallableFromTracer = tracing.currentTraceContext().wrap(callable);
// end::trace_callable[]
}
Aggregations