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);
}
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();
}
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"));
}
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");
}
Aggregations