Search in sources :

Example 1 with ExceptionMessageErrorParser

use of org.springframework.cloud.sleuth.ExceptionMessageErrorParser 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 ExceptionMessageErrorParser

use of org.springframework.cloud.sleuth.ExceptionMessageErrorParser 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 ExceptionMessageErrorParser

use of org.springframework.cloud.sleuth.ExceptionMessageErrorParser 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 ExceptionMessageErrorParser

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

the class TraceFilterTests method neverSampleFilter.

private Filter neverSampleFilter() {
    Tracing tracing = Tracing.newBuilder().currentTraceContext(CurrentTraceContext.Default.create()).spanReporter(this.reporter).sampler(Sampler.NEVER_SAMPLE).supportsJoin(false).build();
    HttpTracing httpTracing = HttpTracing.newBuilder(tracing).clientParser(new SleuthHttpClientParser(this.traceKeys)).serverParser(new SleuthHttpServerParser(this.traceKeys, new ExceptionMessageErrorParser())).serverSampler(new SleuthHttpSampler(() -> Pattern.compile(""))).build();
    return TracingFilter.create(httpTracing);
}
Also used : HttpTracing(brave.http.HttpTracing) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) Tracing(brave.Tracing) HttpTracing(brave.http.HttpTracing)

Example 5 with ExceptionMessageErrorParser

use of org.springframework.cloud.sleuth.ExceptionMessageErrorParser 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)

Aggregations

ExceptionMessageErrorParser (org.springframework.cloud.sleuth.ExceptionMessageErrorParser)14 DefaultSpanNamer (org.springframework.cloud.sleuth.DefaultSpanNamer)12 Test (org.junit.Test)9 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 Tracing (brave.Tracing)1 HttpTracing (brave.http.HttpTracing)1 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 After (org.junit.After)1