Search in sources :

Example 1 with TraceKeys

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

the class TraceCommandTests method should_pass_tracing_information_when_using_Hystrix_commands.

@Test
public void should_pass_tracing_information_when_using_Hystrix_commands() {
    Tracer tracer = this.tracer;
    TraceKeys traceKeys = new TraceKeys();
    HystrixCommand.Setter setter = withGroupKey(asKey("group")).andCommandKey(HystrixCommandKey.Factory.asKey("command"));
    // tag::hystrix_command[]
    HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {

        @Override
        protected String run() throws Exception {
            return someLogic();
        }
    };
    // end::hystrix_command[]
    // tag::trace_hystrix_command[]
    TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {

        @Override
        public String doRun() throws Exception {
            return someLogic();
        }
    };
    // end::trace_hystrix_command[]
    String resultFromHystrixCommand = hystrixCommand.execute();
    String resultFromTraceCommand = traceCommand.execute();
    then(resultFromHystrixCommand).isEqualTo(resultFromTraceCommand);
}
Also used : TraceKeys(org.springframework.cloud.sleuth.TraceKeys) HystrixCommand(com.netflix.hystrix.HystrixCommand) Tracer(brave.Tracer) Test(org.junit.Test)

Example 2 with TraceKeys

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

the class MyFilter method should_create_a_trace.

@Test
public void should_create_a_trace() throws Exception {
    whenSentPingWithoutTracingData();
    then(this.reporter.getSpans()).hasSize(1);
    zipkin2.Span span = this.reporter.getSpans().get(0);
    then(span.tags()).containsKey(new TraceKeys().getMvc().getControllerClass()).containsKey(new TraceKeys().getMvc().getControllerMethod());
    then(this.tracer.currentSpan()).isNull();
}
Also used : TraceKeys(org.springframework.cloud.sleuth.TraceKeys) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with TraceKeys

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

the class LabelExtractorTests method testRpcClientBasicsTraceKeys.

@Test
public void testRpcClientBasicsTraceKeys() {
    LabelExtractor extractor = new LabelExtractor(new TraceKeys());
    String instanceId = "localhost";
    long begin = 1238912378081L;
    long end = 1238912378123L;
    Span span = Span.newBuilder().traceId("123").id("9999").timestamp(begin).duration(end - begin).putTag("http.host", "localhost").putTag("custom-tag", "hello").localEndpoint(Endpoint.newBuilder().serviceName("hello-service").build()).build();
    Map<String, String> labels = extractor.extract(span);
    Assert.assertNotNull("span shouldn't be null", span);
    Assert.assertEquals("localhost", labels.get("/http/host"));
    Assert.assertEquals("spring-cloud-gcp-trace", labels.get("/agent"));
    Assert.assertEquals("hello-service", labels.get("/component"));
    Assert.assertEquals("hello", labels.get("cloud.spring.io/custom-tag"));
}
Also used : TraceKeys(org.springframework.cloud.sleuth.TraceKeys) Span(zipkin2.Span) Test(org.junit.Test)

Example 4 with TraceKeys

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

the class TraceAsyncAspectTest method should_work.

// Issue#926
@Test
public void should_work() throws Throwable {
    TraceAsyncAspect asyncAspect = new TraceAsyncAspect(this.tracing.tracer(), new DefaultSpanNamer(), new TraceKeys()) {

        @Override
        String name(ProceedingJoinPoint pjp) {
            return "foo-bar";
        }
    };
    asyncAspect.traceBackgroundThread(this.point);
    BDDAssertions.then(this.reporter.getSpans()).hasSize(1);
    BDDAssertions.then(this.reporter.getSpans().get(0).name()).isEqualTo("foo-bar");
}
Also used : TraceKeys(org.springframework.cloud.sleuth.TraceKeys) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 TraceKeys (org.springframework.cloud.sleuth.TraceKeys)4 Tracer (brave.Tracer)1 HystrixCommand (com.netflix.hystrix.HystrixCommand)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 DefaultSpanNamer (org.springframework.cloud.sleuth.DefaultSpanNamer)1 Span (zipkin2.Span)1