Bumping versions
This commit is contained in:
@@ -28,8 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@EnableAutoConfiguration(
|
||||
exclude = { LoadBalancerAutoConfiguration.class, JmxAutoConfiguration.class })
|
||||
@EnableAutoConfiguration(exclude = { LoadBalancerAutoConfiguration.class, JmxAutoConfiguration.class })
|
||||
@Configuration
|
||||
public @interface DefaultTestAutoConfiguration {
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ public class TraceAsyncIntegrationTests {
|
||||
@ClassRule
|
||||
public static IntegrationTestSpanHandler spans = new IntegrationTestSpanHandler();
|
||||
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true)
|
||||
.build();
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true).build();
|
||||
|
||||
@Autowired
|
||||
AsyncLogic asyncLogic;
|
||||
@@ -62,8 +61,7 @@ public class TraceAsyncIntegrationTests {
|
||||
MutableSpan span = takeDesirableSpan();
|
||||
assertThat(span.name()).isEqualTo("invoke-async");
|
||||
assertThat(span.containsAnnotation("@Async")).isTrue();
|
||||
assertThat(span.tags()).containsEntry("class", "AsyncLogic")
|
||||
.containsEntry("method", "invokeAsync");
|
||||
assertThat(span.tags()).containsEntry("class", "AsyncLogic").containsEntry("method", "invokeAsync");
|
||||
|
||||
// continues the trace
|
||||
assertThat(span.traceId()).isEqualTo(context.traceIdString());
|
||||
@@ -78,8 +76,8 @@ public class TraceAsyncIntegrationTests {
|
||||
MutableSpan span = takeDesirableSpan();
|
||||
assertThat(span.name()).isEqualTo("foo");
|
||||
assertThat(span.containsAnnotation("@Async")).isTrue();
|
||||
assertThat(span.tags()).containsEntry("class", "AsyncLogic")
|
||||
.containsEntry("method", "invokeAsync_customName");
|
||||
assertThat(span.tags()).containsEntry("class", "AsyncLogic").containsEntry("method",
|
||||
"invokeAsync_customName");
|
||||
|
||||
// continues the trace
|
||||
assertThat(span.traceId()).isEqualTo(context.traceIdString());
|
||||
|
||||
@@ -57,8 +57,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@SpringBootTest(classes = { AppConfig.class, Application.class },
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(classes = { AppConfig.class, Application.class }, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class Issue410Tests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(Issue410Tests.class);
|
||||
@@ -86,14 +85,13 @@ public class Issue410Tests {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
log.info("Starting test");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
|
||||
String response = this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/without_pool", String.class);
|
||||
String response = this.restTemplate.getForObject("http://localhost:" + port() + "/without_pool",
|
||||
String.class);
|
||||
|
||||
then(response).isEqualTo(span.context().traceIdString());
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.asyncTask.getSpan().get()).isNotNull();
|
||||
then(this.asyncTask.getSpan().get().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.asyncTask.getSpan().get().context().traceId()).isEqualTo(span.context().traceId());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -108,14 +106,12 @@ public class Issue410Tests {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
log.info("Starting test");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
|
||||
String response = this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/with_pool", String.class);
|
||||
String response = this.restTemplate.getForObject("http://localhost:" + port() + "/with_pool", String.class);
|
||||
|
||||
then(response).isEqualTo(span.context().traceIdString());
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.asyncTask.getSpan().get()).isNotNull();
|
||||
then(this.asyncTask.getSpan().get().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.asyncTask.getSpan().get().context().traceId()).isEqualTo(span.context().traceId());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -133,14 +129,13 @@ public class Issue410Tests {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
log.info("Starting test");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
|
||||
String response = this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/completable", String.class);
|
||||
String response = this.restTemplate.getForObject("http://localhost:" + port() + "/completable",
|
||||
String.class);
|
||||
|
||||
then(response).isEqualTo(span.context().traceIdString());
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.asyncTask.getSpan().get()).isNotNull();
|
||||
then(this.asyncTask.getSpan().get().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.asyncTask.getSpan().get().context().traceId()).isEqualTo(span.context().traceId());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -158,14 +153,13 @@ public class Issue410Tests {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
log.info("Starting test");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
|
||||
String response = this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/taskScheduler", String.class);
|
||||
String response = this.restTemplate.getForObject("http://localhost:" + port() + "/taskScheduler",
|
||||
String.class);
|
||||
|
||||
then(response).isEqualTo(span.context().traceIdString());
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.asyncTask.getSpan().get()).isNotNull();
|
||||
then(this.asyncTask.getSpan().get().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.asyncTask.getSpan().get().context().traceId()).isEqualTo(span.context().traceId());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -183,15 +177,13 @@ public class Issue410Tests {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
log.info("Starting test");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
|
||||
String response = this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/threadPoolTaskScheduler_submit",
|
||||
String.class);
|
||||
String response = this.restTemplate
|
||||
.getForObject("http://localhost:" + port() + "/threadPoolTaskScheduler_submit", String.class);
|
||||
|
||||
then(response).isEqualTo(span.context().traceIdString());
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.asyncTask.getSpan().get()).isNotNull();
|
||||
then(this.asyncTask.getSpan().get().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.asyncTask.getSpan().get().context().traceId()).isEqualTo(span.context().traceId());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -206,15 +198,13 @@ public class Issue410Tests {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
log.info("Starting test");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
|
||||
String response = this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/threadPoolTaskScheduler_schedule",
|
||||
String.class);
|
||||
String response = this.restTemplate
|
||||
.getForObject("http://localhost:" + port() + "/threadPoolTaskScheduler_schedule", String.class);
|
||||
|
||||
then(response).isEqualTo(span.context().traceIdString());
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.asyncTask.getSpan().get()).isNotNull();
|
||||
then(this.asyncTask.getSpan().get().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.asyncTask.getSpan().get().context().traceId()).isEqualTo(span.context().traceId());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -232,15 +222,13 @@ public class Issue410Tests {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
log.info("Starting test");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
|
||||
String response = this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/scheduledThreadPoolExecutor",
|
||||
String.class);
|
||||
String response = this.restTemplate
|
||||
.getForObject("http://localhost:" + port() + "/scheduledThreadPoolExecutor", String.class);
|
||||
|
||||
then(response).isEqualTo(span.context().traceIdString());
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.asyncTask.getSpan().get()).isNotNull();
|
||||
then(this.asyncTask.getSpan().get().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.asyncTask.getSpan().get().context().traceId()).isEqualTo(span.context().traceId());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -345,17 +333,15 @@ class AsyncTask {
|
||||
AsyncTask.log.info("Second completable future");
|
||||
return AsyncTask.this.tracer.currentSpan();
|
||||
}, AsyncTask.this.executor);
|
||||
CompletableFuture<Span> response = CompletableFuture.allOf(span1, span2)
|
||||
.thenApply(ignoredVoid -> {
|
||||
AsyncTask.log.info("Third completable future");
|
||||
Span joinedSpan1 = span1.join();
|
||||
Span joinedSpan2 = span2.join();
|
||||
then(joinedSpan2).isNotNull();
|
||||
then(joinedSpan1.context().traceId())
|
||||
.isEqualTo(joinedSpan2.context().traceId());
|
||||
AsyncTask.log.info("TraceIds are correct");
|
||||
return joinedSpan2;
|
||||
});
|
||||
CompletableFuture<Span> response = CompletableFuture.allOf(span1, span2).thenApply(ignoredVoid -> {
|
||||
AsyncTask.log.info("Third completable future");
|
||||
Span joinedSpan1 = span1.join();
|
||||
Span joinedSpan2 = span2.join();
|
||||
then(joinedSpan2).isNotNull();
|
||||
then(joinedSpan1.context().traceId()).isEqualTo(joinedSpan2.context().traceId());
|
||||
AsyncTask.log.info("TraceIds are correct");
|
||||
return joinedSpan2;
|
||||
});
|
||||
this.span.set(response.get());
|
||||
return this.span.get();
|
||||
}
|
||||
@@ -365,30 +351,25 @@ class AsyncTask {
|
||||
CompletableFuture<Span> span1 = CompletableFuture.supplyAsync(() -> {
|
||||
AsyncTask.log.info("First completable future");
|
||||
return AsyncTask.this.tracer.currentSpan();
|
||||
}, new LazyTraceExecutor(AsyncTask.this.beanFactory,
|
||||
AsyncTask.this.taskScheduler));
|
||||
}, new LazyTraceExecutor(AsyncTask.this.beanFactory, AsyncTask.this.taskScheduler));
|
||||
CompletableFuture<Span> span2 = CompletableFuture.supplyAsync(() -> {
|
||||
AsyncTask.log.info("Second completable future");
|
||||
return AsyncTask.this.tracer.currentSpan();
|
||||
}, new LazyTraceExecutor(AsyncTask.this.beanFactory,
|
||||
AsyncTask.this.taskScheduler));
|
||||
CompletableFuture<Span> response = CompletableFuture.allOf(span1, span2)
|
||||
.thenApply(ignoredVoid -> {
|
||||
AsyncTask.log.info("Third completable future");
|
||||
Span joinedSpan1 = span1.join();
|
||||
Span joinedSpan2 = span2.join();
|
||||
then(joinedSpan2).isNotNull();
|
||||
then(joinedSpan1.context().traceId())
|
||||
.isEqualTo(joinedSpan2.context().traceId());
|
||||
AsyncTask.log.info("TraceIds are correct");
|
||||
return joinedSpan2;
|
||||
});
|
||||
}, new LazyTraceExecutor(AsyncTask.this.beanFactory, AsyncTask.this.taskScheduler));
|
||||
CompletableFuture<Span> response = CompletableFuture.allOf(span1, span2).thenApply(ignoredVoid -> {
|
||||
AsyncTask.log.info("Third completable future");
|
||||
Span joinedSpan1 = span1.join();
|
||||
Span joinedSpan2 = span2.join();
|
||||
then(joinedSpan2).isNotNull();
|
||||
then(joinedSpan1.context().traceId()).isEqualTo(joinedSpan2.context().traceId());
|
||||
AsyncTask.log.info("TraceIds are correct");
|
||||
return joinedSpan2;
|
||||
});
|
||||
this.span.set(response.get());
|
||||
return this.span.get();
|
||||
}
|
||||
|
||||
public Span scheduledThreadPoolExecutor()
|
||||
throws ExecutionException, InterruptedException {
|
||||
public Span scheduledThreadPoolExecutor() throws ExecutionException, InterruptedException {
|
||||
log.info("This task is running with ScheduledThreadPoolExecutor");
|
||||
this.scheduledThreadPoolExecutor.submit(() -> {
|
||||
log.info("Hello from runnable");
|
||||
@@ -397,8 +378,7 @@ class AsyncTask {
|
||||
return this.span.get();
|
||||
}
|
||||
|
||||
public Span threadPoolTaskSchedulerSubmit()
|
||||
throws ExecutionException, InterruptedException {
|
||||
public Span threadPoolTaskSchedulerSubmit() throws ExecutionException, InterruptedException {
|
||||
log.info("This task is running with ThreadPoolTaskScheduler");
|
||||
this.threadPoolTaskScheduler.submit(() -> {
|
||||
log.info("Hello from runnable");
|
||||
@@ -407,8 +387,7 @@ class AsyncTask {
|
||||
return this.span.get();
|
||||
}
|
||||
|
||||
public Span threadPoolTaskSchedulerSchedule()
|
||||
throws ExecutionException, InterruptedException {
|
||||
public Span threadPoolTaskSchedulerSchedule() throws ExecutionException, InterruptedException {
|
||||
log.info("This task is running with ThreadPoolTaskScheduler");
|
||||
this.threadPoolTaskScheduler.schedule(() -> {
|
||||
log.info("Hello from runnable");
|
||||
@@ -463,22 +442,19 @@ class Application {
|
||||
}
|
||||
|
||||
@RequestMapping("/threadPoolTaskScheduler_submit")
|
||||
public String threadPoolTaskSchedulerSubmit()
|
||||
throws ExecutionException, InterruptedException {
|
||||
public String threadPoolTaskSchedulerSubmit() throws ExecutionException, InterruptedException {
|
||||
log.info("Executing completable via ThreadPoolTaskScheduler");
|
||||
return this.asyncTask.threadPoolTaskSchedulerSubmit().context().traceIdString();
|
||||
}
|
||||
|
||||
@RequestMapping("/threadPoolTaskScheduler_schedule")
|
||||
public String threadPoolTaskSchedulerSchedule()
|
||||
throws ExecutionException, InterruptedException {
|
||||
public String threadPoolTaskSchedulerSchedule() throws ExecutionException, InterruptedException {
|
||||
log.info("Executing completable via ThreadPoolTaskScheduler");
|
||||
return this.asyncTask.threadPoolTaskSchedulerSchedule().context().traceIdString();
|
||||
}
|
||||
|
||||
@RequestMapping("/scheduledThreadPoolExecutor")
|
||||
public String scheduledThreadPoolExecutor()
|
||||
throws ExecutionException, InterruptedException {
|
||||
public String scheduledThreadPoolExecutor() throws ExecutionException, InterruptedException {
|
||||
log.info("Executing completable via ScheduledThreadPoolExecutor");
|
||||
return this.asyncTask.scheduledThreadPoolExecutor().context().traceIdString();
|
||||
}
|
||||
|
||||
@@ -49,9 +49,7 @@ public class Issue546Tests {
|
||||
|
||||
@Test
|
||||
public void should_pass_tracing_info_when_using_callbacks() {
|
||||
new RestTemplate().getForObject(
|
||||
"http://localhost:" + port() + "/trace-async-rest-template",
|
||||
String.class);
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/trace-async-rest-template", String.class);
|
||||
}
|
||||
|
||||
private int port() {
|
||||
@@ -94,8 +92,7 @@ class Controller {
|
||||
}
|
||||
|
||||
@RequestMapping("/trace-async-rest-template")
|
||||
public void asyncTest(@RequestParam(required = false) boolean isSleep)
|
||||
throws InterruptedException {
|
||||
public void asyncTest(@RequestParam(required = false) boolean isSleep) throws InterruptedException {
|
||||
log.info("(/trace-async-rest-template) I got a request!");
|
||||
final long traceId = this.tracer.tracer().currentSpan().context().traceId();
|
||||
ListenableFuture<ResponseEntity<HogeBean>> res = this.traceAsyncRestTemplate
|
||||
@@ -104,17 +101,13 @@ class Controller {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
res.addCallback(success -> {
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId())
|
||||
.isEqualTo(traceId);
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId()).isEqualTo(traceId);
|
||||
log.info("(/trace-async-rest-template) success");
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId())
|
||||
.isEqualTo(traceId);
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId()).isEqualTo(traceId);
|
||||
}, failure -> {
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId())
|
||||
.isEqualTo(traceId);
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId()).isEqualTo(traceId);
|
||||
log.error("(/trace-async-rest-template) failure", failure);
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId())
|
||||
.isEqualTo(traceId);
|
||||
then(Controller.this.tracer.tracer().currentSpan().context().traceId()).isEqualTo(traceId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@SpringBootTest(classes = Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class ManuallyCreatedLoadBalancerFeignClientTests {
|
||||
|
||||
@@ -150,9 +149,9 @@ class MyDelegateClient implements Client {
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options) {
|
||||
this.wasCalled = true;
|
||||
return Response.builder().body("foo", StandardCharsets.UTF_8)
|
||||
.request(Request.create(Request.HttpMethod.POST, "/foo", new HashMap<>(),
|
||||
Request.Body.empty(), new RequestTemplate()))
|
||||
return Response
|
||||
.builder().body("foo", StandardCharsets.UTF_8).request(Request.create(Request.HttpMethod.POST, "/foo",
|
||||
new HashMap<>(), Request.Body.empty(), new RequestTemplate()))
|
||||
.headers(new HashMap<>()).status(200).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@SpringBootTest(classes = Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class ManuallyCreatedDelegateLoadBalancerFeignClientTests {
|
||||
|
||||
@@ -114,11 +113,10 @@ class Application {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnnotatedFeignClient annotatedFeignClient(Client client, Decoder decoder,
|
||||
Encoder encoder, Contract contract) {
|
||||
return Feign.builder().client(client).encoder(encoder).decoder(decoder)
|
||||
.contract(contract).target(new HardCodedTarget<>(
|
||||
AnnotatedFeignClient.class, "foo", "http://foo"));
|
||||
public AnnotatedFeignClient annotatedFeignClient(Client client, Decoder decoder, Encoder encoder,
|
||||
Contract contract) {
|
||||
return Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract)
|
||||
.target(new HardCodedTarget<>(AnnotatedFeignClient.class, "foo", "http://foo"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -146,9 +144,9 @@ class MyDelegateClient implements Client {
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options) {
|
||||
this.wasCalled = true;
|
||||
return Response.builder().body("foo", StandardCharsets.UTF_8)
|
||||
.request(Request.create(Request.HttpMethod.POST, "/foo", new HashMap<>(),
|
||||
Request.Body.empty(), new RequestTemplate()))
|
||||
return Response
|
||||
.builder().body("foo", StandardCharsets.UTF_8).request(Request.create(Request.HttpMethod.POST, "/foo",
|
||||
new HashMap<>(), Request.Body.empty(), new RequestTemplate()))
|
||||
.headers(new HashMap<>()).status(200).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,8 @@ public class Issue307Tests {
|
||||
|
||||
@Test
|
||||
public void should_start_context() {
|
||||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(
|
||||
SleuthSampleApplication.class, "--spring.jmx.enabled=false",
|
||||
"--server.port=0")) {
|
||||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(SleuthSampleApplication.class,
|
||||
"--spring.jmx.enabled=false", "--server.port=0")) {
|
||||
// code
|
||||
}
|
||||
}
|
||||
@@ -67,8 +66,7 @@ public class Issue307Tests {
|
||||
@EnableFeignClients
|
||||
class SleuthSampleApplication {
|
||||
|
||||
private static final Logger LOG = LoggerFactory
|
||||
.getLogger(SleuthSampleApplication.class.getName());
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SleuthSampleApplication.class.getName());
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@@ -55,8 +55,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@FeignClient(value = "myFeignClient", url = "http://localhost:9998",
|
||||
configuration = CustomConfig.class)
|
||||
@FeignClient(value = "myFeignClient", url = "http://localhost:9998", configuration = CustomConfig.class)
|
||||
interface MyFeignClient {
|
||||
|
||||
@RequestMapping("/service/ok")
|
||||
@@ -71,8 +70,7 @@ interface MyFeignClient {
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
|
||||
@SpringBootTest(classes = Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@TestPropertySource(properties = { "server.port=9998" })
|
||||
public class Issue362Tests {
|
||||
|
||||
@@ -97,12 +95,10 @@ public class Issue362Tests {
|
||||
public void should_successfully_work_with_custom_error_decoder_when_sending_successful_request() {
|
||||
String securedURl = "http://localhost:9998/sleuth/test-ok";
|
||||
|
||||
ResponseEntity<String> response = this.template.getForEntity(securedURl,
|
||||
String.class);
|
||||
ResponseEntity<String> response = this.template.getForEntity(securedURl, String.class);
|
||||
|
||||
then(response.getBody()).isEqualTo("I'm OK");
|
||||
then(this.feignComponentAsserter.executedComponents).containsEntry(Client.class,
|
||||
true);
|
||||
then(this.feignComponentAsserter.executedComponents).containsEntry(Client.class, true);
|
||||
then(this.spans).hasSize(1);
|
||||
then(this.spans.get(0).tags()).containsEntry("http.path", "/service/ok");
|
||||
}
|
||||
@@ -118,13 +114,12 @@ public class Issue362Tests {
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
then(this.feignComponentAsserter.executedComponents)
|
||||
.containsEntry(ErrorDecoder.class, true)
|
||||
then(this.feignComponentAsserter.executedComponents).containsEntry(ErrorDecoder.class, true)
|
||||
.containsEntry(Client.class, true);
|
||||
// retries
|
||||
then(this.spans).hasSize(5);
|
||||
then(this.spans.spans().stream().map(span -> span.tags().get("http.status_code"))
|
||||
.collect(Collectors.toList())).containsOnly("409");
|
||||
then(this.spans.spans().stream().map(span -> span.tags().get("http.status_code")).collect(Collectors.toList()))
|
||||
.containsOnly("409");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -205,8 +200,8 @@ class CustomConfig {
|
||||
public Exception decode(String methodKey, Response response) {
|
||||
this.feignComponentAsserter.executedComponents.put(ErrorDecoder.class, true);
|
||||
if (response.status() == 409) {
|
||||
return new RetryableException(response.status(), "Article not Ready",
|
||||
Request.HttpMethod.GET, new Date(), response.request());
|
||||
return new RetryableException(response.status(), "Article not Ready", Request.HttpMethod.GET,
|
||||
new Date(), response.request());
|
||||
}
|
||||
else {
|
||||
return super.decode(methodKey, response);
|
||||
@@ -225,8 +220,7 @@ class CustomConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options)
|
||||
throws IOException {
|
||||
public Response execute(Request request, Request.Options options) throws IOException {
|
||||
this.feignComponentAsserter.executedComponents.put(Client.class, true);
|
||||
return super.execute(request, options);
|
||||
}
|
||||
|
||||
@@ -56,10 +56,8 @@ interface MyNameRemote {
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
|
||||
@SpringBootTest(classes = Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@TestPropertySource(
|
||||
properties = { "spring.application.name=demo-feign-uri", "server.port=9978" })
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@TestPropertySource(properties = { "spring.application.name=demo-feign-uri", "server.port=9978" })
|
||||
public class Issue393Tests {
|
||||
|
||||
RestTemplate template = new RestTemplate();
|
||||
@@ -84,8 +82,8 @@ public class Issue393Tests {
|
||||
then(response.getBody()).isEqualTo("mikesarver foo");
|
||||
// retries
|
||||
then(this.spans).hasSize(2);
|
||||
then(this.spans.spans().stream().map(span -> span.tags().get("http.path"))
|
||||
.collect(Collectors.toList())).containsOnly("/name/mikesarver");
|
||||
then(this.spans.spans().stream().map(span -> span.tags().get("http.path")).collect(Collectors.toList()))
|
||||
.containsOnly("/name/mikesarver");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ interface MyNameRemote {
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@SpringBootTest(classes = Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
public class Issue502Tests {
|
||||
|
||||
@Autowired
|
||||
@@ -121,9 +120,9 @@ class MyClient implements Client {
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options) {
|
||||
this.wasCalled = true;
|
||||
return Response.builder().body("foo", StandardCharsets.UTF_8)
|
||||
.request(Request.create(Request.HttpMethod.POST, "/foo", new HashMap<>(),
|
||||
Request.Body.empty(), new RequestTemplate()))
|
||||
return Response
|
||||
.builder().body("foo", StandardCharsets.UTF_8).request(Request.create(Request.HttpMethod.POST, "/foo",
|
||||
new HashMap<>(), Request.Body.empty(), new RequestTemplate()))
|
||||
.headers(new HashMap<>()).status(200).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -85,14 +85,12 @@ public class GrpcTracingIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void integrationTest() throws Exception {
|
||||
ManagedChannel inProcessManagedChannel = this.clientManagedChannelBuilder
|
||||
.inProcessChannelBuilder("testServer").directExecutor().build();
|
||||
ManagedChannel inProcessManagedChannel = this.clientManagedChannelBuilder.inProcessChannelBuilder("testServer")
|
||||
.directExecutor().build();
|
||||
|
||||
HelloServiceGrpcClient client = new HelloServiceGrpcClient(
|
||||
inProcessManagedChannel);
|
||||
HelloServiceGrpcClient client = new HelloServiceGrpcClient(inProcessManagedChannel);
|
||||
|
||||
assertThat(client.sayHello("Testy McTest Face"))
|
||||
.isEqualTo("Hello Testy McTest Face");
|
||||
assertThat(client.sayHello("Testy McTest Face")).isEqualTo("Hello Testy McTest Face");
|
||||
assertThat(this.spans).hasSize(2);
|
||||
assertThat(this.spans.get(0).kind()).isEqualTo(Kind.SERVER);
|
||||
assertThat(this.spans.get(1).kind()).isEqualTo(Kind.CLIENT);
|
||||
@@ -164,8 +162,7 @@ public class GrpcTracingIntegrationTests {
|
||||
private Logger logger = LoggerFactory.getLogger(HelloGrpcService.class);
|
||||
|
||||
@Override
|
||||
public void sayHello(HelloRequest request,
|
||||
StreamObserver<HelloReply> responseObserver) {
|
||||
public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
|
||||
String message = "Hello " + request.getName();
|
||||
this.logger.debug("In the grpc server stub.");
|
||||
HelloReply reply = HelloReply.newBuilder().setMessage(message).build();
|
||||
@@ -191,11 +188,9 @@ public class GrpcTracingIntegrationTests {
|
||||
@Override
|
||||
public String sayHello(String name) throws Exception {
|
||||
|
||||
HelloServiceBlockingStub stub = HelloServiceGrpc
|
||||
.newBlockingStub(this.managedChannel)
|
||||
.withDeadlineAfter(3, TimeUnit.SECONDS);
|
||||
HelloReply reply = stub
|
||||
.sayHello(HelloRequest.newBuilder().setName(name).build());
|
||||
HelloServiceBlockingStub stub = HelloServiceGrpc.newBlockingStub(this.managedChannel).withDeadlineAfter(3,
|
||||
TimeUnit.SECONDS);
|
||||
HelloReply reply = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
|
||||
return reply.getMessage();
|
||||
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
throw new java.lang.NullPointerException();
|
||||
}
|
||||
int mutable_bitField0_ = 0;
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet
|
||||
.newBuilder();
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
@@ -81,8 +80,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
done = true;
|
||||
break;
|
||||
default:
|
||||
if (!parseUnknownFieldProto3(input, unknownFields, extensionRegistry,
|
||||
tag)) {
|
||||
if (!parseUnknownFieldProto3(input, unknownFields, extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
@@ -97,8 +95,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
throw e.setUnfinishedMessage(this);
|
||||
}
|
||||
catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(e)
|
||||
.setUnfinishedMessage(this);
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this);
|
||||
}
|
||||
finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
@@ -132,52 +129,40 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloReply parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
public static HelloReply parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
|
||||
public static HelloReply parseFrom(byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
public static HelloReply parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloReply parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
public static HelloReply parseFrom(java.io.InputStream input) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static HelloReply parseFrom(java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input,
|
||||
extensionRegistry);
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloReply parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
public static HelloReply parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static HelloReply parseDelimitedFrom(java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloReply parseFrom(com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
public static HelloReply parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static HelloReply parseFrom(com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input,
|
||||
extensionRegistry);
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static Builder newBuilder() {
|
||||
@@ -204,8 +189,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
@Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() {
|
||||
return HelloServiceOuterClass.internal_static_sample_grpc_HelloReply_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(HelloReply.class,
|
||||
HelloReply.Builder.class);
|
||||
.ensureFieldAccessorsInitialized(HelloReply.class, HelloReply.Builder.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,8 +216,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
public com.google.protobuf.ByteString getMessageBytes() {
|
||||
java.lang.Object ref = this.message_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString
|
||||
.copyFromUtf8((java.lang.String) ref);
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
|
||||
this.message_ = b;
|
||||
return b;
|
||||
}
|
||||
@@ -257,8 +240,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
|
||||
if (!getMessageBytes().isEmpty()) {
|
||||
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, this.message_);
|
||||
}
|
||||
@@ -274,8 +256,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
|
||||
size = 0;
|
||||
if (!getMessageBytes().isEmpty()) {
|
||||
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1,
|
||||
this.message_);
|
||||
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, this.message_);
|
||||
}
|
||||
size += this.unknownFields.getSerializedSize();
|
||||
this.memoizedSize = size;
|
||||
@@ -323,8 +304,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
@@ -346,8 +326,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
*
|
||||
* Protobuf type {@code HelloReply}
|
||||
*/
|
||||
public static final class Builder
|
||||
extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:HelloReply)
|
||||
HelloReplyOrBuilder {
|
||||
|
||||
@@ -370,8 +349,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
@Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() {
|
||||
return HelloServiceOuterClass.internal_static_sample_grpc_HelloReply_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(HelloReply.class,
|
||||
HelloReply.Builder.class);
|
||||
.ensureFieldAccessorsInitialized(HelloReply.class, HelloReply.Builder.class);
|
||||
}
|
||||
|
||||
private void maybeForceBuilderInitialization() {
|
||||
@@ -420,8 +398,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
|
||||
return super.setField(field, value);
|
||||
}
|
||||
|
||||
@@ -436,16 +413,13 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field, int index,
|
||||
public Builder setRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, int index,
|
||||
java.lang.Object value) {
|
||||
return super.setRepeatedField(field, index, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder addRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
|
||||
return super.addRepeatedField(field, value);
|
||||
}
|
||||
|
||||
@@ -480,8 +454,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
|
||||
@Override
|
||||
public Builder mergeFrom(com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
HelloReply parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
@@ -535,8 +508,7 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
public com.google.protobuf.ByteString getMessageBytes() {
|
||||
java.lang.Object ref = this.message_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString
|
||||
.copyFromUtf8((java.lang.String) ref);
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
|
||||
this.message_ = b;
|
||||
return b;
|
||||
}
|
||||
@@ -570,14 +542,12 @@ public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Builder setUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.setUnknownFieldsProto3(unknownFields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Builder mergeUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.mergeUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
throw new java.lang.NullPointerException();
|
||||
}
|
||||
int mutable_bitField0_ = 0;
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet
|
||||
.newBuilder();
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
@@ -79,8 +78,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
done = true;
|
||||
break;
|
||||
default:
|
||||
if (!parseUnknownFieldProto3(input, unknownFields, extensionRegistry,
|
||||
tag)) {
|
||||
if (!parseUnknownFieldProto3(input, unknownFields, extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
@@ -96,8 +94,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
throw e.setUnfinishedMessage(this);
|
||||
}
|
||||
catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(e)
|
||||
.setUnfinishedMessage(this);
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this);
|
||||
}
|
||||
finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
@@ -131,52 +128,40 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloRequest parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
public static HelloRequest parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
|
||||
public static HelloRequest parseFrom(byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
public static HelloRequest parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloRequest parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
public static HelloRequest parseFrom(java.io.InputStream input) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static HelloRequest parseFrom(java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input,
|
||||
extensionRegistry);
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloRequest parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
public static HelloRequest parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static HelloRequest parseDelimitedFrom(java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static HelloRequest parseFrom(com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
public static HelloRequest parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static HelloRequest parseFrom(com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input,
|
||||
extensionRegistry);
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static Builder newBuilder() {
|
||||
@@ -203,8 +188,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
@Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() {
|
||||
return HelloServiceOuterClass.internal_static_sample_grpc_HelloRequest_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(HelloRequest.class,
|
||||
HelloRequest.Builder.class);
|
||||
.ensureFieldAccessorsInitialized(HelloRequest.class, HelloRequest.Builder.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,8 +215,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
public com.google.protobuf.ByteString getNameBytes() {
|
||||
java.lang.Object ref = this.name_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString
|
||||
.copyFromUtf8((java.lang.String) ref);
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
|
||||
this.name_ = b;
|
||||
return b;
|
||||
}
|
||||
@@ -256,8 +239,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
|
||||
if (!getNameBytes().isEmpty()) {
|
||||
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, this.name_);
|
||||
}
|
||||
@@ -273,8 +255,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
|
||||
size = 0;
|
||||
if (!getNameBytes().isEmpty()) {
|
||||
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1,
|
||||
this.name_);
|
||||
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, this.name_);
|
||||
}
|
||||
size += this.unknownFields.getSerializedSize();
|
||||
this.memoizedSize = size;
|
||||
@@ -322,8 +303,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
@@ -345,8 +325,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
*
|
||||
* Protobuf type {@code HelloRequest}
|
||||
*/
|
||||
public static final class Builder
|
||||
extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:HelloRequest)
|
||||
HelloRequestOrBuilder {
|
||||
|
||||
@@ -369,8 +348,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
@Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() {
|
||||
return HelloServiceOuterClass.internal_static_sample_grpc_HelloRequest_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(HelloRequest.class,
|
||||
HelloRequest.Builder.class);
|
||||
.ensureFieldAccessorsInitialized(HelloRequest.class, HelloRequest.Builder.class);
|
||||
}
|
||||
|
||||
private void maybeForceBuilderInitialization() {
|
||||
@@ -419,8 +397,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
|
||||
return super.setField(field, value);
|
||||
}
|
||||
|
||||
@@ -435,16 +412,13 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field, int index,
|
||||
public Builder setRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, int index,
|
||||
java.lang.Object value) {
|
||||
return super.setRepeatedField(field, index, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder addRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
|
||||
return super.addRepeatedField(field, value);
|
||||
}
|
||||
|
||||
@@ -479,8 +453,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
|
||||
@Override
|
||||
public Builder mergeFrom(com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||
HelloRequest parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
@@ -534,8 +507,7 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
public com.google.protobuf.ByteString getNameBytes() {
|
||||
java.lang.Object ref = this.name_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString
|
||||
.copyFromUtf8((java.lang.String) ref);
|
||||
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
|
||||
this.name_ = b;
|
||||
return b;
|
||||
}
|
||||
@@ -569,14 +541,12 @@ public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 i
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Builder setUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.setUnknownFieldsProto3(unknownFields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Builder mergeUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.mergeUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
|
||||
* The Hello service definition.
|
||||
* </pre>
|
||||
*/
|
||||
@javax.annotation.Generated(value = "by gRPC proto compiler (version 1.15.1)",
|
||||
comments = "Source: HelloService.proto")
|
||||
@javax.annotation.Generated(value = "by gRPC proto compiler (version 1.15.1)", comments = "Source: HelloService.proto")
|
||||
public final class HelloServiceGrpc {
|
||||
|
||||
public static final String SERVICE_NAME = "HelloService";
|
||||
@@ -53,18 +52,14 @@ public final class HelloServiceGrpc {
|
||||
synchronized (HelloServiceGrpc.class) {
|
||||
if ((getSayHelloMethod = HelloServiceGrpc.getSayHelloMethod) == null) {
|
||||
HelloServiceGrpc.getSayHelloMethod = getSayHelloMethod = io.grpc.MethodDescriptor
|
||||
.<HelloRequest, HelloReply>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(
|
||||
generateFullMethodName("HelloService", "SayHello"))
|
||||
.<HelloRequest, HelloReply>newBuilder().setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName("HelloService", "SayHello"))
|
||||
.setSampledToLocalTracing(true)
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils
|
||||
.marshaller(HelloRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils
|
||||
.marshaller(HelloReply.getDefaultInstance()))
|
||||
.setSchemaDescriptor(
|
||||
new HelloServiceMethodDescriptorSupplier("SayHello"))
|
||||
.build();
|
||||
.setRequestMarshaller(
|
||||
io.grpc.protobuf.ProtoUtils.marshaller(HelloRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(
|
||||
io.grpc.protobuf.ProtoUtils.marshaller(HelloReply.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new HelloServiceMethodDescriptorSupplier("SayHello")).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,8 +94,7 @@ public final class HelloServiceGrpc {
|
||||
synchronized (HelloServiceGrpc.class) {
|
||||
result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
serviceDescriptor = result = io.grpc.ServiceDescriptor
|
||||
.newBuilder(SERVICE_NAME)
|
||||
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
|
||||
.setSchemaDescriptor(new HelloServiceFileDescriptorSupplier())
|
||||
.addMethod(getSayHelloMethod()).build();
|
||||
}
|
||||
@@ -121,8 +115,7 @@ public final class HelloServiceGrpc {
|
||||
* Sends a greeting
|
||||
* </pre>
|
||||
*/
|
||||
public void sayHello(HelloRequest request,
|
||||
io.grpc.stub.StreamObserver<HelloReply> responseObserver) {
|
||||
public void sayHello(HelloRequest request, io.grpc.stub.StreamObserver<HelloReply> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(getSayHelloMethod(), responseObserver);
|
||||
}
|
||||
|
||||
@@ -130,8 +123,7 @@ public final class HelloServiceGrpc {
|
||||
public final io.grpc.ServerServiceDefinition bindService() {
|
||||
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
|
||||
.addMethod(getSayHelloMethod(),
|
||||
asyncUnaryCall(new MethodHandlers<HelloRequest, HelloReply>(
|
||||
this, METHODID_SAY_HELLO)))
|
||||
asyncUnaryCall(new MethodHandlers<HelloRequest, HelloReply>(this, METHODID_SAY_HELLO)))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -142,21 +134,18 @@ public final class HelloServiceGrpc {
|
||||
* The Hello service definition.
|
||||
* </pre>
|
||||
*/
|
||||
public static final class HelloServiceStub
|
||||
extends io.grpc.stub.AbstractStub<HelloServiceStub> {
|
||||
public static final class HelloServiceStub extends io.grpc.stub.AbstractStub<HelloServiceStub> {
|
||||
|
||||
private HelloServiceStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private HelloServiceStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
private HelloServiceStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected HelloServiceStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
protected HelloServiceStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new HelloServiceStub(channel, callOptions);
|
||||
}
|
||||
|
||||
@@ -165,10 +154,8 @@ public final class HelloServiceGrpc {
|
||||
* Sends a greeting
|
||||
* </pre>
|
||||
*/
|
||||
public void sayHello(HelloRequest request,
|
||||
io.grpc.stub.StreamObserver<HelloReply> responseObserver) {
|
||||
asyncUnaryCall(getChannel().newCall(getSayHelloMethod(), getCallOptions()),
|
||||
request, responseObserver);
|
||||
public void sayHello(HelloRequest request, io.grpc.stub.StreamObserver<HelloReply> responseObserver) {
|
||||
asyncUnaryCall(getChannel().newCall(getSayHelloMethod(), getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -178,21 +165,18 @@ public final class HelloServiceGrpc {
|
||||
* The Hello service definition.
|
||||
* </pre>
|
||||
*/
|
||||
public static final class HelloServiceBlockingStub
|
||||
extends io.grpc.stub.AbstractStub<HelloServiceBlockingStub> {
|
||||
public static final class HelloServiceBlockingStub extends io.grpc.stub.AbstractStub<HelloServiceBlockingStub> {
|
||||
|
||||
private HelloServiceBlockingStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private HelloServiceBlockingStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
private HelloServiceBlockingStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected HelloServiceBlockingStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
protected HelloServiceBlockingStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new HelloServiceBlockingStub(channel, callOptions);
|
||||
}
|
||||
|
||||
@@ -202,8 +186,7 @@ public final class HelloServiceGrpc {
|
||||
* </pre>
|
||||
*/
|
||||
public HelloReply sayHello(HelloRequest request) {
|
||||
return blockingUnaryCall(getChannel(), getSayHelloMethod(), getCallOptions(),
|
||||
request);
|
||||
return blockingUnaryCall(getChannel(), getSayHelloMethod(), getCallOptions(), request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -213,21 +196,18 @@ public final class HelloServiceGrpc {
|
||||
* The Hello service definition.
|
||||
* </pre>
|
||||
*/
|
||||
public static final class HelloServiceFutureStub
|
||||
extends io.grpc.stub.AbstractStub<HelloServiceFutureStub> {
|
||||
public static final class HelloServiceFutureStub extends io.grpc.stub.AbstractStub<HelloServiceFutureStub> {
|
||||
|
||||
private HelloServiceFutureStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private HelloServiceFutureStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
private HelloServiceFutureStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected HelloServiceFutureStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
protected HelloServiceFutureStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new HelloServiceFutureStub(channel, callOptions);
|
||||
}
|
||||
|
||||
@@ -236,16 +216,13 @@ public final class HelloServiceGrpc {
|
||||
* Sends a greeting
|
||||
* </pre>
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<HelloReply> sayHello(
|
||||
HelloRequest request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(getSayHelloMethod(), getCallOptions()), request);
|
||||
public com.google.common.util.concurrent.ListenableFuture<HelloReply> sayHello(HelloRequest request) {
|
||||
return futureUnaryCall(getChannel().newCall(getSayHelloMethod(), getCallOptions()), request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class MethodHandlers<Req, Resp>
|
||||
implements io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
||||
private static final class MethodHandlers<Req, Resp> implements io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
|
||||
@@ -261,8 +238,7 @@ public final class HelloServiceGrpc {
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("unchecked")
|
||||
public void invoke(Req request,
|
||||
io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (this.methodId) {
|
||||
case METHODID_SAY_HELLO:
|
||||
this.serviceImpl.sayHello((HelloRequest) request,
|
||||
@@ -275,8 +251,7 @@ public final class HelloServiceGrpc {
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("unchecked")
|
||||
public io.grpc.stub.StreamObserver<Req> invoke(
|
||||
io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
public io.grpc.stub.StreamObserver<Req> invoke(io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (this.methodId) {
|
||||
default:
|
||||
throw new AssertionError();
|
||||
@@ -286,8 +261,7 @@ public final class HelloServiceGrpc {
|
||||
}
|
||||
|
||||
private static abstract class HelloServiceBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoFileDescriptorSupplier,
|
||||
io.grpc.protobuf.ProtoServiceDescriptorSupplier {
|
||||
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
|
||||
|
||||
HelloServiceBaseDescriptorSupplier() {
|
||||
}
|
||||
@@ -304,16 +278,14 @@ public final class HelloServiceGrpc {
|
||||
|
||||
}
|
||||
|
||||
private static final class HelloServiceFileDescriptorSupplier
|
||||
extends HelloServiceBaseDescriptorSupplier {
|
||||
private static final class HelloServiceFileDescriptorSupplier extends HelloServiceBaseDescriptorSupplier {
|
||||
|
||||
HelloServiceFileDescriptorSupplier() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class HelloServiceMethodDescriptorSupplier
|
||||
extends HelloServiceBaseDescriptorSupplier
|
||||
private static final class HelloServiceMethodDescriptorSupplier extends HelloServiceBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
|
||||
|
||||
private final String methodName;
|
||||
|
||||
@@ -26,12 +26,11 @@ public final class HelloServiceOuterClass {
|
||||
private static com.google.protobuf.Descriptors.FileDescriptor descriptor;
|
||||
|
||||
static {
|
||||
java.lang.String[] descriptorData = {
|
||||
"\n\022HelloService.proto\022\013sample.grpc\"\034\n\014Hel"
|
||||
+ "loRequest\022\014\n\004name\030\001 \001(\t\"\035\n\nHelloReply\022\017\n"
|
||||
+ "\007message\030\001 \001(\t2P\n\014HelloService\022@\n\010SayHel"
|
||||
+ "lo\022\031.sample.grpc.HelloRequest\032\027.sample.g"
|
||||
+ "rpc.HelloReply\"\000B\002P\001b\006proto3" };
|
||||
java.lang.String[] descriptorData = { "\n\022HelloService.proto\022\013sample.grpc\"\034\n\014Hel"
|
||||
+ "loRequest\022\014\n\004name\030\001 \001(\t\"\035\n\nHelloReply\022\017\n"
|
||||
+ "\007message\030\001 \001(\t2P\n\014HelloService\022@\n\010SayHel"
|
||||
+ "lo\022\031.sample.grpc.HelloRequest\032\027.sample.g"
|
||||
+ "rpc.HelloReply\"\000B\002P\001b\006proto3" };
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
@Override
|
||||
public com.google.protobuf.ExtensionRegistry assignDescriptors(
|
||||
@@ -40,30 +39,23 @@ public final class HelloServiceOuterClass {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(
|
||||
descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {},
|
||||
assigner);
|
||||
internal_static_sample_grpc_HelloRequest_descriptor = getDescriptor()
|
||||
.getMessageTypes().get(0);
|
||||
com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData,
|
||||
new com.google.protobuf.Descriptors.FileDescriptor[] {}, assigner);
|
||||
internal_static_sample_grpc_HelloRequest_descriptor = getDescriptor().getMessageTypes().get(0);
|
||||
internal_static_sample_grpc_HelloRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
internal_static_sample_grpc_HelloRequest_descriptor,
|
||||
new java.lang.String[] { "Name", });
|
||||
internal_static_sample_grpc_HelloReply_descriptor = getDescriptor()
|
||||
.getMessageTypes().get(1);
|
||||
internal_static_sample_grpc_HelloRequest_descriptor, new java.lang.String[] { "Name", });
|
||||
internal_static_sample_grpc_HelloReply_descriptor = getDescriptor().getMessageTypes().get(1);
|
||||
internal_static_sample_grpc_HelloReply_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
internal_static_sample_grpc_HelloReply_descriptor,
|
||||
new java.lang.String[] { "Message", });
|
||||
internal_static_sample_grpc_HelloReply_descriptor, new java.lang.String[] { "Message", });
|
||||
}
|
||||
|
||||
private HelloServiceOuterClass() {
|
||||
}
|
||||
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
}
|
||||
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistry registry) {
|
||||
public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {
|
||||
registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,16 +70,14 @@ public class TraceRedisAutoConfigurationTests {
|
||||
@Bean
|
||||
TestTraceLettuceClientResourcesBeanPostProcessor testTraceLettuceClientResourcesBeanPostProcessor(
|
||||
BeanFactory beanFactory, TraceRedisProperties traceRedisProperties) {
|
||||
return new TestTraceLettuceClientResourcesBeanPostProcessor(beanFactory,
|
||||
traceRedisProperties);
|
||||
return new TestTraceLettuceClientResourcesBeanPostProcessor(beanFactory, traceRedisProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestTraceLettuceClientResourcesBeanPostProcessor
|
||||
extends TraceLettuceClientResourcesBeanPostProcessor {
|
||||
class TestTraceLettuceClientResourcesBeanPostProcessor extends TraceLettuceClientResourcesBeanPostProcessor {
|
||||
|
||||
boolean tracingCalled = false;
|
||||
|
||||
@@ -89,8 +87,7 @@ class TestTraceLettuceClientResourcesBeanPostProcessor
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
this.tracingCalled = true;
|
||||
return super.postProcessAfterInitialization(bean, beanName);
|
||||
}
|
||||
|
||||
@@ -56,8 +56,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@SpringBootTest(classes = ITTracingChannelInterceptorTests.App.class,
|
||||
webEnvironment = WebEnvironment.NONE,
|
||||
@SpringBootTest(classes = ITTracingChannelInterceptorTests.App.class, webEnvironment = WebEnvironment.NONE,
|
||||
properties = "spring.sleuth.integration.enabled=true")
|
||||
@DirtiesContext
|
||||
public class ITTracingChannelInterceptorTests implements MessageHandler {
|
||||
@@ -104,8 +103,7 @@ public class ITTracingChannelInterceptorTests implements MessageHandler {
|
||||
// formerly known as TraceChannelInterceptorTest.executableSpanCreation
|
||||
@Test
|
||||
public void propagatesNoopSpan() {
|
||||
this.directChannel
|
||||
.send(MessageBuilder.withPayload("hi").setHeader("b3", "0").build());
|
||||
this.directChannel.send(MessageBuilder.withPayload("hi").setHeader("b3", "0").build());
|
||||
|
||||
assertThat(this.message.getHeaders()).containsEntry("b3", "0");
|
||||
|
||||
@@ -114,27 +112,21 @@ public class ITTracingChannelInterceptorTests implements MessageHandler {
|
||||
|
||||
@Test
|
||||
public void messageHeadersStillMutableForStomp() {
|
||||
this.directChannel.send(MessageBuilder.withPayload("hi")
|
||||
.setHeader("stompCommand", "DISCONNECT").build());
|
||||
this.directChannel.send(MessageBuilder.withPayload("hi").setHeader("stompCommand", "DISCONNECT").build());
|
||||
|
||||
assertThat(MessageHeaderAccessor.getAccessor(this.message,
|
||||
MessageHeaderAccessor.class)).isNotNull();
|
||||
assertThat(MessageHeaderAccessor.getAccessor(this.message, MessageHeaderAccessor.class)).isNotNull();
|
||||
|
||||
this.message = null;
|
||||
this.directChannel.send(MessageBuilder.withPayload("hi")
|
||||
.setHeader("simpMessageType", "sth").build());
|
||||
this.directChannel.send(MessageBuilder.withPayload("hi").setHeader("simpMessageType", "sth").build());
|
||||
|
||||
assertThat(MessageHeaderAccessor.getAccessor(this.message,
|
||||
MessageHeaderAccessor.class)).isNotNull();
|
||||
assertThat(MessageHeaderAccessor.getAccessor(this.message, MessageHeaderAccessor.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageHeadersImmutableForNonStomp() {
|
||||
this.directChannel
|
||||
.send(MessageBuilder.withPayload("hi").setHeader("foo", "bar").build());
|
||||
this.directChannel.send(MessageBuilder.withPayload("hi").setHeader("foo", "bar").build());
|
||||
|
||||
assertThat(MessageHeaderAccessor.getAccessor(this.message,
|
||||
MessageHeaderAccessor.class)).isNull();
|
||||
assertThat(MessageHeaderAccessor.getAccessor(this.message, MessageHeaderAccessor.class)).isNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -155,8 +147,8 @@ public class ITTracingChannelInterceptorTests implements MessageHandler {
|
||||
|
||||
@Bean
|
||||
Tracing tracing() {
|
||||
return Tracing.newBuilder().currentTraceContext(currentTraceContext())
|
||||
.addSpanHandler(testSpanHandler()).build();
|
||||
return Tracing.newBuilder().currentTraceContext(currentTraceContext()).addSpanHandler(testSpanHandler())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -56,9 +56,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class JmsTracingConfigurationTest {
|
||||
|
||||
final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(JmsTestTracingConfiguration.class,
|
||||
XAConfiguration.class, SimpleJmsListenerConfiguration.class));
|
||||
final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations
|
||||
.of(JmsTestTracingConfiguration.class, XAConfiguration.class, SimpleJmsListenerConfiguration.class));
|
||||
|
||||
static void checkConnection(AssertableApplicationContext ctx) throws JMSException {
|
||||
// Not using try-with-resources as that doesn't exist in JMS 1.1
|
||||
@@ -88,11 +87,9 @@ public class JmsTracingConfigurationTest {
|
||||
}
|
||||
}
|
||||
|
||||
static void checkTopicConnection(AssertableApplicationContext ctx)
|
||||
throws JMSException {
|
||||
static void checkTopicConnection(AssertableApplicationContext ctx) throws JMSException {
|
||||
// Not using try-with-resources as that doesn't exist in JMS 1.1
|
||||
TopicConnection con = ctx.getBean(TopicConnectionFactory.class)
|
||||
.createTopicConnection();
|
||||
TopicConnection con = ctx.getBean(TopicConnectionFactory.class).createTopicConnection();
|
||||
try {
|
||||
con.setExceptionListener(exception -> {
|
||||
});
|
||||
@@ -139,8 +136,7 @@ public class JmsTracingConfigurationTest {
|
||||
@EnableJms
|
||||
static class SimpleJmsListenerConfiguration implements JmsListenerConfigurer {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(SimpleJmsListenerConfiguration.class);
|
||||
private static final Log log = LogFactory.getLog(SimpleJmsListenerConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext current;
|
||||
@@ -159,8 +155,7 @@ public class JmsTracingConfigurationTest {
|
||||
return message -> {
|
||||
log.info("Got message");
|
||||
// Didn't restart the trace
|
||||
assertThat(current.get()).isNotNull()
|
||||
.extracting(TraceContext::parentIdAsLong).isNotEqualTo(0L);
|
||||
assertThat(current.get()).isNotNull().extracting(TraceContext::parentIdAsLong).isNotEqualTo(0L);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
/**
|
||||
* @author Tim te Beek
|
||||
*/
|
||||
@SpringBootTest(classes = SleuthKafkaStreamsConfigurationTest.Config.class,
|
||||
webEnvironment = WebEnvironment.NONE)
|
||||
@SpringBootTest(classes = SleuthKafkaStreamsConfigurationTest.Config.class, webEnvironment = WebEnvironment.NONE)
|
||||
public class SleuthKafkaStreamsConfigurationTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -38,8 +38,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(classes = StreamFunctionAdapterTests.Config.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SpringBootTest(classes = StreamFunctionAdapterTests.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
public class StreamFunctionAdapterTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -56,8 +55,7 @@ public class StreamFunctionAdapterTests {
|
||||
|
||||
@Test
|
||||
void should_instrument_a_simple_message_to_message_function() {
|
||||
assertThat(tracingChannelInterceptor)
|
||||
.as("Ensure that we're doing instrumentation via function wrapper")
|
||||
assertThat(tracingChannelInterceptor).as("Ensure that we're doing instrumentation via function wrapper")
|
||||
.isNull();
|
||||
|
||||
this.inputDestination.send(MessageBuilder.withPayload("hello".getBytes())
|
||||
@@ -69,8 +67,8 @@ public class StreamFunctionAdapterTests {
|
||||
String b3 = message.getHeaders().get("b3", String.class);
|
||||
assertThat(b3).startsWith("4883117762eb9420");
|
||||
|
||||
assertThat(this.handler.spans()).hasSize(3).extracting("kind")
|
||||
.containsOnly(Span.Kind.CONSUMER, null, Span.Kind.PRODUCER);
|
||||
assertThat(this.handler.spans()).hasSize(3).extracting("kind").containsOnly(Span.Kind.CONSUMER, null,
|
||||
Span.Kind.PRODUCER);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -99,8 +97,7 @@ class SimpleFunction implements Function<Message<String>, Message<String>> {
|
||||
@Override
|
||||
public Message<String> apply(Message<String> input) {
|
||||
log.info("Hello from simple [{}]", input);
|
||||
return MessageBuilder.createMessage(input.getPayload().toUpperCase(),
|
||||
input.getHeaders());
|
||||
return MessageBuilder.createMessage(input.getPayload().toUpperCase(), input.getHeaders());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(classes = StreamMessageOperatorsTests.Config.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SpringBootTest(classes = StreamMessageOperatorsTests.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
public class StreamMessageOperatorsTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -61,8 +60,7 @@ public class StreamMessageOperatorsTests {
|
||||
|
||||
@Test
|
||||
void should_instrument_a_simple_message_to_message_function() {
|
||||
assertThat(tracingChannelInterceptor)
|
||||
.as("Ensure that we're doing instrumentation via function wrapper")
|
||||
assertThat(tracingChannelInterceptor).as("Ensure that we're doing instrumentation via function wrapper")
|
||||
.isNull();
|
||||
|
||||
this.inputDestination.send(MessageBuilder.withPayload("hello".getBytes())
|
||||
@@ -74,8 +72,8 @@ public class StreamMessageOperatorsTests {
|
||||
String b3 = message.getHeaders().get("b3", String.class);
|
||||
assertThat(b3).startsWith("4883117762eb9420");
|
||||
|
||||
assertThat(this.handler.spans()).hasSize(3).extracting("kind")
|
||||
.containsOnly(Span.Kind.CONSUMER, null, Span.Kind.PRODUCER);
|
||||
assertThat(this.handler.spans()).hasSize(3).extracting("kind").containsOnly(Span.Kind.CONSUMER, null,
|
||||
Span.Kind.PRODUCER);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -97,11 +95,9 @@ public class StreamMessageOperatorsTests {
|
||||
|
||||
}
|
||||
|
||||
class SimpleReactiveManualFunction
|
||||
implements Function<Flux<Message<String>>, Flux<Message<String>>> {
|
||||
class SimpleReactiveManualFunction implements Function<Flux<Message<String>>, Flux<Message<String>>> {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SimpleReactiveManualFunction.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(SimpleReactiveManualFunction.class);
|
||||
|
||||
private final Tracing tracing;
|
||||
|
||||
@@ -111,29 +107,19 @@ class SimpleReactiveManualFunction
|
||||
|
||||
@Override
|
||||
public Flux<Message<String>> apply(Flux<Message<String>> input) {
|
||||
return input.map(
|
||||
message -> (MessagingSleuthOperators.asFunction(this.tracing, message))
|
||||
.andThen(msg -> MessagingSleuthOperators
|
||||
.withSpanInScope(this.tracing, msg, stringMessage -> {
|
||||
log.info("Hello from simple manual [{}]",
|
||||
stringMessage.getPayload());
|
||||
return stringMessage;
|
||||
}))
|
||||
.andThen(msg -> MessagingSleuthOperators
|
||||
.afterMessageHandled(this.tracing, msg, null))
|
||||
.andThen(msg -> {
|
||||
MessagingSleuthOperators.withSpanInScope(this.tracing, msg,
|
||||
stringMessage -> {
|
||||
log.info("Here we may do some processing");
|
||||
});
|
||||
Map<String, Object> headers = new HashMap<>(msg.getHeaders());
|
||||
headers.put("destination", "specialDestination");
|
||||
return MessageBuilder.createMessage(
|
||||
msg.getPayload().toUpperCase(),
|
||||
new MessageHeaders(headers));
|
||||
}).andThen(msg -> MessagingSleuthOperators
|
||||
.handleOutputMessage(this.tracing, msg))
|
||||
.apply(message));
|
||||
return input.map(message -> (MessagingSleuthOperators.asFunction(this.tracing, message))
|
||||
.andThen(msg -> MessagingSleuthOperators.withSpanInScope(this.tracing, msg, stringMessage -> {
|
||||
log.info("Hello from simple manual [{}]", stringMessage.getPayload());
|
||||
return stringMessage;
|
||||
})).andThen(msg -> MessagingSleuthOperators.afterMessageHandled(this.tracing, msg, null))
|
||||
.andThen(msg -> {
|
||||
MessagingSleuthOperators.withSpanInScope(this.tracing, msg, stringMessage -> {
|
||||
log.info("Here we may do some processing");
|
||||
});
|
||||
Map<String, Object> headers = new HashMap<>(msg.getHeaders());
|
||||
headers.put("destination", "specialDestination");
|
||||
return MessageBuilder.createMessage(msg.getPayload().toUpperCase(), new MessageHeaders(headers));
|
||||
}).andThen(msg -> MessagingSleuthOperators.handleOutputMessage(this.tracing, msg)).apply(message));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,8 +87,7 @@ public class TraceContextPropagationChannelInterceptorTests {
|
||||
// Trace and Span IDs are implicitly checked
|
||||
TraceContext extracted = B3SingleFormat.parseB3SingleFormat(b3).context();
|
||||
|
||||
assertThat(extracted.spanIdString()).as("spanId was equal to parent's id")
|
||||
.isNotEqualTo(expectedSpanId);
|
||||
assertThat(extracted.spanIdString()).as("spanId was equal to parent's id").isNotEqualTo(expectedSpanId);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -89,8 +89,7 @@ class MySleuthKafka1664Aspect extends SleuthKafkaAspect {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object wrapListenerContainerCreation(ProceedingJoinPoint pjp)
|
||||
throws Throwable {
|
||||
public Object wrapListenerContainerCreation(ProceedingJoinPoint pjp) throws Throwable {
|
||||
this.adapterWrapped = true;
|
||||
return Mockito.mock(MessageListenerContainer.class);
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ public class TraceMessagingAutoConfigurationTests {
|
||||
@Test
|
||||
public void defaultsToBraveProducerSampler() {
|
||||
contextRunner().run((context) -> {
|
||||
SamplerFunction<MessagingRequest> producerSampler = context
|
||||
.getBean(MessagingTracing.class).producerSampler();
|
||||
SamplerFunction<MessagingRequest> producerSampler = context.getBean(MessagingTracing.class)
|
||||
.producerSampler();
|
||||
|
||||
then(producerSampler).isSameAs(SamplerFunctions.deferDecision());
|
||||
});
|
||||
@@ -114,20 +114,19 @@ public class TraceMessagingAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void configuresUserProvidedProducerSampler() {
|
||||
contextRunner().withUserConfiguration(ProducerSamplerConfig.class)
|
||||
.run((context) -> {
|
||||
SamplerFunction<MessagingRequest> producerSampler = context
|
||||
.getBean(MessagingTracing.class).producerSampler();
|
||||
contextRunner().withUserConfiguration(ProducerSamplerConfig.class).run((context) -> {
|
||||
SamplerFunction<MessagingRequest> producerSampler = context.getBean(MessagingTracing.class)
|
||||
.producerSampler();
|
||||
|
||||
then(producerSampler).isSameAs(ProducerSamplerConfig.INSTANCE);
|
||||
});
|
||||
then(producerSampler).isSameAs(ProducerSamplerConfig.INSTANCE);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultsToBraveConsumerSampler() {
|
||||
contextRunner().run((context) -> {
|
||||
SamplerFunction<MessagingRequest> consumerSampler = context
|
||||
.getBean(MessagingTracing.class).consumerSampler();
|
||||
SamplerFunction<MessagingRequest> consumerSampler = context.getBean(MessagingTracing.class)
|
||||
.consumerSampler();
|
||||
|
||||
then(consumerSampler).isSameAs(SamplerFunctions.deferDecision());
|
||||
});
|
||||
@@ -135,19 +134,17 @@ public class TraceMessagingAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void configuresUserProvidedConsumerSampler() {
|
||||
contextRunner().withUserConfiguration(ConsumerSamplerConfig.class)
|
||||
.run((context) -> {
|
||||
SamplerFunction<MessagingRequest> consumerSampler = context
|
||||
.getBean(MessagingTracing.class).consumerSampler();
|
||||
contextRunner().withUserConfiguration(ConsumerSamplerConfig.class).run((context) -> {
|
||||
SamplerFunction<MessagingRequest> consumerSampler = context.getBean(MessagingTracing.class)
|
||||
.consumerSampler();
|
||||
|
||||
then(consumerSampler).isSameAs(ConsumerSamplerConfig.INSTANCE);
|
||||
});
|
||||
then(consumerSampler).isSameAs(ConsumerSamplerConfig.INSTANCE);
|
||||
});
|
||||
}
|
||||
|
||||
private ApplicationContextRunner contextRunner(String... propertyValues) {
|
||||
return new ApplicationContextRunner().withPropertyValues(propertyValues)
|
||||
.withConfiguration(AutoConfigurations.of(TraceAutoConfiguration.class,
|
||||
TraceMessagingAutoConfiguration.class));
|
||||
return new ApplicationContextRunner().withPropertyValues(propertyValues).withConfiguration(
|
||||
AutoConfigurations.of(TraceAutoConfiguration.class, TraceMessagingAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -165,8 +162,7 @@ public class TraceMessagingAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
SleuthRabbitBeanPostProcessor sleuthRabbitBeanPostProcessor(
|
||||
BeanFactory beanFactory) {
|
||||
SleuthRabbitBeanPostProcessor sleuthRabbitBeanPostProcessor(BeanFactory beanFactory) {
|
||||
return new TestSleuthRabbitBeanPostProcessor(beanFactory);
|
||||
}
|
||||
|
||||
@@ -176,8 +172,7 @@ public class TraceMessagingAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
TestSleuthJmsBeanPostProcessor sleuthJmsBeanPostProcessor(
|
||||
BeanFactory beanFactory) {
|
||||
TestSleuthJmsBeanPostProcessor sleuthJmsBeanPostProcessor(BeanFactory beanFactory) {
|
||||
return new TestSleuthJmsBeanPostProcessor(beanFactory);
|
||||
}
|
||||
|
||||
@@ -231,8 +226,7 @@ class MySleuthKafkaAspect extends SleuthKafkaAspect {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object wrapListenerContainerCreation(ProceedingJoinPoint pjp)
|
||||
throws Throwable {
|
||||
public Object wrapListenerContainerCreation(ProceedingJoinPoint pjp) throws Throwable {
|
||||
this.adapterWrapped = true;
|
||||
return Mockito.mock(MessageListenerContainer.class);
|
||||
}
|
||||
@@ -248,8 +242,7 @@ class TestSleuthJmsBeanPostProcessor extends TracingConnectionFactoryBeanPostPro
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
this.tracingCalled = true;
|
||||
return super.postProcessAfterInitialization(bean, beanName);
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootTest(classes = TraceStreamChannelInterceptorTests.App.class,
|
||||
properties = { "spring.cloud.stream.source=testSupplier",
|
||||
"spring.sleuth.integration.enabled=true" })
|
||||
properties = { "spring.cloud.stream.source=testSupplier", "spring.sleuth.integration.enabled=true" })
|
||||
@DirtiesContext
|
||||
public class TraceStreamChannelInterceptorTests {
|
||||
|
||||
@@ -90,8 +89,7 @@ public class TraceStreamChannelInterceptorTests {
|
||||
// Trace and Span IDs are implicitly checked
|
||||
TraceContext extracted = B3SingleFormat.parseB3SingleFormat(b3).context();
|
||||
|
||||
assertThat(extracted.spanIdString()).as("spanId was equal to parent's id")
|
||||
.isNotEqualTo(expectedSpanId);
|
||||
assertThat(extracted.spanIdString()).as("spanId was equal to parent's id").isNotEqualTo(expectedSpanId);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -43,15 +43,12 @@ public class TraceWebSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void should_register_interceptors_for_all_channels() {
|
||||
then(this.delegatingWebSocketMessageBrokerConfiguration.clientInboundChannel()
|
||||
.getInterceptors())
|
||||
.hasAtLeastOneElementOfType(TracingChannelInterceptor.class);
|
||||
then(this.delegatingWebSocketMessageBrokerConfiguration.clientOutboundChannel()
|
||||
.getInterceptors())
|
||||
.hasAtLeastOneElementOfType(TracingChannelInterceptor.class);
|
||||
then(this.delegatingWebSocketMessageBrokerConfiguration.brokerChannel()
|
||||
.getInterceptors())
|
||||
.hasAtLeastOneElementOfType(TracingChannelInterceptor.class);
|
||||
then(this.delegatingWebSocketMessageBrokerConfiguration.clientInboundChannel().getInterceptors())
|
||||
.hasAtLeastOneElementOfType(TracingChannelInterceptor.class);
|
||||
then(this.delegatingWebSocketMessageBrokerConfiguration.clientOutboundChannel().getInterceptors())
|
||||
.hasAtLeastOneElementOfType(TracingChannelInterceptor.class);
|
||||
then(this.delegatingWebSocketMessageBrokerConfiguration.brokerChannel().getInterceptors())
|
||||
.hasAtLeastOneElementOfType(TracingChannelInterceptor.class);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -30,8 +30,7 @@ import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class })
|
||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
|
||||
@ImportResource("classpath:beans/applicationContext.xml")
|
||||
@EnableIntegration
|
||||
@EnableAsync
|
||||
|
||||
@@ -35,14 +35,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class HelloWorldRestController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory
|
||||
.getLogger(HelloWorldRestController.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HelloWorldRestController.class);
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@RequestMapping(path = "getHelloWorldMessage", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(path = "getHelloWorldMessage", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public ResponseEntity<String> getHelloWorld() throws Exception {
|
||||
|
||||
LOG.info("Inside getHelloWorldMessage");
|
||||
@@ -52,11 +50,9 @@ public class HelloWorldRestController {
|
||||
requestMessage[1] = "Hellow World Message 2";
|
||||
requestMessage[2] = "Hellow World Message 3";
|
||||
|
||||
PollableChannel outputChannel = (PollableChannel) this.applicationContext
|
||||
.getBean("messagingOutputChannel");
|
||||
PollableChannel outputChannel = (PollableChannel) this.applicationContext.getBean("messagingOutputChannel");
|
||||
|
||||
MessagingGateway messagingGateway = (MessagingGateway) this.applicationContext
|
||||
.getBean("messagingGateway");
|
||||
MessagingGateway messagingGateway = (MessagingGateway) this.applicationContext.getBean("messagingGateway");
|
||||
|
||||
messagingGateway.processMessage(requestMessage);
|
||||
|
||||
|
||||
@@ -38,24 +38,19 @@ public class Issue943Tests {
|
||||
|
||||
@Test
|
||||
public void should_pass_tracing_context_via_spring_integration() {
|
||||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(
|
||||
HelloSpringIntegration.class, "--spring.jmx.enabled=false",
|
||||
"--server.port=0", "--spring.sleuth.integration.enabled=true")) {
|
||||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(HelloSpringIntegration.class,
|
||||
"--spring.jmx.enabled=false", "--server.port=0", "--spring.sleuth.integration.enabled=true")) {
|
||||
// given
|
||||
Tracer tracer = applicationContext.getBean(Tracer.class);
|
||||
Span newSpan = tracer.nextSpan().name("foo").start();
|
||||
String object;
|
||||
try (Tracer.SpanInScope ws = tracer.withSpanInScope(newSpan)) {
|
||||
RestTemplate restTemplate = applicationContext
|
||||
.getBean(RestTemplate.class);
|
||||
RestTemplate restTemplate = applicationContext.getBean(RestTemplate.class);
|
||||
// when
|
||||
object = restTemplate
|
||||
.getForObject(
|
||||
"http://localhost:"
|
||||
+ applicationContext.getEnvironment()
|
||||
.getProperty("local.server.port")
|
||||
+ "/getHelloWorldMessage",
|
||||
String.class);
|
||||
object = restTemplate.getForObject(
|
||||
"http://localhost:" + applicationContext.getEnvironment().getProperty("local.server.port")
|
||||
+ "/getHelloWorldMessage",
|
||||
String.class);
|
||||
}
|
||||
|
||||
// then
|
||||
@@ -63,15 +58,11 @@ public class Issue943Tests {
|
||||
then(object).contains("Hellow World Message 1 Persist into DB")
|
||||
.contains("Hellow World Message 2 Persist into DB")
|
||||
.contains("Hellow World Message 3 Persist into DB");
|
||||
then(spans.spans().stream().filter(
|
||||
span -> span.traceId().equals(newSpan.context().traceIdString()))
|
||||
.map(span -> span.tags().getOrDefault("channel",
|
||||
span.tags().get("http.path")))
|
||||
.collect(Collectors.toList()))
|
||||
.as("trace context was propagated successfully").isNotEmpty()
|
||||
.contains("splitterOutChannel", "messagingChannel",
|
||||
"messagingProcessedChannel", "messagingOutputChannel",
|
||||
"/getHelloWorldMessage");
|
||||
then(spans.spans().stream().filter(span -> span.traceId().equals(newSpan.context().traceIdString()))
|
||||
.map(span -> span.tags().getOrDefault("channel", span.tags().get("http.path")))
|
||||
.collect(Collectors.toList())).as("trace context was propagated successfully").isNotEmpty()
|
||||
.contains("splitterOutChannel", "messagingChannel", "messagingProcessedChannel",
|
||||
"messagingOutputChannel", "/getHelloWorldMessage");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@ public final class SpanUtil {
|
||||
throw new IllegalStateException("Can't instantiate a utility class");
|
||||
}
|
||||
|
||||
static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
// Represents given long id as 16-character lower-hex string
|
||||
public static String idToHex(long id) {
|
||||
|
||||
@@ -45,8 +45,7 @@ public abstract class AbstractMvcIntegrationTest {
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
DefaultMockMvcBuilder mockMvcBuilder = MockMvcBuilders
|
||||
.webAppContextSetup(this.webApplicationContext);
|
||||
DefaultMockMvcBuilder mockMvcBuilder = MockMvcBuilders.webAppContextSetup(this.webApplicationContext);
|
||||
configureMockMvcBuilder(mockMvcBuilder);
|
||||
this.mockMvc = mockMvcBuilder.build();
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@SpringBootTest(
|
||||
classes = { TraceAsyncIntegrationTests.TraceAsyncITestConfiguration.class })
|
||||
@SpringBootTest(classes = { TraceAsyncIntegrationTests.TraceAsyncITestConfiguration.class })
|
||||
public class TraceAsyncIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@@ -118,15 +117,14 @@ public class TraceAsyncIntegrationTests {
|
||||
|
||||
private void thenTraceIdIsPassedFromTheCurrentThreadToTheAsyncOne(final Span span) {
|
||||
Awaitility.await().atMost(5, SECONDS).untilAsserted(() -> {
|
||||
then(TraceAsyncIntegrationTests.this.classPerformingAsyncLogic.getSpan()
|
||||
.context().traceId()).isEqualTo(span.context().traceId());
|
||||
then(TraceAsyncIntegrationTests.this.classPerformingAsyncLogic.getSpan().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.spans).hasSize(2);
|
||||
// HTTP
|
||||
then(this.spans.get(0).name()).isEqualTo("http:existing");
|
||||
// ASYNC
|
||||
then(this.spans.get(1).tags())
|
||||
.containsEntry("class", "ClassPerformingAsyncLogic")
|
||||
.containsEntry("method", "invokeAsynchronousLogic");
|
||||
then(this.spans.get(1).tags()).containsEntry("class", "ClassPerformingAsyncLogic").containsEntry("method",
|
||||
"invokeAsynchronousLogic");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,23 +133,21 @@ public class TraceAsyncIntegrationTests {
|
||||
then(this.spans).hasSize(1);
|
||||
MutableSpan storedSpan = this.spans.get(0);
|
||||
then(storedSpan.name()).isEqualTo("invoke-asynchronous-logic");
|
||||
then(storedSpan.tags()).containsEntry("class", "ClassPerformingAsyncLogic")
|
||||
.containsEntry("method", "invokeAsynchronousLogic");
|
||||
then(storedSpan.tags()).containsEntry("class", "ClassPerformingAsyncLogic").containsEntry("method",
|
||||
"invokeAsynchronousLogic");
|
||||
});
|
||||
}
|
||||
|
||||
private void thenTraceIdIsPassedFromTheCurrentThreadToTheAsyncOneAndSpanHasCustomName(
|
||||
final Span span) {
|
||||
private void thenTraceIdIsPassedFromTheCurrentThreadToTheAsyncOneAndSpanHasCustomName(final Span span) {
|
||||
Awaitility.await().atMost(5, SECONDS).untilAsserted(() -> {
|
||||
then(TraceAsyncIntegrationTests.this.classPerformingAsyncLogic.getSpan()
|
||||
.context().traceId()).isEqualTo(span.context().traceId());
|
||||
then(TraceAsyncIntegrationTests.this.classPerformingAsyncLogic.getSpan().context().traceId())
|
||||
.isEqualTo(span.context().traceId());
|
||||
then(this.spans).hasSize(2);
|
||||
// HTTP
|
||||
then(this.spans.get(0).name()).isEqualTo("http:existing");
|
||||
// ASYNC
|
||||
then(this.spans.get(1).tags())
|
||||
.containsEntry("class", "ClassPerformingAsyncLogic")
|
||||
.containsEntry("method", "customNameInvokeAsynchronousLogic");
|
||||
then(this.spans.get(1).tags()).containsEntry("class", "ClassPerformingAsyncLogic").containsEntry("method",
|
||||
"customNameInvokeAsynchronousLogic");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -160,8 +156,8 @@ public class TraceAsyncIntegrationTests {
|
||||
then(this.spans).hasSize(1);
|
||||
MutableSpan storedSpan = this.spans.get(0);
|
||||
then(storedSpan.name()).isEqualTo("foo");
|
||||
then(storedSpan.tags()).containsEntry("class", "ClassPerformingAsyncLogic")
|
||||
.containsEntry("method", "customNameInvokeAsynchronousLogic");
|
||||
then(storedSpan.tags()).containsEntry("class", "ClassPerformingAsyncLogic").containsEntry("method",
|
||||
"customNameInvokeAsynchronousLogic");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ import static brave.propagation.B3SingleFormat.writeB3SingleFormat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@SpringBootTest(classes = TraceCustomFilterResponseInjectorTests.Config.class,
|
||||
webEnvironment = RANDOM_PORT)
|
||||
@SpringBootTest(classes = TraceCustomFilterResponseInjectorTests.Config.class, webEnvironment = RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
public class TraceCustomFilterResponseInjectorTests {
|
||||
|
||||
@@ -74,15 +73,12 @@ public class TraceCustomFilterResponseInjectorTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void should_inject_trace_and_span_ids_in_response_headers() {
|
||||
RequestEntity<?> requestEntity = RequestEntity
|
||||
.get(URI.create("http://localhost:" + this.config.port + "/headers"))
|
||||
.build();
|
||||
.get(URI.create("http://localhost:" + this.config.port + "/headers")).build();
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> responseEntity = this.restTemplate.exchange(requestEntity,
|
||||
Map.class);
|
||||
ResponseEntity<Map> responseEntity = this.restTemplate.exchange(requestEntity, Map.class);
|
||||
|
||||
then(responseEntity.getHeaders()).containsKey("b3")
|
||||
.as("Trace headers must be present in response headers");
|
||||
then(responseEntity.getHeaders()).containsKey("b3").as("Trace headers must be present in response headers");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -94,14 +90,13 @@ public class TraceCustomFilterResponseInjectorTests {
|
||||
@Bean
|
||||
BaggagePropagation.FactoryBuilder baggagePropagationFactoryBuilder() {
|
||||
// Use b3 single format as it is less verbose
|
||||
return BaggagePropagation.newFactoryBuilder(B3Propagation.newFactoryBuilder()
|
||||
.injectFormat(CLIENT, SINGLE_NO_PARENT).build());
|
||||
return BaggagePropagation.newFactoryBuilder(
|
||||
B3Propagation.newFactoryBuilder().injectFormat(CLIENT, SINGLE_NO_PARENT).build());
|
||||
}
|
||||
|
||||
// tag::configuration[]
|
||||
@Bean
|
||||
HttpResponseInjectingTraceFilter responseInjectingTraceFilter(
|
||||
HttpTracing httpTracing) {
|
||||
HttpResponseInjectingTraceFilter responseInjectingTraceFilter(HttpTracing httpTracing) {
|
||||
return new HttpResponseInjectingTraceFilter(httpTracing);
|
||||
}
|
||||
// end::configuration[]
|
||||
@@ -133,8 +128,8 @@ public class TraceCustomFilterResponseInjectorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse servletResponse,
|
||||
FilterChain filterChain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse servletResponse, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
Span currentSpan = this.httpTracing.tracing().tracer().currentSpan();
|
||||
response.addHeader("b3", writeB3SingleFormat(currentSpan.context()));
|
||||
|
||||
@@ -103,8 +103,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_ignore_sampling_the_span_if_uri_matches_management_properties_context_path()
|
||||
throws Exception {
|
||||
public void should_ignore_sampling_the_span_if_uri_matches_management_properties_context_path() throws Exception {
|
||||
MvcResult mvcResult = whenSentInfoWithTraceId(new Random().nextLong());
|
||||
|
||||
// https://github.com/spring-cloud/spring-cloud-sleuth/issues/327
|
||||
@@ -142,23 +141,20 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
Long expectedTraceId = new Random().nextLong();
|
||||
|
||||
MvcResult mvcResult = whenSentFutureWithTraceId(expectedTraceId);
|
||||
this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk())
|
||||
.andReturn();
|
||||
this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andReturn();
|
||||
|
||||
then(this.tracer.currentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_add_a_custom_tag_to_the_span_created_in_controller()
|
||||
throws Exception {
|
||||
public void should_add_a_custom_tag_to_the_span_created_in_controller() throws Exception {
|
||||
Long expectedTraceId = new Random().nextLong();
|
||||
|
||||
MvcResult mvcResult = whenSentDeferredWithTraceId(expectedTraceId);
|
||||
this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk())
|
||||
.andReturn();
|
||||
this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andReturn();
|
||||
|
||||
Optional<MutableSpan> taggedSpan = this.spans.spans().stream()
|
||||
.filter(span -> span.tags().containsKey("tag")).findFirst();
|
||||
Optional<MutableSpan> taggedSpan = this.spans.spans().stream().filter(span -> span.tags().containsKey("tag"))
|
||||
.findFirst();
|
||||
then(taggedSpan.isPresent()).isTrue();
|
||||
then(taggedSpan.get().tags()).containsEntry("tag", "value")
|
||||
.containsEntry("mvc.controller.method", "deferredMethod")
|
||||
@@ -167,8 +163,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_log_tracing_information_when_404_exception_was_thrown()
|
||||
throws Exception {
|
||||
public void should_log_tracing_information_when_404_exception_was_thrown() throws Exception {
|
||||
Long expectedTraceId = new Random().nextLong();
|
||||
|
||||
whenSentToNonExistentEndpointWithTraceId(expectedTraceId);
|
||||
@@ -176,14 +171,12 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
// it's a span with the same ids
|
||||
then(this.spans).hasSize(1);
|
||||
MutableSpan serverSpan = this.spans.get(0);
|
||||
then(serverSpan.tags()).containsEntry("custom", "tag")
|
||||
.containsEntry("http.status_code", "404");
|
||||
then(serverSpan.tags()).containsEntry("custom", "tag").containsEntry("http.status_code", "404");
|
||||
then(this.tracer.currentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_log_tracing_information_when_500_exception_was_thrown()
|
||||
throws Exception {
|
||||
public void should_log_tracing_information_when_500_exception_was_thrown() throws Exception {
|
||||
Long expectedTraceId = new Random().nextLong();
|
||||
|
||||
try {
|
||||
@@ -197,32 +190,29 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
// we need to dump the span cause it's not in TracingFilter since TF
|
||||
// has also error dispatch and the ErrorController would report the span
|
||||
then(this.spans).hasSize(1);
|
||||
then(this.spans.get(0).error()).hasMessageContaining(
|
||||
"Request processing failed; nested exception is java.lang.RuntimeException");
|
||||
then(this.spans.get(0).error())
|
||||
.hasMessageContaining("Request processing failed; nested exception is java.lang.RuntimeException");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_assume_that_a_request_without_span_and_with_trace_is_a_root_span()
|
||||
throws Exception {
|
||||
public void should_assume_that_a_request_without_span_and_with_trace_is_a_root_span() throws Exception {
|
||||
Long expectedTraceId = new Random().nextLong();
|
||||
|
||||
whenSentRequestWithTraceIdAndNoSpanId(expectedTraceId);
|
||||
whenSentRequestWithTraceIdAndNoSpanId(expectedTraceId);
|
||||
|
||||
then(this.spans.spans().stream().filter(span -> span.id().equals(span.traceId()))
|
||||
.findAny().isPresent()).as("a root span exists").isTrue();
|
||||
then(this.spans.spans().stream().filter(span -> span.id().equals(span.traceId())).findAny().isPresent())
|
||||
.as("a root span exists").isTrue();
|
||||
then(this.tracer.currentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_custom_response_headers_when_custom_trace_filter_gets_registered()
|
||||
throws Exception {
|
||||
public void should_return_custom_response_headers_when_custom_trace_filter_gets_registered() throws Exception {
|
||||
Long expectedTraceId = new Random().nextLong();
|
||||
|
||||
MvcResult mvcResult = whenSentPingWithTraceId(expectedTraceId);
|
||||
|
||||
then(mvcResult.getResponse().getHeader("ZIPKIN-TRACE-ID"))
|
||||
.isEqualTo(SpanUtil.idToHex(expectedTraceId));
|
||||
then(mvcResult.getResponse().getHeader("ZIPKIN-TRACE-ID")).isEqualTo(SpanUtil.idToHex(expectedTraceId));
|
||||
then(this.spans).hasSize(1);
|
||||
then(this.spans.get(0).tags()).containsEntry("custom", "tag");
|
||||
}
|
||||
@@ -233,9 +223,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
}
|
||||
|
||||
private MvcResult whenSentPingWithoutTracingData() throws Exception {
|
||||
return this.mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/ping").accept(MediaType.TEXT_PLAIN))
|
||||
.andReturn();
|
||||
return this.mockMvc.perform(MockMvcRequestBuilders.get("/ping").accept(MediaType.TEXT_PLAIN)).andReturn();
|
||||
}
|
||||
|
||||
private MvcResult whenSentPingWithTraceId(Long passedTraceId) throws Exception {
|
||||
@@ -254,16 +242,12 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
return sendDeferredWithTraceId(passedTraceId);
|
||||
}
|
||||
|
||||
private MvcResult whenSentToNonExistentEndpointWithTraceId(Long passedTraceId)
|
||||
throws Exception {
|
||||
return sendRequestWithTraceId("/exception/nonExistent", passedTraceId,
|
||||
HttpStatus.NOT_FOUND);
|
||||
private MvcResult whenSentToNonExistentEndpointWithTraceId(Long passedTraceId) throws Exception {
|
||||
return sendRequestWithTraceId("/exception/nonExistent", passedTraceId, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
private MvcResult whenSentToExceptionThrowingEndpoint(Long passedTraceId)
|
||||
throws Exception {
|
||||
return sendRequestWithTraceId("/throwsException", passedTraceId,
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
private MvcResult whenSentToExceptionThrowingEndpoint(Long passedTraceId) throws Exception {
|
||||
return sendRequestWithTraceId("/throwsException", passedTraceId, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
private MvcResult sendPingWithTraceId(Long traceId) throws Exception {
|
||||
@@ -275,28 +259,19 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
}
|
||||
|
||||
private MvcResult sendRequestWithTraceId(String path, Long traceId) throws Exception {
|
||||
return this.mockMvc
|
||||
.perform(MockMvcRequestBuilders.get(path).accept(MediaType.TEXT_PLAIN)
|
||||
.header("b3",
|
||||
SpanUtil.idToHex(traceId) + "-"
|
||||
+ SpanUtil.idToHex(new Random().nextLong())))
|
||||
.andReturn();
|
||||
return this.mockMvc.perform(MockMvcRequestBuilders.get(path).accept(MediaType.TEXT_PLAIN).header("b3",
|
||||
SpanUtil.idToHex(traceId) + "-" + SpanUtil.idToHex(new Random().nextLong()))).andReturn();
|
||||
}
|
||||
|
||||
private MvcResult whenSentRequestWithTraceIdAndNoSpanId(Long traceId)
|
||||
throws Exception {
|
||||
return this.mockMvc.perform(MockMvcRequestBuilders.get("/ping")
|
||||
.accept(MediaType.TEXT_PLAIN).header("b3", SpanUtil.idToHex(traceId)))
|
||||
.andReturn();
|
||||
private MvcResult whenSentRequestWithTraceIdAndNoSpanId(Long traceId) throws Exception {
|
||||
return this.mockMvc.perform(MockMvcRequestBuilders.get("/ping").accept(MediaType.TEXT_PLAIN).header("b3",
|
||||
SpanUtil.idToHex(traceId))).andReturn();
|
||||
}
|
||||
|
||||
private MvcResult sendRequestWithTraceId(String path, Long traceId, HttpStatus status)
|
||||
throws Exception {
|
||||
private MvcResult sendRequestWithTraceId(String path, Long traceId, HttpStatus status) throws Exception {
|
||||
return this.mockMvc
|
||||
.perform(MockMvcRequestBuilders.get(path).accept(MediaType.TEXT_PLAIN)
|
||||
.header("b3",
|
||||
SpanUtil.idToHex(traceId) + "-"
|
||||
+ SpanUtil.idToHex(new Random().nextLong())))
|
||||
.perform(MockMvcRequestBuilders.get(path).accept(MediaType.TEXT_PLAIN).header("b3",
|
||||
SpanUtil.idToHex(traceId) + "-" + SpanUtil.idToHex(new Random().nextLong())))
|
||||
.andExpect(status().is(status.value())).andReturn();
|
||||
}
|
||||
|
||||
@@ -369,8 +344,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
@Primary
|
||||
ManagementServerProperties managementServerProperties() {
|
||||
ManagementServerProperties managementServerProperties = new ManagementServerProperties();
|
||||
managementServerProperties.getServlet()
|
||||
.setContextPath("/additionalContextPath");
|
||||
managementServerProperties.getServlet().setContextPath("/additionalContextPath");
|
||||
return managementServerProperties;
|
||||
}
|
||||
|
||||
@@ -392,16 +366,15 @@ class MyFilter extends GenericFilterBean {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
Span currentSpan = this.tracer.currentSpan();
|
||||
if (currentSpan == null) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
// for readability we're returning trace id in a hex form
|
||||
((HttpServletResponse) response).addHeader("ZIPKIN-TRACE-ID",
|
||||
currentSpan.context().traceIdString());
|
||||
((HttpServletResponse) response).addHeader("ZIPKIN-TRACE-ID", currentSpan.context().traceIdString());
|
||||
// we can also add some custom tags
|
||||
currentSpan.tag("custom", "tag");
|
||||
chain.doFilter(request, response);
|
||||
|
||||
@@ -170,8 +170,8 @@ public class TraceFilterWebIntegrationMultipleFiltersTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
Span currentSpan = this.tracer.tracer().currentSpan();
|
||||
this.span.set(currentSpan);
|
||||
}
|
||||
|
||||
@@ -76,8 +76,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
@ClassRule
|
||||
public static IntegrationTestSpanHandler spanHandler = new IntegrationTestSpanHandler();
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(TraceFilterWebIntegrationTests.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(TraceFilterWebIntegrationTests.class);
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
@@ -91,8 +90,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void should_tag_url() {
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/good",
|
||||
String.class);
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/good", String.class);
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(spanHandler.takeRemoteSpan(Kind.SERVER).tags()).containsKey("http.url");
|
||||
@@ -100,8 +98,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void should_tag_with_value_from_null_expression() {
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/null-parameter",
|
||||
String.class);
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/null-parameter", String.class);
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(spanHandler.takeRemoteSpan(Kind.SERVER).tags()).containsEntry("foo", "1001");
|
||||
@@ -109,50 +106,42 @@ public class TraceFilterWebIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void should_tag_with_value_from_non_null_expression() {
|
||||
new RestTemplate().getForObject(
|
||||
"http://localhost:" + port() + "/null-parameter?bar=10", String.class);
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/null-parameter?bar=10", String.class);
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(spanHandler.takeRemoteSpan(Kind.SERVER).tags()).containsEntry("foo", "11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exception_logging_span_handler_logs_synchronous_exceptions(
|
||||
CapturedOutput capture) {
|
||||
public void exception_logging_span_handler_logs_synchronous_exceptions(CapturedOutput capture) {
|
||||
try {
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/",
|
||||
String.class);
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/", String.class);
|
||||
BDDAssertions.fail("should fail due to runtime exception");
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
MutableSpan fromFirstTraceFilterFlow = spanHandler.takeRemoteSpanWithErrorMessage(
|
||||
Kind.SERVER,
|
||||
MutableSpan fromFirstTraceFilterFlow = spanHandler.takeRemoteSpanWithErrorMessage(Kind.SERVER,
|
||||
"Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception");
|
||||
then(fromFirstTraceFilterFlow.tags()).containsEntry("http.method", "GET")
|
||||
.containsEntry("mvc.controller.class", "BasicErrorController");
|
||||
then(fromFirstTraceFilterFlow.tags()).containsEntry("http.method", "GET").containsEntry("mvc.controller.class",
|
||||
"BasicErrorController");
|
||||
// Trace IDs in logs: issue#714
|
||||
String hex = fromFirstTraceFilterFlow.traceId();
|
||||
thenLogsForExceptionLoggingFilterContainTracingInformation(capture, hex);
|
||||
}
|
||||
|
||||
private void thenLogsForExceptionLoggingFilterContainTracingInformation(
|
||||
CapturedOutput capture, String hex) {
|
||||
private void thenLogsForExceptionLoggingFilterContainTracingInformation(CapturedOutput capture, String hex) {
|
||||
String[] split = capture.toString().split("\n");
|
||||
List<String> list = Arrays.stream(split)
|
||||
.filter(s -> s.contains("Uncaught exception thrown"))
|
||||
.filter(s -> s.contains(hex + "," + hex + "]"))
|
||||
.collect(Collectors.toList());
|
||||
List<String> list = Arrays.stream(split).filter(s -> s.contains("Uncaught exception thrown"))
|
||||
.filter(s -> s.contains(hex + "," + hex + "]")).collect(Collectors.toList());
|
||||
then(list).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_create_spans_for_endpoint_returning_unsuccessful_result() {
|
||||
try {
|
||||
new RestTemplate().getForObject(
|
||||
"http://localhost:" + port() + "/test_bad_request", String.class);
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/test_bad_request", String.class);
|
||||
fail("should throw exception");
|
||||
}
|
||||
catch (HttpClientErrorException e) {
|
||||
@@ -205,8 +194,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
return new SpanHandler() {
|
||||
@Override
|
||||
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
|
||||
if (span.kind() != Kind.SERVER || span.error() == null
|
||||
|| !log.isErrorEnabled()) {
|
||||
if (span.kind() != Kind.SERVER || span.error() == null || !log.isErrorEnabled()) {
|
||||
return true; // don't add overhead as we only log server errors
|
||||
}
|
||||
|
||||
@@ -289,9 +277,8 @@ public class TraceFilterWebIntegrationTests {
|
||||
|
||||
@RequestMapping("/null-parameter")
|
||||
@ContinueSpan
|
||||
public String nullParameter(
|
||||
@SpanTag(key = "foo", expression = "(#root?:1000)+1") @RequestParam(
|
||||
value = "bar", required = false) Integer param) {
|
||||
public String nullParameter(@SpanTag(key = "foo", expression = "(#root?:1000)+1") @RequestParam(value = "bar",
|
||||
required = false) Integer param) {
|
||||
return "ok param=" + param;
|
||||
}
|
||||
|
||||
@@ -300,8 +287,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
@RestController
|
||||
public static class ExceptionThrowingController {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ExceptionThrowingController.class);
|
||||
private static final Log log = LogFactory.getLog(ExceptionThrowingController.class);
|
||||
|
||||
@RequestMapping("/")
|
||||
public void throwException() {
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@SpringBootTest(classes = { TraceWebDisabledTests.Config.class },
|
||||
properties = { "spring.sleuth.web.enabled=false" })
|
||||
@SpringBootTest(classes = { TraceWebDisabledTests.Config.class }, properties = { "spring.sleuth.web.enabled=false" })
|
||||
public class TraceWebDisabledTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -103,8 +103,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_span_data_on_headers_via_aspect_in_synchronous_call()
|
||||
throws Exception {
|
||||
public void should_set_span_data_on_headers_via_aspect_in_synchronous_call() throws Exception {
|
||||
whenARequestIsSentToASyncEndpoint();
|
||||
|
||||
thenTraceIdHasBeenSetOnARequestHeader();
|
||||
@@ -112,8 +111,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_span_data_on_headers_when_sending_a_request_via_async_rest_template()
|
||||
throws Exception {
|
||||
public void should_set_span_data_on_headers_when_sending_a_request_via_async_rest_template() throws Exception {
|
||||
whenARequestIsSentToAnAsyncRestTemplateEndpoint();
|
||||
|
||||
thenTraceIdHasBeenSetOnARequestHeader();
|
||||
@@ -121,8 +119,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_span_data_on_headers_via_aspect_in_asynchronous_callable()
|
||||
throws Exception {
|
||||
public void should_set_span_data_on_headers_via_aspect_in_asynchronous_callable() throws Exception {
|
||||
whenARequestIsSentToAnAsyncEndpoint("/callablePing");
|
||||
|
||||
thenTraceIdHasBeenSetOnARequestHeader();
|
||||
@@ -130,8 +127,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_span_data_on_headers_via_aspect_in_asynchronous_web_async()
|
||||
throws Exception {
|
||||
public void should_set_span_data_on_headers_via_aspect_in_asynchronous_web_async() throws Exception {
|
||||
whenARequestIsSentToAnAsyncEndpoint("/webAsyncTaskPing");
|
||||
|
||||
thenTraceIdHasBeenSetOnARequestHeader();
|
||||
@@ -140,8 +136,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
|
||||
// issue #1047
|
||||
@Test
|
||||
public void should_not_create_a_client_span_for_filtered_out_paths()
|
||||
throws Exception {
|
||||
public void should_not_create_a_client_span_for_filtered_out_paths() throws Exception {
|
||||
whenARequestIsSentToASyncEndpointThatShouldBeFilteredOut();
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
@@ -149,20 +144,15 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
}
|
||||
|
||||
private void whenARequestIsSentToAnAsyncRestTemplateEndpoint() throws Exception {
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/asyncRestTemplate")
|
||||
.accept(MediaType.TEXT_PLAIN)).andReturn();
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/asyncRestTemplate").accept(MediaType.TEXT_PLAIN)).andReturn();
|
||||
}
|
||||
|
||||
private void whenARequestIsSentToASyncEndpoint() throws Exception {
|
||||
this.mockMvc.perform(
|
||||
MockMvcRequestBuilders.get("/syncPing").accept(MediaType.TEXT_PLAIN))
|
||||
.andReturn();
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/syncPing").accept(MediaType.TEXT_PLAIN)).andReturn();
|
||||
}
|
||||
|
||||
private void whenARequestIsSentToASyncEndpointThatShouldBeFilteredOut()
|
||||
throws Exception {
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/issue1047_start")
|
||||
.accept(MediaType.TEXT_PLAIN)).andReturn();
|
||||
private void whenARequestIsSentToASyncEndpointThatShouldBeFilteredOut() throws Exception {
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/issue1047_start").accept(MediaType.TEXT_PLAIN)).andReturn();
|
||||
}
|
||||
|
||||
private void thenTraceIdHasBeenSetOnARequestHeader() {
|
||||
@@ -172,17 +162,15 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
// Brave was never designed to run tests of server and client in one test
|
||||
// that's why we have to pick only CLIENT side
|
||||
private void thenClientKindIsReported() {
|
||||
assertThat(this.spans.spans().stream().map(MutableSpan::kind)
|
||||
.collect(Collectors.toList())).contains(Span.Kind.CLIENT);
|
||||
assertThat(this.spans.spans().stream().map(MutableSpan::kind).collect(Collectors.toList()))
|
||||
.contains(Span.Kind.CLIENT);
|
||||
}
|
||||
|
||||
private void whenARequestIsSentToAnAsyncEndpoint(String url) throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc
|
||||
.perform(MockMvcRequestBuilders.get(url).accept(MediaType.TEXT_PLAIN))
|
||||
MvcResult mvcResult = this.mockMvc.perform(MockMvcRequestBuilders.get(url).accept(MediaType.TEXT_PLAIN))
|
||||
.andExpect(request().asyncStarted()).andReturn();
|
||||
mvcResult.getAsyncResult(SECONDS.toMillis(2));
|
||||
this.mockMvc.perform(asyncDispatch(mvcResult)).andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
this.mockMvc.perform(asyncDispatch(mvcResult)).andDo(print()).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration(
|
||||
@@ -205,8 +193,8 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
@Bean
|
||||
public AsyncRestTemplate asyncRestTemplate(Tracing tracing) {
|
||||
AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate();
|
||||
asyncRestTemplate.setInterceptors(Collections.singletonList(
|
||||
TracingAsyncClientHttpRequestInterceptor.create(tracing)));
|
||||
asyncRestTemplate.setInterceptors(
|
||||
Collections.singletonList(TracingAsyncClientHttpRequestInterceptor.create(tracing)));
|
||||
return asyncRestTemplate;
|
||||
}
|
||||
|
||||
@@ -238,49 +226,39 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
this.traceId = null;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/issue1047_end", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(value = "/issue1047_end", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String issue1047() {
|
||||
return "should_filter_out_this_endpoint";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/issue1047_start", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(value = "/issue1047_start", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String issue1047Start() {
|
||||
return callAndReturnIssue1047();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String home(
|
||||
@RequestHeader(value = "X-B3-SpanId", required = false) String traceId) {
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String home(@RequestHeader(value = "X-B3-SpanId", required = false) String traceId) {
|
||||
this.traceId = traceId == null ? "UNKNOWN" : traceId;
|
||||
return "trace=" + this.getTraceId();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/customTag", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String customTag(
|
||||
@RequestHeader(value = "X-B3-TraceId", required = false) String traceId) {
|
||||
@RequestMapping(value = "/customTag", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String customTag(@RequestHeader(value = "X-B3-TraceId", required = false) String traceId) {
|
||||
this.traceId = traceId == null ? "UNKNOWN" : traceId;
|
||||
return "trace=" + this.getTraceId();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/asyncRestTemplate", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String asyncRestTemplate()
|
||||
throws ExecutionException, InterruptedException {
|
||||
@RequestMapping(value = "/asyncRestTemplate", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String asyncRestTemplate() throws ExecutionException, InterruptedException {
|
||||
return callViaAsyncRestTemplateAndReturnOk();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/syncPing", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(value = "/syncPing", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String syncPing() {
|
||||
return callAndReturnOk();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/callablePing", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(value = "/callablePing", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public Callable<String> asyncPing() {
|
||||
return new Callable<String>() {
|
||||
@Override
|
||||
@@ -290,8 +268,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
};
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/webAsyncTaskPing", method = RequestMethod.GET,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(value = "/webAsyncTaskPing", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public WebAsyncTask<String> webAsyncTaskPing() {
|
||||
return new WebAsyncTask<>(new Callable<String>() {
|
||||
@Override
|
||||
@@ -302,8 +279,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
}
|
||||
|
||||
private String callAndReturnIssue1047() {
|
||||
this.restTemplate.getForObject(
|
||||
"http://localhost:" + port() + "/issue1047_end", String.class);
|
||||
this.restTemplate.getForObject("http://localhost:" + port() + "/issue1047_end", String.class);
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@@ -312,10 +288,8 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
return "OK";
|
||||
}
|
||||
|
||||
private String callViaAsyncRestTemplateAndReturnOk()
|
||||
throws ExecutionException, InterruptedException {
|
||||
this.asyncRestTemplate
|
||||
.getForEntity("http://localhost:" + port(), String.class).get();
|
||||
private String callViaAsyncRestTemplateAndReturnOk() throws ExecutionException, InterruptedException {
|
||||
this.asyncRestTemplate.getForEntity("http://localhost:" + port(), String.class).get();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
|
||||
@SpringBootTest(
|
||||
classes = { TraceWebAsyncClientAutoConfigurationTests.TestConfiguration.class },
|
||||
@SpringBootTest(classes = { TraceWebAsyncClientAutoConfigurationTests.TestConfiguration.class },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class TraceWebAsyncClientAutoConfigurationTests {
|
||||
|
||||
@@ -74,12 +73,10 @@ public class TraceWebAsyncClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_close_span_upon_success_callback()
|
||||
throws ExecutionException, InterruptedException {
|
||||
public void should_close_span_upon_success_callback() throws ExecutionException, InterruptedException {
|
||||
brave.Span initialSpan = this.tracer.tracer().nextSpan().name("foo");
|
||||
|
||||
try (Tracer.SpanInScope ws = this.tracer.tracer()
|
||||
.withSpanInScope(initialSpan.start())) {
|
||||
try (Tracer.SpanInScope ws = this.tracer.tracer().withSpanInScope(initialSpan.start())) {
|
||||
ListenableFuture<ResponseEntity<String>> future = this.asyncRestTemplate
|
||||
.getForEntity("http://localhost:" + port() + "/foo", String.class);
|
||||
String result = future.get().getBody();
|
||||
@@ -91,11 +88,8 @@ public class TraceWebAsyncClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(this.spans.spans().stream()
|
||||
.filter(span -> Span.Kind.CLIENT == span.kind()).findFirst().get())
|
||||
.matches(span -> span.finishTimestamp()
|
||||
- span.startTimestamp() >= TimeUnit.MILLISECONDS
|
||||
.toMicros(100));
|
||||
then(this.spans.spans().stream().filter(span -> Span.Kind.CLIENT == span.kind()).findFirst().get()).matches(
|
||||
span -> span.finishTimestamp() - span.startTimestamp() >= TimeUnit.MILLISECONDS.toMicros(100));
|
||||
then(this.tracer.tracer().currentSpan()).isNull();
|
||||
});
|
||||
}
|
||||
@@ -104,8 +98,7 @@ public class TraceWebAsyncClientAutoConfigurationTests {
|
||||
public void should_close_span_upon_failure_callback() {
|
||||
ListenableFuture<ResponseEntity<String>> future;
|
||||
try {
|
||||
future = this.asyncRestTemplate.getForEntity(
|
||||
"http://localhost:" + port() + "/blowsup", String.class);
|
||||
future = this.asyncRestTemplate.getForEntity("http://localhost:" + port() + "/blowsup", String.class);
|
||||
future.get();
|
||||
BDDAssertions.fail("should throw an exception from the controller");
|
||||
}
|
||||
@@ -115,8 +108,8 @@ public class TraceWebAsyncClientAutoConfigurationTests {
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
MutableSpan reportedRpcSpan = new ArrayList<>(this.spans.spans()).stream()
|
||||
.filter(span -> Span.Kind.CLIENT == span.kind()).findFirst().get();
|
||||
then(reportedRpcSpan).matches(span -> span.finishTimestamp()
|
||||
- span.startTimestamp() >= TimeUnit.MILLISECONDS.toMicros(100));
|
||||
then(reportedRpcSpan).matches(
|
||||
span -> span.finishTimestamp() - span.startTimestamp() >= TimeUnit.MILLISECONDS.toMicros(100));
|
||||
then(reportedRpcSpan.tags()).containsKey("error");
|
||||
then(this.tracer.tracer().currentSpan()).isNull();
|
||||
});
|
||||
|
||||
@@ -49,8 +49,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@SpringBootTest(classes = TestConfig.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(classes = TestConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class Issue585Tests {
|
||||
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
@@ -66,14 +65,12 @@ public class Issue585Tests {
|
||||
|
||||
@Test
|
||||
public void should_report_span_when_using_custom_exception_resolver() {
|
||||
ResponseEntity<String> entity = this.testRestTemplate.getForEntity(
|
||||
"http://localhost:" + this.port + "/sleuthtest?greeting=foo",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.testRestTemplate
|
||||
.getForEntity("http://localhost:" + this.port + "/sleuthtest?greeting=foo", String.class);
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(entity.getStatusCode().value()).isEqualTo(500);
|
||||
then(this.spans.get(0).tags()).containsEntry("custom", "tag")
|
||||
.containsKeys("error");
|
||||
then(this.spans.get(0).tags()).containsEntry("custom", "tag").containsKeys("error");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -113,18 +110,15 @@ class TestController {
|
||||
@ControllerAdvice
|
||||
class CustomExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
|
||||
private final static Logger logger = LoggerFactory
|
||||
.getLogger(CustomExceptionHandler.class);
|
||||
private final static Logger logger = LoggerFactory.getLogger(CustomExceptionHandler.class);
|
||||
|
||||
@Autowired
|
||||
private Tracing tracer;
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
protected ResponseEntity<ExceptionResponse> handleDefaultError(Exception ex,
|
||||
HttpServletRequest request) {
|
||||
ExceptionResponse exceptionResponse = new ExceptionResponse("ERR-01",
|
||||
ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
request.getRequestURI(), Instant.now().toEpochMilli());
|
||||
protected ResponseEntity<ExceptionResponse> handleDefaultError(Exception ex, HttpServletRequest request) {
|
||||
ExceptionResponse exceptionResponse = new ExceptionResponse("ERR-01", ex.getMessage(),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR, request.getRequestURI(), Instant.now().toEpochMilli());
|
||||
reportErrorSpan(ex.getMessage());
|
||||
return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
@@ -151,8 +145,7 @@ class ExceptionResponse {
|
||||
|
||||
private Long epochTime;
|
||||
|
||||
ExceptionResponse(String errorCode, String errorMessage, HttpStatus httpStatus,
|
||||
String path, Long epochTime) {
|
||||
ExceptionResponse(String errorCode, String errorMessage, HttpStatus httpStatus, String path, Long epochTime) {
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = errorMessage;
|
||||
this.httpStatus = httpStatus;
|
||||
|
||||
@@ -27,10 +27,8 @@ import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@SpringBootTest(classes = Issue469.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestPropertySource(properties = { "spring.mvc.view.prefix=/WEB-INF/jsp/",
|
||||
"spring.mvc.view.suffix=.jsp" })
|
||||
@SpringBootTest(classes = Issue469.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestPropertySource(properties = { "spring.mvc.view.prefix=/WEB-INF/jsp/", "spring.mvc.view.suffix=.jsp" })
|
||||
public class Issue469Tests {
|
||||
|
||||
@Autowired
|
||||
@@ -44,8 +42,7 @@ public class Issue469Tests {
|
||||
@Test
|
||||
public void should_not_result_in_tracing_exceptions_when_using_view_controllers() {
|
||||
try {
|
||||
this.restTemplate.getForObject("http://localhost:" + port() + "/welcome",
|
||||
String.class);
|
||||
this.restTemplate.getForObject("http://localhost:" + port() + "/welcome", String.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// JSPs are not rendered
|
||||
|
||||
@@ -26,8 +26,7 @@ public final class SpanUtil {
|
||||
throw new IllegalStateException("Can't instantiate a utility class");
|
||||
}
|
||||
|
||||
static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
// Represents given long id as 16-character lower-hex string
|
||||
public static String idToHex(long id) {
|
||||
|
||||
@@ -52,14 +52,12 @@ public class FlowsScopePassingSpanSubscriberTests {
|
||||
// iterator. That's not allowed, and will cause an exception
|
||||
// Fuseable$QueueSubscription.NOT_SUPPORTED_MESSAGE.
|
||||
// This ensures AssertJ uses normal toString.
|
||||
StandardRepresentation.registerFormatterForType(ScopePassingSpanSubscriber.class,
|
||||
Objects::toString);
|
||||
StandardRepresentation.registerFormatterForType(ScopePassingSpanSubscriber.class, Objects::toString);
|
||||
}
|
||||
|
||||
final CurrentTraceContext currentTraceContext = CurrentTraceContext.Default.create();
|
||||
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true)
|
||||
.build();
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true).build();
|
||||
|
||||
AnnotationConfigApplicationContext springContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
@@ -133,21 +131,17 @@ public class FlowsScopePassingSpanSubscriberTests {
|
||||
|
||||
transformer.apply(Mono.just(1)).subscribe(assertNoSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.<Integer>error(new Exception()).hide())
|
||||
.subscribe(assertSpanSubscriber);
|
||||
transformer.apply(Mono.<Integer>error(new Exception()).hide()).subscribe(assertSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.error(new Exception()))
|
||||
.subscribe(assertNoSpanSubscriber);
|
||||
transformer.apply(Mono.error(new Exception())).subscribe(assertNoSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.<Integer>empty().hide())
|
||||
.subscribe(assertSpanSubscriber);
|
||||
transformer.apply(Mono.<Integer>empty().hide()).subscribe(assertSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.empty()).subscribe(assertNoSpanSubscriber);
|
||||
|
||||
}
|
||||
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(this.currentTraceContext.get()).isNull());
|
||||
Awaitility.await().untilAsserted(() -> then(this.currentTraceContext.get()).isNull());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,16 +42,13 @@ public class Issue866Configuration {
|
||||
@Bean
|
||||
HookRegisteringBeanDefinitionRegistryPostProcessor overridingProcessorForTests(
|
||||
ConfigurableApplicationContext context) {
|
||||
log.info(
|
||||
"Registering a HookRegisteringBeanDefinitionRegistryPostProcessor for context ["
|
||||
+ context + "]");
|
||||
log.info("Registering a HookRegisteringBeanDefinitionRegistryPostProcessor for context [" + context + "]");
|
||||
TestHook hook = new TestHook(context);
|
||||
Issue866Configuration.hook = hook;
|
||||
return hook;
|
||||
}
|
||||
|
||||
public static class TestHook
|
||||
extends HookRegisteringBeanDefinitionRegistryPostProcessor {
|
||||
public static class TestHook extends HookRegisteringBeanDefinitionRegistryPostProcessor {
|
||||
|
||||
public boolean executed = false;
|
||||
|
||||
@@ -60,8 +57,7 @@ public class Issue866Configuration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
||||
throws BeansException {
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
super.postProcessBeanFactory(beanFactory);
|
||||
this.executed = true;
|
||||
}
|
||||
|
||||
@@ -49,11 +49,9 @@ public class ScopePassingSpanSubscriberSpringBootTests {
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true)
|
||||
.build();
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true).build();
|
||||
|
||||
TraceContext context2 = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true)
|
||||
.build();
|
||||
TraceContext context2 = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true).build();
|
||||
|
||||
@Test
|
||||
public void should_pass_tracing_info_when_using_reactor() {
|
||||
@@ -77,12 +75,11 @@ public class ScopePassingSpanSubscriberSpringBootTests {
|
||||
final AtomicReference<TraceContext> spanInOperation = new AtomicReference<>();
|
||||
|
||||
try (Scope ws = this.currentTraceContext.newScope(context)) {
|
||||
Mono.just(1).flatMap(d -> Flux.just(d + 1).collectList().map(p -> p.get(0)))
|
||||
.map(d -> d + 1).map((d) -> {
|
||||
spanInOperation.set(this.currentTraceContext.get());
|
||||
return d + 1;
|
||||
}).map(d -> d + 1).subscribe(d -> {
|
||||
});
|
||||
Mono.just(1).flatMap(d -> Flux.just(d + 1).collectList().map(p -> p.get(0))).map(d -> d + 1).map((d) -> {
|
||||
spanInOperation.set(this.currentTraceContext.get());
|
||||
return d + 1;
|
||||
}).map(d -> d + 1).subscribe(d -> {
|
||||
});
|
||||
}
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
@@ -94,24 +91,21 @@ public class ScopePassingSpanSubscriberSpringBootTests {
|
||||
final AtomicReference<TraceContext> spanInOperation = new AtomicReference<>();
|
||||
|
||||
try (Scope ws = this.currentTraceContext.newScope(context)) {
|
||||
Flux.just(1, 2, 3).publishOn(Schedulers.single()).log("reactor.1")
|
||||
.map(d -> d + 1).map(d -> d + 1)
|
||||
.publishOn(Schedulers.newSingle("secondThread")).log("reactor.2")
|
||||
.map((d) -> {
|
||||
Flux.just(1, 2, 3).publishOn(Schedulers.single()).log("reactor.1").map(d -> d + 1).map(d -> d + 1)
|
||||
.publishOn(Schedulers.newSingle("secondThread")).log("reactor.2").map((d) -> {
|
||||
spanInOperation.set(this.currentTraceContext.get());
|
||||
return d + 1;
|
||||
}).map(d -> d + 1).blockLast();
|
||||
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(spanInOperation.get()).isEqualTo(context));
|
||||
Awaitility.await().untilAsserted(() -> then(spanInOperation.get()).isEqualTo(context));
|
||||
then(this.currentTraceContext.get()).isEqualTo(context);
|
||||
}
|
||||
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
|
||||
try (Scope ws = this.currentTraceContext.newScope(context2)) {
|
||||
Flux.just(1, 2, 3).publishOn(Schedulers.single()).log("reactor.")
|
||||
.map(d -> d + 1).map(d -> d + 1).map((d) -> {
|
||||
Flux.just(1, 2, 3).publishOn(Schedulers.single()).log("reactor.").map(d -> d + 1).map(d -> d + 1)
|
||||
.map((d) -> {
|
||||
spanInOperation.set(this.currentTraceContext.get());
|
||||
return d + 1;
|
||||
}).map(d -> d + 1).blockLast();
|
||||
@@ -138,10 +132,9 @@ public class ScopePassingSpanSubscriberSpringBootTests {
|
||||
final AtomicReference<TraceContext> spanInZipOperation = new AtomicReference<>();
|
||||
|
||||
try (Scope ws = this.currentTraceContext.newScope(context)) {
|
||||
Mono.fromCallable(this.currentTraceContext::get).map(span -> span)
|
||||
.doOnNext(spanInOperation::set)
|
||||
.zipWith(Mono.fromCallable(this.currentTraceContext::get)
|
||||
.map(span -> span).doOnNext(spanInZipOperation::set))
|
||||
Mono.fromCallable(this.currentTraceContext::get).map(span -> span).doOnNext(spanInOperation::set)
|
||||
.zipWith(Mono.fromCallable(this.currentTraceContext::get).map(span -> span)
|
||||
.doOnNext(spanInZipOperation::set))
|
||||
.block();
|
||||
}
|
||||
|
||||
@@ -153,9 +146,7 @@ public class ScopePassingSpanSubscriberSpringBootTests {
|
||||
@Test
|
||||
public void should_work_for_mono_just_with_flat_map() {
|
||||
try (Scope ws = this.currentTraceContext.newScope(context)) {
|
||||
Mono.just("value1")
|
||||
.flatMap(request -> Mono.just("value2").then(Mono.just("foo")))
|
||||
.map(a -> "qwe").block();
|
||||
Mono.just("value1").flatMap(request -> Mono.just("value2").then(Mono.just("foo"))).map(a -> "qwe").block();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,11 +168,8 @@ public class ScopePassingSpanSubscriberSpringBootTests {
|
||||
final AtomicReference<TraceContext> spanInOperation = new AtomicReference<>();
|
||||
|
||||
try (Scope ws = this.currentTraceContext.newScope(context)) {
|
||||
Flux.range(0, 5)
|
||||
.flatMap(it -> Mono.delay(Duration.ofMillis(1))
|
||||
.map(context -> this.currentTraceContext.get())
|
||||
.doOnNext(spanInOperation::set))
|
||||
.blockFirst();
|
||||
Flux.range(0, 5).flatMap(it -> Mono.delay(Duration.ofMillis(1))
|
||||
.map(context -> this.currentTraceContext.get()).doOnNext(spanInOperation::set)).blockFirst();
|
||||
}
|
||||
|
||||
then(spanInOperation.get()).isEqualTo(context);
|
||||
|
||||
@@ -55,17 +55,14 @@ public class ScopePassingSpanSubscriberTests {
|
||||
// iterator. That's not allowed, and will cause an exception
|
||||
// Fuseable$QueueSubscription.NOT_SUPPORTED_MESSAGE.
|
||||
// This ensures AssertJ uses normal toString.
|
||||
StandardRepresentation.registerFormatterForType(ScopePassingSpanSubscriber.class,
|
||||
Objects::toString);
|
||||
StandardRepresentation.registerFormatterForType(ScopePassingSpanSubscriber.class, Objects::toString);
|
||||
}
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true)
|
||||
.build();
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true).build();
|
||||
|
||||
TraceContext context2 = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true)
|
||||
.build();
|
||||
TraceContext context2 = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true).build();
|
||||
|
||||
Subscriber<Object> assertNotScopePassingSpanSubscriber = new CoreSubscriber<Object>() {
|
||||
@Override
|
||||
@@ -132,8 +129,8 @@ public class ScopePassingSpanSubscriberTests {
|
||||
|
||||
@Test
|
||||
public void should_propagate_current_context() {
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null,
|
||||
Context.of("foo", "bar"), this.currentTraceContext, null);
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null, Context.of("foo", "bar"),
|
||||
this.currentTraceContext, null);
|
||||
|
||||
then((String) subscriber.currentContext().get("foo")).isEqualTo("bar");
|
||||
}
|
||||
@@ -144,16 +141,16 @@ public class ScopePassingSpanSubscriberTests {
|
||||
@Test
|
||||
public void should_not_redundantly_copy_context() {
|
||||
Context initial = Context.of(TraceContext.class, context);
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null,
|
||||
initial, this.currentTraceContext, context);
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null, initial,
|
||||
this.currentTraceContext, context);
|
||||
|
||||
then(initial).isSameAs(subscriber.currentContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_empty_context_when_context_is_null() {
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null,
|
||||
Context.empty(), this.currentTraceContext, null);
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null, Context.empty(),
|
||||
this.currentTraceContext, null);
|
||||
|
||||
then(subscriber.currentContext().isEmpty()).isTrue();
|
||||
}
|
||||
@@ -161,9 +158,8 @@ public class ScopePassingSpanSubscriberTests {
|
||||
@Test
|
||||
public void should_put_current_span_to_context() {
|
||||
try (Scope ws = this.currentTraceContext.newScope(context2)) {
|
||||
CoreSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(
|
||||
new BaseSubscriber<Object>() {
|
||||
}, Context.empty(), currentTraceContext, context);
|
||||
CoreSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(new BaseSubscriber<Object>() {
|
||||
}, Context.empty(), currentTraceContext, context);
|
||||
|
||||
then(subscriber.currentContext().get(TraceContext.class)).isEqualTo(context);
|
||||
}
|
||||
@@ -179,14 +175,11 @@ public class ScopePassingSpanSubscriberTests {
|
||||
|
||||
try (Scope ws = this.currentTraceContext.newScope(context)) {
|
||||
|
||||
transformer.apply(Mono.just(1))
|
||||
.subscribe(assertNotScopePassingSpanSubscriber);
|
||||
transformer.apply(Mono.just(1)).subscribe(assertNotScopePassingSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.error(new Exception()))
|
||||
.subscribe(assertNotScopePassingSpanSubscriber);
|
||||
transformer.apply(Mono.error(new Exception())).subscribe(assertNotScopePassingSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.empty())
|
||||
.subscribe(assertNotScopePassingSpanSubscriber);
|
||||
transformer.apply(Mono.empty()).subscribe(assertNotScopePassingSpanSubscriber);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -201,14 +194,11 @@ public class ScopePassingSpanSubscriberTests {
|
||||
|
||||
try (Scope ws = this.currentTraceContext.newScope(context)) {
|
||||
|
||||
transformer.apply(Mono.just(1).hide())
|
||||
.subscribe(assertScopePassingSpanSubscriber);
|
||||
transformer.apply(Mono.just(1).hide()).subscribe(assertScopePassingSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.<Integer>error(new Exception()).hide())
|
||||
.subscribe(assertScopePassingSpanSubscriber);
|
||||
transformer.apply(Mono.<Integer>error(new Exception()).hide()).subscribe(assertScopePassingSpanSubscriber);
|
||||
|
||||
transformer.apply(Mono.<Integer>empty().hide())
|
||||
.subscribe(assertScopePassingSpanSubscriber);
|
||||
transformer.apply(Mono.<Integer>empty().hide()).subscribe(assertScopePassingSpanSubscriber);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ public final class TraceReactorAutoConfigurationAccessorConfiguration {
|
||||
throw new IllegalStateException("Can't instantiate a utility class");
|
||||
}
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(TraceReactorAutoConfigurationAccessorConfiguration.class);
|
||||
private static final Log log = LogFactory.getLog(TraceReactorAutoConfigurationAccessorConfiguration.class);
|
||||
|
||||
public static void close() {
|
||||
if (log.isTraceEnabled()) {
|
||||
|
||||
@@ -80,57 +80,48 @@ public class FlatMapTests {
|
||||
@Test
|
||||
public void should_work_with_flat_maps(CapturedOutput capture) {
|
||||
// given
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
FlatMapTests.TestConfiguration.class, Issue866Configuration.class)
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(FlatMapTests.TestConfiguration.class,
|
||||
Issue866Configuration.class)
|
||||
.web(WebApplicationType.REACTIVE)
|
||||
.properties("server.port=0", "spring.jmx.enabled=false",
|
||||
"spring.application.name=TraceWebFluxTests",
|
||||
"security.basic.enabled=false",
|
||||
"spring.application.name=TraceWebFluxTests", "security.basic.enabled=false",
|
||||
"management.security.enabled=false")
|
||||
.run();
|
||||
assertReactorTracing(context, capture,
|
||||
() -> context.getBean(TestConfiguration.class).spanInFoo);
|
||||
assertReactorTracing(context, capture, () -> context.getBean(TestConfiguration.class).spanInFoo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_work_with_flat_maps_with_on_last_operator_instrumentation(
|
||||
CapturedOutput capture) {
|
||||
public void should_work_with_flat_maps_with_on_last_operator_instrumentation(CapturedOutput capture) {
|
||||
// given
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
FlatMapTests.TestConfiguration.class, Issue866Configuration.class)
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(FlatMapTests.TestConfiguration.class,
|
||||
Issue866Configuration.class)
|
||||
.web(WebApplicationType.REACTIVE)
|
||||
.properties("server.port=0", "spring.jmx.enabled=false",
|
||||
"spring.sleuth.reactor.decorate-on-each=false",
|
||||
"spring.application.name=TraceWebFlux2Tests",
|
||||
"security.basic.enabled=false",
|
||||
"spring.application.name=TraceWebFlux2Tests", "security.basic.enabled=false",
|
||||
"management.security.enabled=false")
|
||||
.run();
|
||||
assertReactorTracing(context, capture,
|
||||
() -> context.getBean(TestConfiguration.class).spanInFoo);
|
||||
assertReactorTracing(context, capture, () -> context.getBean(TestConfiguration.class).spanInFoo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_work_with_flat_maps_with_on_manual_operator_instrumentation(
|
||||
CapturedOutput capture) {
|
||||
public void should_work_with_flat_maps_with_on_manual_operator_instrumentation(CapturedOutput capture) {
|
||||
// given
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
FlatMapTests.TestManualConfiguration.class, Issue866Configuration.class)
|
||||
.web(WebApplicationType.REACTIVE)
|
||||
.properties("server.port=0", "spring.jmx.enabled=false",
|
||||
"spring.sleuth.reactor.instrumentation-type=MANUAL",
|
||||
"spring.application.name=TraceWebFlux3Tests",
|
||||
"security.basic.enabled=false",
|
||||
"spring.application.name=TraceWebFlux3Tests", "security.basic.enabled=false",
|
||||
"management.security.enabled=false")
|
||||
.run();
|
||||
assertReactorTracing(context, capture,
|
||||
() -> context.getBean(TestManualConfiguration.class).spanInFoo);
|
||||
assertReactorTracing(context, capture, () -> context.getBean(TestManualConfiguration.class).spanInFoo);
|
||||
}
|
||||
|
||||
private void assertReactorTracing(ConfigurableApplicationContext context,
|
||||
CapturedOutput capture, SpanProvider spanProvider) {
|
||||
private void assertReactorTracing(ConfigurableApplicationContext context, CapturedOutput capture,
|
||||
SpanProvider spanProvider) {
|
||||
TestSpanHandler spans = context.getBean(TestSpanHandler.class);
|
||||
int port = context.getBean(Environment.class).getProperty("local.server.port",
|
||||
Integer.class);
|
||||
int port = context.getBean(Environment.class).getProperty("local.server.port", Integer.class);
|
||||
RequestSender sender = context.getBean(RequestSender.class);
|
||||
FactoryUser factoryUser = context.getBean(FactoryUser.class);
|
||||
sender.port = port;
|
||||
@@ -152,29 +143,23 @@ public class FlatMapTests {
|
||||
LOGGER.info("Second trace start");
|
||||
String secondTraceId = flatMapTraceId(spans, callFlatMap(port).block());
|
||||
// then
|
||||
then(firstTraceId).as("Id will not be reused between calls")
|
||||
.isNotEqualTo(secondTraceId);
|
||||
then(firstTraceId).as("Id will not be reused between calls").isNotEqualTo(secondTraceId);
|
||||
LOGGER.info("Id was not reused between calls");
|
||||
thenSpanInFooHasSameTraceId(secondTraceId, spanProvider);
|
||||
LOGGER.info("Span in Foo has same trace id");
|
||||
// and
|
||||
List<String> requestUri = Arrays.stream(capture.toString().split("\n"))
|
||||
.filter(s -> s.contains("Received a request to uri"))
|
||||
.map(s -> s.split(",")[1]).collect(Collectors.toList());
|
||||
LOGGER.info(
|
||||
"TracingFilter should not have any trace when receiving a request "
|
||||
+ requestUri);
|
||||
then(requestUri).as(
|
||||
"TracingFilter should not have any trace when receiving a request")
|
||||
.containsOnly("");
|
||||
.filter(s -> s.contains("Received a request to uri")).map(s -> s.split(",")[1])
|
||||
.collect(Collectors.toList());
|
||||
LOGGER.info("TracingFilter should not have any trace when receiving a request " + requestUri);
|
||||
then(requestUri).as("TracingFilter should not have any trace when receiving a request").containsOnly("");
|
||||
// and #866
|
||||
then(factoryUser.wasSchedulerWrapped).isTrue();
|
||||
LOGGER.info("Factory was wrapped");
|
||||
});
|
||||
}
|
||||
|
||||
private void thenAllWebClientCallsHaveSameTraceId(String traceId,
|
||||
RequestSender sender) {
|
||||
private void thenAllWebClientCallsHaveSameTraceId(String traceId, RequestSender sender) {
|
||||
then(sender.span.context().traceIdString()).isEqualTo(traceId);
|
||||
}
|
||||
|
||||
@@ -183,17 +168,15 @@ public class FlatMapTests {
|
||||
}
|
||||
|
||||
private Mono<ClientResponse> callFlatMap(int port) {
|
||||
return WebClient.create().get().uri("http://localhost:" + port + "/withFlatMap")
|
||||
.exchange();
|
||||
return WebClient.create().get().uri("http://localhost:" + port + "/withFlatMap").exchange();
|
||||
}
|
||||
|
||||
private String flatMapTraceId(TestSpanHandler spans, ClientResponse response) {
|
||||
then(response.statusCode().value()).isEqualTo(200);
|
||||
then(spans).isNotEmpty();
|
||||
LOGGER.info("Accumulated spans: " + spans);
|
||||
List<String> traceIdOfFlatMap = spans.spans().stream()
|
||||
.filter(span -> span.tags().containsKey("http.path")
|
||||
&& span.tags().get("http.path").equals("/withFlatMap"))
|
||||
List<String> traceIdOfFlatMap = spans.spans().stream().filter(
|
||||
span -> span.tags().containsKey("http.path") && span.tags().get("http.path").equals("/withFlatMap"))
|
||||
.map(MutableSpan::traceId).collect(Collectors.toList());
|
||||
then(traceIdOfFlatMap).hasSize(1);
|
||||
return traceIdOfFlatMap.get(0);
|
||||
@@ -206,8 +189,7 @@ public class FlatMapTests {
|
||||
brave.Span spanInFoo;
|
||||
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> handlers(Tracer tracer,
|
||||
RequestSender requestSender) {
|
||||
RouterFunction<ServerResponse> handlers(Tracer tracer, RequestSender requestSender) {
|
||||
return route(GET("/noFlatMap"), request -> {
|
||||
LOGGER.info("noFlatMap");
|
||||
Flux<Integer> one = requestSender.getAll().map(String::length);
|
||||
@@ -215,9 +197,8 @@ public class FlatMapTests {
|
||||
}).andRoute(GET("/withFlatMap"), request -> {
|
||||
LOGGER.info("withFlatMap");
|
||||
Flux<Integer> one = requestSender.getAll().map(String::length);
|
||||
Flux<Integer> response = one
|
||||
.flatMap(size -> requestSender.getAll().doOnEach(
|
||||
sig -> LOGGER.info(sig.getContext().toString())))
|
||||
Flux<Integer> response = one.flatMap(
|
||||
size -> requestSender.getAll().doOnEach(sig -> LOGGER.info(sig.getContext().toString())))
|
||||
.map(string -> {
|
||||
LOGGER.info("WHATEVER YEAH");
|
||||
return string.length();
|
||||
@@ -265,24 +246,19 @@ public class FlatMapTests {
|
||||
brave.Span spanInFoo;
|
||||
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> handlers(Tracing tracing,
|
||||
ManualRequestSender requestSender) {
|
||||
RouterFunction<ServerResponse> handlers(Tracing tracing, ManualRequestSender requestSender) {
|
||||
return route(GET("/noFlatMap"), request -> {
|
||||
ServerWebExchange exchange = request.exchange();
|
||||
WebFluxSleuthOperators.withSpanInScope(tracing, exchange,
|
||||
() -> LOGGER.info("noFlatMap"));
|
||||
WebFluxSleuthOperators.withSpanInScope(tracing, exchange, () -> LOGGER.info("noFlatMap"));
|
||||
Flux<Integer> one = requestSender.getAll().map(String::length);
|
||||
return ServerResponse.ok().body(one, Integer.class);
|
||||
}).andRoute(GET("/withFlatMap"), request -> {
|
||||
ServerWebExchange exchange = request.exchange();
|
||||
WebFluxSleuthOperators.withSpanInScope(tracing, exchange,
|
||||
() -> LOGGER.info("withFlatMap"));
|
||||
WebFluxSleuthOperators.withSpanInScope(tracing, exchange, () -> LOGGER.info("withFlatMap"));
|
||||
Flux<Integer> one = requestSender.getAll().map(String::length);
|
||||
Flux<Integer> response = one
|
||||
.flatMap(size -> requestSender.getAll()
|
||||
.doOnEach(sig -> WebFluxSleuthOperators.withSpanInScope(
|
||||
sig.getContext(),
|
||||
() -> LOGGER.info(sig.getContext().toString()))))
|
||||
.flatMap(size -> requestSender.getAll().doOnEach(sig -> WebFluxSleuthOperators
|
||||
.withSpanInScope(sig.getContext(), () -> LOGGER.info(sig.getContext().toString()))))
|
||||
.map(string -> {
|
||||
WebFluxSleuthOperators.withSpanInScope(tracing, exchange,
|
||||
() -> LOGGER.info("WHATEVER YEAH"));
|
||||
|
||||
@@ -29,8 +29,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
class ManualRequestSender extends RequestSender {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory
|
||||
.getLogger(ManualRequestSender.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ManualRequestSender.class);
|
||||
|
||||
ManualRequestSender(WebClient webClient, Tracer tracer) {
|
||||
super(webClient, tracer);
|
||||
@@ -38,25 +37,21 @@ class ManualRequestSender extends RequestSender {
|
||||
|
||||
@Override
|
||||
public Mono<String> get(Integer someParameterNotUsedNow) {
|
||||
return Mono.just(this.webClient).doOnEach(
|
||||
WebFluxSleuthOperators.withSpanInScope(SignalType.ON_NEXT, () -> {
|
||||
this.span = this.tracer.currentSpan();
|
||||
LOGGER.info("getting for parameter {}", someParameterNotUsedNow);
|
||||
}))
|
||||
.flatMap(webClient -> Mono.subscriberContext()
|
||||
.flatMap(ctx -> WebFluxSleuthOperators.withSpanInScope(ctx,
|
||||
() -> webClient.method(HttpMethod.GET)
|
||||
.uri("http://localhost:" + port + "/foo")
|
||||
.retrieve().bodyToMono(String.class))));
|
||||
return Mono.just(this.webClient).doOnEach(WebFluxSleuthOperators.withSpanInScope(SignalType.ON_NEXT, () -> {
|
||||
this.span = this.tracer.currentSpan();
|
||||
LOGGER.info("getting for parameter {}", someParameterNotUsedNow);
|
||||
})).flatMap(webClient -> Mono.subscriberContext()
|
||||
.flatMap(ctx -> WebFluxSleuthOperators.withSpanInScope(ctx, () -> webClient.method(HttpMethod.GET)
|
||||
.uri("http://localhost:" + port + "/foo").retrieve().bodyToMono(String.class))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<String> getAll() {
|
||||
return Flux.just("").flatMap(s -> Flux.deferWithContext(ctx -> Flux.just("")
|
||||
.doOnNext(t -> WebFluxSleuthOperators.withSpanInScope(ctx,
|
||||
() -> LOGGER.info("before merge")))
|
||||
.mergeWith(get(2)).mergeWith(get(3)).doOnNext(t -> WebFluxSleuthOperators
|
||||
.withSpanInScope(ctx, () -> LOGGER.info("after merge")))));
|
||||
return Flux.just("")
|
||||
.flatMap(s -> Flux.deferWithContext(ctx -> Flux.just("")
|
||||
.doOnNext(t -> WebFluxSleuthOperators.withSpanInScope(ctx, () -> LOGGER.info("before merge")))
|
||||
.mergeWith(get(2)).mergeWith(get(3))
|
||||
.doOnNext(t -> WebFluxSleuthOperators.withSpanInScope(ctx, () -> LOGGER.info("after merge")))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ class RequestSender {
|
||||
public Mono<String> get(Integer someParameterNotUsedNow) {
|
||||
LOGGER.info("getting for parameter {}", someParameterNotUsedNow);
|
||||
this.span = this.tracer.currentSpan();
|
||||
return this.webClient.method(HttpMethod.GET)
|
||||
.uri("http://localhost:" + this.port + "/foo").retrieve()
|
||||
return this.webClient.method(HttpMethod.GET).uri("http://localhost:" + this.port + "/foo").retrieve()
|
||||
.bodyToMono(String.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* present.
|
||||
*/
|
||||
// Function of spring context so that shutdown hooks happen!
|
||||
abstract class ITSpringConfiguredReactorClient
|
||||
extends ITHttpAsyncClient<AnnotationConfigApplicationContext> {
|
||||
abstract class ITSpringConfiguredReactorClient extends ITHttpAsyncClient<AnnotationConfigApplicationContext> {
|
||||
|
||||
@Before
|
||||
@After
|
||||
@@ -73,8 +72,7 @@ abstract class ITSpringConfiguredReactorClient
|
||||
AnnotationConfigApplicationContext result = new AnnotationConfigApplicationContext();
|
||||
URI baseUrl = URI.create("http://127.0.0.1:" + server.getPort());
|
||||
result.registerBean(HttpTracing.class, () -> httpTracing);
|
||||
result.registerBean(CurrentTraceContext.class,
|
||||
() -> httpTracing.tracing().currentTraceContext());
|
||||
result.registerBean(CurrentTraceContext.class, () -> httpTracing.tracing().currentTraceContext());
|
||||
result.registerBean(HttpClient.class, () -> testHttpClient(baseUrl));
|
||||
result.registerBean(URI.class, () -> baseUrl);
|
||||
result.register(componentClasses);
|
||||
@@ -84,10 +82,8 @@ abstract class ITSpringConfiguredReactorClient
|
||||
|
||||
static HttpClient testHttpClient(URI baseUrl) {
|
||||
return HttpClient.create().baseUrl(baseUrl.toString())
|
||||
.tcpConfiguration(tcpClient -> tcpClient
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
|
||||
.doOnConnected(conn -> conn
|
||||
.addHandler(new ReadTimeoutHandler(3, TimeUnit.SECONDS))))
|
||||
.tcpConfiguration(tcpClient -> tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
|
||||
.doOnConnected(conn -> conn.addHandler(new ReadTimeoutHandler(3, TimeUnit.SECONDS))))
|
||||
.disableRetry(true).followRedirect(true);
|
||||
}
|
||||
|
||||
@@ -97,14 +93,12 @@ abstract class ITSpringConfiguredReactorClient
|
||||
}
|
||||
|
||||
@Override
|
||||
final protected void get(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery) {
|
||||
final protected void get(AnnotationConfigApplicationContext context, String pathIncludingQuery) {
|
||||
getMono(context, pathIncludingQuery).block();
|
||||
}
|
||||
|
||||
@Override
|
||||
final protected void post(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery, String body) {
|
||||
final protected void post(AnnotationConfigApplicationContext context, String pathIncludingQuery, String body) {
|
||||
postMono(context, pathIncludingQuery, body).block();
|
||||
}
|
||||
|
||||
@@ -115,12 +109,10 @@ abstract class ITSpringConfiguredReactorClient
|
||||
}
|
||||
|
||||
/** Returns a {@link Mono} of the HTTP status code from the given "POST" request. */
|
||||
abstract Mono<Integer> postMono(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery, String body);
|
||||
abstract Mono<Integer> postMono(AnnotationConfigApplicationContext context, String pathIncludingQuery, String body);
|
||||
|
||||
/** Returns a {@link Mono} of the HTTP status code. */
|
||||
abstract Mono<Integer> getMono(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery);
|
||||
abstract Mono<Integer> getMono(AnnotationConfigApplicationContext context, String pathIncludingQuery);
|
||||
|
||||
/**
|
||||
* This assumes that implementations do not issue an HTTP request until
|
||||
|
||||
@@ -72,18 +72,14 @@ public class ReactorNettyHttpClientBraveTests extends ITSpringConfiguredReactorC
|
||||
}
|
||||
|
||||
@Override
|
||||
Mono<Integer> postMono(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery, String body) {
|
||||
return context.getBean(HttpClient.class).post()
|
||||
.send(ByteBufFlux.fromString(Mono.just(body))).uri(pathIncludingQuery)
|
||||
.response().map(r -> r.status().code());
|
||||
Mono<Integer> postMono(AnnotationConfigApplicationContext context, String pathIncludingQuery, String body) {
|
||||
return context.getBean(HttpClient.class).post().send(ByteBufFlux.fromString(Mono.just(body)))
|
||||
.uri(pathIncludingQuery).response().map(r -> r.status().code());
|
||||
}
|
||||
|
||||
@Override
|
||||
Mono<Integer> getMono(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery) {
|
||||
return context.getBean(HttpClient.class).get().uri(pathIncludingQuery).response()
|
||||
.map(r -> r.status().code());
|
||||
Mono<Integer> getMono(AnnotationConfigApplicationContext context, String pathIncludingQuery) {
|
||||
return context.getBean(HttpClient.class).get().uri(pathIncludingQuery).response().map(r -> r.status().code());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,8 +90,7 @@ final class TestHttpCallbackSubscriber implements CoreSubscriber<Integer> {
|
||||
// Tests make a non-empty Mono subscription, which should not signal
|
||||
// onComplete() before onNext(). If we reach here, possibly instrumentation
|
||||
// is not signaling onNext() when it should.
|
||||
callback.accept(null,
|
||||
new AssertionError("onComplete() called before onNext!"));
|
||||
callback.accept(null, new AssertionError("onComplete() called before onNext!"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,25 +48,21 @@ public class WebClientBraveTests extends ITSpringConfiguredReactorClient {
|
||||
* {@link BeanPostProcessor}.
|
||||
*/
|
||||
public WebClientBraveTests() {
|
||||
super(WebClientConfiguration.class, WebClientAutoConfiguration.class,
|
||||
TraceWebClientBeanPostProcessor.class);
|
||||
super(WebClientConfiguration.class, WebClientAutoConfiguration.class, TraceWebClientBeanPostProcessor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
Mono<Integer> postMono(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery, String body) {
|
||||
return context.getBean(WebClient.Builder.class).build().post()
|
||||
.uri(pathIncludingQuery).body(BodyInserters.fromValue(body)).exchange()
|
||||
Mono<Integer> postMono(AnnotationConfigApplicationContext context, String pathIncludingQuery, String body) {
|
||||
return context.getBean(WebClient.Builder.class).build().post().uri(pathIncludingQuery)
|
||||
.body(BodyInserters.fromValue(body)).exchange().map(ClientResponse::rawStatusCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
Mono<Integer> getMono(AnnotationConfigApplicationContext context, String pathIncludingQuery) {
|
||||
return context.getBean(WebClient.Builder.class).build().get().uri(pathIncludingQuery).exchange()
|
||||
.map(ClientResponse::rawStatusCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
Mono<Integer> getMono(AnnotationConfigApplicationContext context,
|
||||
String pathIncludingQuery) {
|
||||
return context.getBean(WebClient.Builder.class).build().get()
|
||||
.uri(pathIncludingQuery).exchange().map(ClientResponse::rawStatusCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("WebClient is blind to the implementation of redirects")
|
||||
@Override
|
||||
@@ -94,8 +90,7 @@ public class WebClientBraveTests extends ITSpringConfiguredReactorClient {
|
||||
*/
|
||||
@Bean
|
||||
@Order(0)
|
||||
public WebClientCustomizer clientConnectorCustomizer(HttpClient httpClient,
|
||||
URI baseUrl) {
|
||||
public WebClientCustomizer clientConnectorCustomizer(HttpClient httpClient, URI baseUrl) {
|
||||
return (builder) -> builder.baseUrl(baseUrl.toString())
|
||||
.clientConnector(new ReactorClientHttpConnector(httpClient));
|
||||
}
|
||||
|
||||
@@ -62,10 +62,8 @@ public class TraceRpcAutoConfigurationIntegrationTests {
|
||||
// tag::custom_rpc_server_sampler[]
|
||||
@Bean(name = RpcServerSampler.NAME)
|
||||
SamplerFunction<RpcRequest> myRpcSampler() {
|
||||
Matcher<RpcRequest> userAuth = and(serviceEquals("users.UserService"),
|
||||
methodEquals("GetUserToken"));
|
||||
return RpcRuleSampler.newBuilder()
|
||||
.putRule(serviceEquals("grpc.health.v1.Health"), Sampler.NEVER_SAMPLE)
|
||||
Matcher<RpcRequest> userAuth = and(serviceEquals("users.UserService"), methodEquals("GetUserToken"));
|
||||
return RpcRuleSampler.newBuilder().putRule(serviceEquals("grpc.health.v1.Health"), Sampler.NEVER_SAMPLE)
|
||||
.putRule(userAuth, RateLimitingSampler.create(100)).build();
|
||||
}
|
||||
// end::custom_rpc_server_sampler[]
|
||||
|
||||
@@ -54,8 +54,8 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
|
||||
TestSpanHandler spans = new TestSpanHandler();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.addSpanHandler(this.spans).build();
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext).addSpanHandler(this.spans)
|
||||
.build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
|
||||
@@ -76,13 +76,11 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
@Test
|
||||
public void should_not_override_existing_custom_hooks() {
|
||||
RxJavaPlugins.getInstance().registerErrorHandler(new MyRxJavaErrorHandler());
|
||||
RxJavaPlugins.getInstance()
|
||||
.registerObservableExecutionHook(new MyRxJavaObservableExecutionHook());
|
||||
RxJavaPlugins.getInstance().registerObservableExecutionHook(new MyRxJavaObservableExecutionHook());
|
||||
|
||||
new SleuthRxJavaSchedulersHook(this.tracer, this.threadsToIgnore);
|
||||
|
||||
then(RxJavaPlugins.getInstance().getErrorHandler())
|
||||
.isExactlyInstanceOf(MyRxJavaErrorHandler.class);
|
||||
then(RxJavaPlugins.getInstance().getErrorHandler()).isExactlyInstanceOf(MyRxJavaErrorHandler.class);
|
||||
then(RxJavaPlugins.getInstance().getObservableExecutionHook())
|
||||
.isExactlyInstanceOf(MyRxJavaObservableExecutionHook.class);
|
||||
}
|
||||
@@ -90,8 +88,7 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
@Test
|
||||
public void should_wrap_delegates_action_in_wrapped_action_when_delegate_is_present_on_schedule() {
|
||||
RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
|
||||
SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(
|
||||
this.tracer, this.threadsToIgnore);
|
||||
SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(this.tracer, this.threadsToIgnore);
|
||||
Action0 action = schedulersHook.onSchedule(() -> {
|
||||
caller = new StringBuilder("hello");
|
||||
});
|
||||
@@ -109,8 +106,8 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
throws ExecutionException, InterruptedException {
|
||||
String threadNameToIgnore = "^MyCustomThread.*$";
|
||||
RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
|
||||
SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(
|
||||
this.tracer, Collections.singletonList(threadNameToIgnore));
|
||||
SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(this.tracer,
|
||||
Collections.singletonList(threadNameToIgnore));
|
||||
Future<Void> hello = executorService().submit((Callable<Void>) () -> {
|
||||
Action0 action = schedulersHook.onSchedule(() -> {
|
||||
caller = new StringBuilder("hello");
|
||||
|
||||
@@ -66,11 +66,8 @@ public class SleuthRxJavaTests {
|
||||
|
||||
@Test
|
||||
public void should_create_new_span_when_rx_java_action_is_executed_and_there_was_no_span() {
|
||||
Observable
|
||||
.defer(() -> Observable.just(
|
||||
(Action0) () -> this.caller = new StringBuffer("actual_action")))
|
||||
.subscribeOn(Schedulers.newThread()).toBlocking()
|
||||
.subscribe(Action0::call);
|
||||
Observable.defer(() -> Observable.just((Action0) () -> this.caller = new StringBuffer("actual_action")))
|
||||
.subscribeOn(Schedulers.newThread()).toBlocking().subscribe(Action0::call);
|
||||
|
||||
then(this.caller.toString()).isEqualTo("actual_action");
|
||||
then(this.tracer.currentSpan()).isNull();
|
||||
@@ -84,10 +81,8 @@ public class SleuthRxJavaTests {
|
||||
Span spanInCurrentThread = this.tracer.nextSpan().name("current_span");
|
||||
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(spanInCurrentThread)) {
|
||||
Observable.defer(() -> Observable.just(
|
||||
(Action0) () -> this.caller = new StringBuffer("actual_action")))
|
||||
.subscribeOn(Schedulers.newThread()).toBlocking()
|
||||
.subscribe(Action0::call);
|
||||
Observable.defer(() -> Observable.just((Action0) () -> this.caller = new StringBuffer("actual_action")))
|
||||
.subscribeOn(Schedulers.newThread()).toBlocking().subscribe(Action0::call);
|
||||
}
|
||||
finally {
|
||||
spanInCurrentThread.finish();
|
||||
|
||||
@@ -93,8 +93,7 @@ public class TracingOnScheduledTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_not_create_span_in_the_scheduled_class_that_matches_skip_pattern()
|
||||
throws Exception {
|
||||
public void should_not_create_span_in_the_scheduled_class_that_matches_skip_pattern() throws Exception {
|
||||
await().atMost(5, SECONDS).untilAsserted(() -> {
|
||||
then(this.beanWithScheduledMethodToBeIgnored.isExecuted()).isTrue();
|
||||
then(this.beanWithScheduledMethodToBeIgnored.getSpan()).isNull();
|
||||
@@ -105,12 +104,10 @@ public class TracingOnScheduledTests {
|
||||
Span storedSpan = TracingOnScheduledTests.this.beanWithScheduledMethod.getSpan();
|
||||
then(storedSpan).isNotNull();
|
||||
then(storedSpan.context().traceId()).isNotNull();
|
||||
MutableSpan foundSpan = spans.spans().stream()
|
||||
.filter(span -> !span.tags().containsKey("error")
|
||||
&& span.tags().containsValue("TestBeanWithScheduledMethod"))
|
||||
MutableSpan foundSpan = spans.spans().stream().filter(
|
||||
span -> !span.tags().containsKey("error") && span.tags().containsValue("TestBeanWithScheduledMethod"))
|
||||
.findFirst().orElseThrow(() -> new AssertionError("Span is missing"));
|
||||
then(foundSpan.tags()).contains(
|
||||
new AbstractMap.SimpleEntry<>("class", "TestBeanWithScheduledMethod"),
|
||||
then(foundSpan.tags()).contains(new AbstractMap.SimpleEntry<>("class", "TestBeanWithScheduledMethod"),
|
||||
new AbstractMap.SimpleEntry<>("method", "scheduledMethod"));
|
||||
then(foundSpan.finishTimestamp()).isGreaterThan(0L);
|
||||
}
|
||||
@@ -119,20 +116,17 @@ public class TracingOnScheduledTests {
|
||||
Span storedSpan = TracingOnScheduledTests.this.beanWithScheduledMethod.getSpan();
|
||||
then(storedSpan).isNotNull();
|
||||
then(storedSpan.context().traceId()).isNotNull();
|
||||
MutableSpan foundSpan = spans.spans().stream()
|
||||
.filter(span -> span.tags().containsKey("error")).findFirst()
|
||||
MutableSpan foundSpan = spans.spans().stream().filter(span -> span.tags().containsKey("error")).findFirst()
|
||||
.orElseThrow(() -> new AssertionError("Span is missing"));
|
||||
then(foundSpan.tags()).contains(
|
||||
new AbstractMap.SimpleEntry<>("class",
|
||||
"TestBeanWithScheduledMethodThatThrowsAnException"),
|
||||
new AbstractMap.SimpleEntry<>("class", "TestBeanWithScheduledMethodThatThrowsAnException"),
|
||||
new AbstractMap.SimpleEntry<>("method", "scheduledMethod"));
|
||||
then(foundSpan.finishTimestamp()).isGreaterThan(0L);
|
||||
then(foundSpan.tags().get("error")).isNotEmpty();
|
||||
}
|
||||
|
||||
private void differentSpanHasBeenSetThan(final Span spanToCompare) {
|
||||
then(TracingOnScheduledTests.this.beanWithScheduledMethod.getSpan())
|
||||
.isNotEqualTo(spanToCompare);
|
||||
then(TracingOnScheduledTests.this.beanWithScheduledMethod.getSpan()).isNotEqualTo(spanToCompare);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -153,8 +147,7 @@ class ScheduledTestConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
TestBeanWithScheduledMethodToBeIgnored testBeanWithScheduledMethodToBeIgnored(
|
||||
Tracing tracing) {
|
||||
TestBeanWithScheduledMethodToBeIgnored testBeanWithScheduledMethodToBeIgnored(Tracing tracing) {
|
||||
return new TestBeanWithScheduledMethodToBeIgnored(tracing);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ public class GH1102Tests {
|
||||
public void should_store_retries_as_separate_spans() throws Exception {
|
||||
ScopedSpan foo = this.tracer.startScopedSpan("foo");
|
||||
try {
|
||||
this.webClient.get().uri("http://localhost:" + this.port + "/test").retrieve()
|
||||
.bodyToMono(String.class).retry(1).block();
|
||||
this.webClient.get().uri("http://localhost:" + this.port + "/test").retrieve().bodyToMono(String.class)
|
||||
.retry(1).block();
|
||||
BDDAssertions.fail("should throw exception");
|
||||
}
|
||||
catch (WebClientResponseException ex) {
|
||||
@@ -72,8 +72,7 @@ public class GH1102Tests {
|
||||
}
|
||||
|
||||
// Default inject format for client spans is B3 multi
|
||||
BDDAssertions.then(this.testRetry.getHttpHeaders().get("x-b3-traceid"))
|
||||
.hasSize(1);
|
||||
BDDAssertions.then(this.testRetry.getHttpHeaders().get("x-b3-traceid")).hasSize(1);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -54,18 +54,14 @@ public class TraceWebFluxTests {
|
||||
@Test
|
||||
public void should_instrument_web_filter() throws Exception {
|
||||
// setup
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TraceWebFluxTests.Config.class)
|
||||
.web(WebApplicationType.REACTIVE)
|
||||
.properties("server.port=0", "spring.jmx.enabled=false",
|
||||
"spring.sleuth.web.skipPattern=/skipped",
|
||||
"spring.application.name=TraceWebFluxTests",
|
||||
"security.basic.enabled=false",
|
||||
"management.security.enabled=false")
|
||||
.run();
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TraceWebFluxTests.Config.class)
|
||||
.web(WebApplicationType.REACTIVE)
|
||||
.properties("server.port=0", "spring.jmx.enabled=false", "spring.sleuth.web.skipPattern=/skipped",
|
||||
"spring.application.name=TraceWebFluxTests", "security.basic.enabled=false",
|
||||
"management.security.enabled=false")
|
||||
.run();
|
||||
TestSpanHandler spans = context.getBean(TestSpanHandler.class);
|
||||
int port = context.getBean(Environment.class).getProperty("local.server.port",
|
||||
Integer.class);
|
||||
int port = context.getBean(Environment.class).getProperty("local.server.port", Integer.class);
|
||||
Controller2 controller2 = context.getBean(Controller2.class);
|
||||
clean(spans, controller2);
|
||||
|
||||
@@ -106,10 +102,8 @@ public class TraceWebFluxTests {
|
||||
controller2.span = null;
|
||||
}
|
||||
|
||||
private void thenSpanWasReportedWithTags(TestSpanHandler spans,
|
||||
ClientResponse response) {
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(response.statusCode().value()).isEqualTo(200));
|
||||
private void thenSpanWasReportedWithTags(TestSpanHandler spans, ClientResponse response) {
|
||||
Awaitility.await().untilAsserted(() -> then(response.statusCode().value()).isEqualTo(200));
|
||||
then(spans).hasSize(1);
|
||||
then(spans.get(0).name()).isEqualTo("GET /api/c2/{id}");
|
||||
then(spans.get(0).tags()).containsEntry("mvc.controller.method", "successful")
|
||||
@@ -117,26 +111,21 @@ public class TraceWebFluxTests {
|
||||
then(spans.get(0).remoteIp()).isEqualTo("127.0.0.1");
|
||||
}
|
||||
|
||||
private void thenSpanWasReportedWithRemoteIpTags(TestSpanHandler spans,
|
||||
ClientResponse response) {
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(response.statusCode().value()).isEqualTo(200));
|
||||
private void thenSpanWasReportedWithRemoteIpTags(TestSpanHandler spans, ClientResponse response) {
|
||||
Awaitility.await().untilAsserted(() -> then(response.statusCode().value()).isEqualTo(200));
|
||||
then(spans).hasSize(1);
|
||||
then(spans.get(0).remoteIp()).isEqualTo("203.0.113.195");
|
||||
}
|
||||
|
||||
private void thenFunctionalSpanWasReportedWithTags(TestSpanHandler spans,
|
||||
ClientResponse response) {
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(response.statusCode().value()).isEqualTo(200));
|
||||
private void thenFunctionalSpanWasReportedWithTags(TestSpanHandler spans, ClientResponse response) {
|
||||
Awaitility.await().untilAsserted(() -> then(response.statusCode().value()).isEqualTo(200));
|
||||
then(spans).hasSize(1);
|
||||
then(spans.get(0).name()).isEqualTo("GET /api/fn/{id}");
|
||||
then(spans.get(0).tags()).hasEntrySatisfying("mvc.controller.class",
|
||||
value -> then(value).startsWith("TraceWebFluxTests$Config$$Lambda$"));
|
||||
}
|
||||
|
||||
private void thenNoSpanWasReported(TestSpanHandler spans, ClientResponse response,
|
||||
Controller2 controller2) {
|
||||
private void thenNoSpanWasReported(TestSpanHandler spans, ClientResponse response, Controller2 controller2) {
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
then(response.statusCode().value()).isEqualTo(200);
|
||||
then(spans).isEmpty();
|
||||
@@ -146,30 +135,25 @@ public class TraceWebFluxTests {
|
||||
}
|
||||
|
||||
private ClientResponse whenRequestIsSent(int port, String path) {
|
||||
Mono<ClientResponse> exchange = WebClient.create().get()
|
||||
.uri("http://localhost:" + port + path).exchange();
|
||||
Mono<ClientResponse> exchange = WebClient.create().get().uri("http://localhost:" + port + path).exchange();
|
||||
return exchange.block();
|
||||
}
|
||||
|
||||
private ClientResponse whenRequestWithXForwardedForIsSent(int port, String path) {
|
||||
Mono<ClientResponse> exchange = WebClient.create().get()
|
||||
.uri("http://localhost:" + port + path)
|
||||
.header("X-Forwarded-For", "203.0.113.195, 70.41.3.18, 150.172.238.178")
|
||||
.exchange();
|
||||
Mono<ClientResponse> exchange = WebClient.create().get().uri("http://localhost:" + port + path)
|
||||
.header("X-Forwarded-For", "203.0.113.195, 70.41.3.18, 150.172.238.178").exchange();
|
||||
return exchange.block();
|
||||
}
|
||||
|
||||
private ClientResponse whenRequestIsSentToSkippedPattern(int port) {
|
||||
Mono<ClientResponse> exchange = WebClient.create().get()
|
||||
.uri("http://localhost:" + port + "/skipped").exchange();
|
||||
Mono<ClientResponse> exchange = WebClient.create().get().uri("http://localhost:" + port + "/skipped")
|
||||
.exchange();
|
||||
return exchange.block();
|
||||
}
|
||||
|
||||
private ClientResponse whenNonSampledRequestIsSent(int port) {
|
||||
Mono<ClientResponse> exchange = WebClient.create().get()
|
||||
.uri("http://localhost:" + port + "/api/c2/10")
|
||||
.header("b3", EXPECTED_TRACE_ID + "-" + EXPECTED_TRACE_ID + "-0")
|
||||
.exchange();
|
||||
Mono<ClientResponse> exchange = WebClient.create().get().uri("http://localhost:" + port + "/api/c2/10")
|
||||
.header("b3", EXPECTED_TRACE_ID + "-" + EXPECTED_TRACE_ID + "-0").exchange();
|
||||
return exchange.block();
|
||||
}
|
||||
|
||||
@@ -201,10 +185,8 @@ public class TraceWebFluxTests {
|
||||
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> route() {
|
||||
return RouterFunctions.route()
|
||||
.GET("/api/fn/{id}", serverRequest -> ServerResponse.ok()
|
||||
.bodyValue(serverRequest.pathVariable("id")))
|
||||
.build();
|
||||
return RouterFunctions.route().GET("/api/fn/{id}",
|
||||
serverRequest -> ServerResponse.ok().bodyValue(serverRequest.pathVariable("id"))).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ public final class SpanUtil {
|
||||
throw new IllegalStateException("Can't instantiate a utility class");
|
||||
}
|
||||
|
||||
static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
// Represents given long id as 16-character lower-hex string
|
||||
public static String idToHex(long id) {
|
||||
|
||||
Reference in New Issue
Block a user