Search in sources :

Example 1 with DefaultSpanNamer

use of org.springframework.cloud.sleuth.DefaultSpanNamer in project spring-cloud-sleuth by spring-cloud.

the class SleuthHystrixConcurrencyStrategyTest method should_delegate_work_to_custom_hystrix_concurrency_strategy.

@Test
public void should_delegate_work_to_custom_hystrix_concurrency_strategy() throws Exception {
    HystrixConcurrencyStrategy strategy = Mockito.mock(HystrixConcurrencyStrategy.class);
    HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
    SleuthHystrixConcurrencyStrategy sleuthStrategy = new SleuthHystrixConcurrencyStrategy(this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
    sleuthStrategy.wrapCallable(() -> "foo");
    sleuthStrategy.getThreadPool(HystrixThreadPoolKey.Factory.asKey(""), Mockito.mock(HystrixThreadPoolProperties.class));
    sleuthStrategy.getThreadPool(HystrixThreadPoolKey.Factory.asKey(""), Mockito.mock(HystrixProperty.class), Mockito.mock(HystrixProperty.class), Mockito.mock(HystrixProperty.class), TimeUnit.DAYS, Mockito.mock(BlockingQueue.class));
    sleuthStrategy.getBlockingQueue(10);
    sleuthStrategy.getRequestVariable(Mockito.mock(HystrixLifecycleForwardingRequestVariable.class));
    BDDMockito.then(strategy).should().wrapCallable((Callable) BDDMockito.any());
    BDDMockito.then(strategy).should().getThreadPool(BDDMockito.any(), BDDMockito.any());
    BDDMockito.then(strategy).should().getThreadPool(BDDMockito.any(), BDDMockito.any(), BDDMockito.any(), BDDMockito.any(), BDDMockito.any(), BDDMockito.any());
    BDDMockito.then(strategy).should().getThreadPool(BDDMockito.any(), BDDMockito.any(), BDDMockito.any(), BDDMockito.any(), BDDMockito.any(), BDDMockito.any());
    BDDMockito.then(strategy).should().getBlockingQueue(10);
    BDDMockito.then(strategy).should().getRequestVariable(BDDMockito.any());
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) HystrixLifecycleForwardingRequestVariable(com.netflix.hystrix.strategy.concurrency.HystrixLifecycleForwardingRequestVariable) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) HystrixConcurrencyStrategy(com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy) HystrixProperty(com.netflix.hystrix.strategy.properties.HystrixProperty) HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties) Test(org.junit.Test)

Example 2 with DefaultSpanNamer

use of org.springframework.cloud.sleuth.DefaultSpanNamer in project spring-cloud-sleuth by spring-cloud.

the class SleuthHystrixConcurrencyStrategyTest method should_wrap_delegates_callable_in_trace_callable_when_delegate_is_present.

@Test
public void should_wrap_delegates_callable_in_trace_callable_when_delegate_is_present() throws Exception {
    HystrixPlugins.getInstance().registerConcurrencyStrategy(new MyHystrixConcurrencyStrategy());
    SleuthHystrixConcurrencyStrategy strategy = new SleuthHystrixConcurrencyStrategy(this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
    Callable<String> callable = strategy.wrapCallable(() -> "hello");
    then(callable).isInstanceOf(TraceCallable.class);
    then(callable.call()).isEqualTo("executed_custom_callable");
}
Also used : ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) Test(org.junit.Test)

Example 3 with DefaultSpanNamer

use of org.springframework.cloud.sleuth.DefaultSpanNamer in project spring-cloud-sleuth by spring-cloud.

the class SpringCloudSleuthDocTests method should_wrap_runnable_in_its_sleuth_representative.

@Test
public void should_wrap_runnable_in_its_sleuth_representative() {
    SpanNamer spanNamer = new DefaultSpanNamer();
    ErrorParser errorParser = new ExceptionMessageErrorParser();
    // tag::trace_runnable[]
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
        // do some work
        }

        @Override
        public String toString() {
            return "spanNameFromToStringMethod";
        }
    };
    // Manual `TraceRunnable` creation with explicit "calculateTax" Span name
    Runnable traceRunnable = new TraceRunnable(tracer, spanNamer, errorParser, runnable, "calculateTax");
    // Wrapping `Runnable` with `Tracing`. That way the current span will be available
    // in the thread of `Runnable`
    Runnable traceRunnableFromTracer = tracing.currentTraceContext().wrap(runnable);
    // end::trace_runnable[]
    then(traceRunnable).isExactlyInstanceOf(TraceRunnable.class);
}
Also used : TraceRunnable(org.springframework.cloud.sleuth.instrument.async.TraceRunnable) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) SpanNamer(org.springframework.cloud.sleuth.SpanNamer) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) TraceRunnable(org.springframework.cloud.sleuth.instrument.async.TraceRunnable) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) ErrorParser(org.springframework.cloud.sleuth.ErrorParser) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) Test(org.junit.Test)

Example 4 with DefaultSpanNamer

use of org.springframework.cloud.sleuth.DefaultSpanNamer in project spring-cloud-sleuth by spring-cloud.

the class TraceableExecutorServiceTests method beanFactory.

BeanFactory beanFactory() {
    BDDMockito.given(this.beanFactory.getBean(Tracer.class)).willReturn(this.tracer);
    BDDMockito.given(this.beanFactory.getBean(SpanNamer.class)).willReturn(new DefaultSpanNamer());
    BDDMockito.given(this.beanFactory.getBean(ErrorParser.class)).willReturn(new ExceptionMessageErrorParser());
    return this.beanFactory;
}
Also used : ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer)

Example 5 with DefaultSpanNamer

use of org.springframework.cloud.sleuth.DefaultSpanNamer in project spring-cloud-sleuth by spring-cloud.

the class TraceableExecutorServiceTests method callables.

private List callables() {
    List list = new ArrayList<>();
    list.add(new TraceCallable<>(this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser(), () -> "foo"));
    list.add((Callable) () -> "bar");
    return list;
}
Also used : ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) ArrayList(java.util.ArrayList) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Aggregations

DefaultSpanNamer (org.springframework.cloud.sleuth.DefaultSpanNamer)13 ExceptionMessageErrorParser (org.springframework.cloud.sleuth.ExceptionMessageErrorParser)12 Test (org.junit.Test)10 ErrorParser (org.springframework.cloud.sleuth.ErrorParser)4 SpanNamer (org.springframework.cloud.sleuth.SpanNamer)4 TraceRunnable (org.springframework.cloud.sleuth.instrument.async.TraceRunnable)3 Span (brave.Span)2 ExecutorService (java.util.concurrent.ExecutorService)2 HystrixThreadPoolProperties (com.netflix.hystrix.HystrixThreadPoolProperties)1 HystrixConcurrencyStrategy (com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy)1 HystrixLifecycleForwardingRequestVariable (com.netflix.hystrix.strategy.concurrency.HystrixLifecycleForwardingRequestVariable)1 HystrixProperty (com.netflix.hystrix.strategy.properties.HystrixProperty)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 Callable (java.util.concurrent.Callable)1 Collectors.toList (java.util.stream.Collectors.toList)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 TraceKeys (org.springframework.cloud.sleuth.TraceKeys)1 TraceCallable (org.springframework.cloud.sleuth.instrument.async.TraceCallable)1