Search in sources :

Example 6 with DefaultSpanNamer

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

the class TraceableScheduledExecutorServiceTest method beanFactory.

BeanFactory beanFactory() {
    BDDMockito.given(this.beanFactory.getBean(Tracer.class)).willReturn(this.tracing.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 7 with DefaultSpanNamer

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

the class SleuthHystrixConcurrencyStrategyTest method should_wrap_callable_in_trace_callable_when_delegate_is_present.

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

Example 8 with DefaultSpanNamer

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

the class SleuthHystrixConcurrencyStrategyTest method should_add_trace_keys_when_span_is_created.

@Test
public void should_add_trace_keys_when_span_is_created() throws Exception {
    SleuthHystrixConcurrencyStrategy strategy = new SleuthHystrixConcurrencyStrategy(this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
    Callable<String> callable = strategy.wrapCallable(() -> "hello");
    callable.call();
    then(callable).isInstanceOf(TraceCallable.class);
    then(this.reporter.getSpans()).hasSize(1);
}
Also used : ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) Test(org.junit.Test)

Example 9 with DefaultSpanNamer

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

the class SleuthHystrixConcurrencyStrategyTest method should_not_override_existing_custom_strategies.

@Test
public void should_not_override_existing_custom_strategies() {
    HystrixPlugins.getInstance().registerCommandExecutionHook(new MyHystrixCommandExecutionHook());
    HystrixPlugins.getInstance().registerEventNotifier(new MyHystrixEventNotifier());
    HystrixPlugins.getInstance().registerMetricsPublisher(new MyHystrixMetricsPublisher());
    HystrixPlugins.getInstance().registerPropertiesStrategy(new MyHystrixPropertiesStrategy());
    new SleuthHystrixConcurrencyStrategy(this.tracing.tracer(), new DefaultSpanNamer(), new ExceptionMessageErrorParser());
    then(HystrixPlugins.getInstance().getCommandExecutionHook()).isExactlyInstanceOf(MyHystrixCommandExecutionHook.class);
    then(HystrixPlugins.getInstance().getEventNotifier()).isExactlyInstanceOf(MyHystrixEventNotifier.class);
    then(HystrixPlugins.getInstance().getMetricsPublisher()).isExactlyInstanceOf(MyHystrixMetricsPublisher.class);
    then(HystrixPlugins.getInstance().getPropertiesStrategy()).isExactlyInstanceOf(MyHystrixPropertiesStrategy.class);
}
Also used : ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) Test(org.junit.Test)

Example 10 with DefaultSpanNamer

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

the class SpringCloudSleuthDocTests method should_set_runnable_name_to_to_string_value.

@Test
public void should_set_runnable_name_to_to_string_value() throws ExecutionException, InterruptedException {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    SpanNamer spanNamer = new DefaultSpanNamer();
    ErrorParser errorParser = new ExceptionMessageErrorParser();
    // tag::span_name_to_string_runnable_execution[]
    Runnable runnable = new TraceRunnable(tracer, spanNamer, errorParser, new Runnable() {

        @Override
        public void run() {
        // perform logic
        }

        @Override
        public String toString() {
            return "calculateTax";
        }
    });
    Future<?> future = executorService.submit(runnable);
    // ... some additional logic ...
    future.get();
    // end::span_name_to_string_runnable_execution[]
    List<zipkin2.Span> spans = this.reporter.getSpans();
    then(spans).hasSize(1);
    then(spans.get(0).name()).isEqualTo("calculatetax");
    executorService.shutdown();
}
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) ExecutorService(java.util.concurrent.ExecutorService) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) ErrorParser(org.springframework.cloud.sleuth.ErrorParser) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) Span(brave.Span) Test(org.junit.Test)

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