Search in sources :

Example 1 with TraceCallable

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[]
}
Also used : ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) SpanNamer(org.springframework.cloud.sleuth.SpanNamer) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) TraceCallable(org.springframework.cloud.sleuth.instrument.async.TraceCallable) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) ErrorParser(org.springframework.cloud.sleuth.ErrorParser) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) Callable(java.util.concurrent.Callable) TraceCallable(org.springframework.cloud.sleuth.instrument.async.TraceCallable) Test(org.junit.Test)

Aggregations

Callable (java.util.concurrent.Callable)1 Test (org.junit.Test)1 DefaultSpanNamer (org.springframework.cloud.sleuth.DefaultSpanNamer)1 ErrorParser (org.springframework.cloud.sleuth.ErrorParser)1 ExceptionMessageErrorParser (org.springframework.cloud.sleuth.ExceptionMessageErrorParser)1 SpanNamer (org.springframework.cloud.sleuth.SpanNamer)1 TraceCallable (org.springframework.cloud.sleuth.instrument.async.TraceCallable)1