Java Code Examples for org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration

The following examples show how to use org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
void defaultsToV2Endpoint() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.base-url",
			this.server.url("/").toString());
	this.context.register(ZipkinAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
			Config.class);
	this.context.refresh();
	Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
			.tag("foo", "bar").start();

	span.finish();

	Awaitility.await().untilAsserted(
			() -> then(this.server.getRequestCount()).isGreaterThan(1));
	// first request is for health check
	this.server.takeRequest();
	// second request is the span one
	RecordedRequest request = this.server.takeRequest();
	then(request.getPath()).isEqualTo("/api/v2/spans");
	then(request.getBody().readUtf8()).contains("localEndpoint");
}
 
Example 2
@Test
public void encoderDirectsEndpoint() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.base-url",
			this.server.url("/").toString());
	environment().setProperty("spring.zipkin.encoder", "JSON_V1");
	this.context.register(ZipkinAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
			Config.class);
	this.context.refresh();
	Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
			.tag("foo", "bar").start();

	span.finish();

	Awaitility.await().untilAsserted(
			() -> then(this.server.getRequestCount()).isGreaterThan(0));
	// first request is for health check
	this.server.takeRequest();
	// second request is the span one
	RecordedRequest request = this.server.takeRequest();
	then(request.getPath()).isEqualTo("/api/v1/spans");
	then(request.getBody().readUtf8()).contains("binaryAnnotations");
}
 
Example 3
@Test
public void overrideActiveMqQueue() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.jms.cache.enabled", "false");
	environment().setProperty("spring.zipkin.activemq.queue", "zipkin2");
	environment().setProperty("spring.zipkin.activemq.message-max-bytes", "50");
	environment().setProperty("spring.zipkin.sender.type", "activemq");
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			ActiveMQAutoConfiguration.class, ZipkinAutoConfiguration.class,
			TraceAutoConfiguration.class);
	this.context.refresh();

	then(this.context.getBean(Sender.class)).isInstanceOf(ActiveMQSender.class);

	this.context.close();
}
 
Example 4
@Test
public void testWithSleuth() {
	this.contextRunner
			.withConfiguration(AutoConfigurations.of(StackdriverTraceAutoConfiguration.class,
					TraceAutoConfiguration.class))
			.withUserConfiguration(Configuration.class)
			.withPropertyValues("spring.cloud.gcp.project-id=pop-1")
			.run((context) -> assertThat(context
					.getBeansOfType(TraceIdLoggingWebMvcInterceptor.class).size())
							.isEqualTo(0));
}
 
Example 5
@Test
public void overrideRabbitMQQueue() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.rabbitmq.queue", "zipkin2");
	environment().setProperty("spring.zipkin.sender.type", "rabbit");
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			RabbitAutoConfiguration.class, ZipkinAutoConfiguration.class,
			TraceAutoConfiguration.class);
	this.context.refresh();

	then(this.context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);

	this.context.close();
}
 
Example 6
@Test
public void overrideKafkaTopic() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.kafka.topic", "zipkin2");
	environment().setProperty("spring.zipkin.sender.type", "kafka");
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			KafkaAutoConfiguration.class, ZipkinAutoConfiguration.class,
			TraceAutoConfiguration.class);
	this.context.refresh();

	then(this.context.getBean(Sender.class)).isInstanceOf(KafkaSender.class);

	this.context.close();
}
 
Example 7
@Test
public void canOverrideBySender() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.sender.type", "web");
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
			ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
	this.context.refresh();

	then(this.context.getBean(Sender.class).getClass().getName())
			.contains("RestTemplateSender");

	this.context.close();
}
 
Example 8
@Test
public void canOverrideBySenderAndIsCaseInsensitive() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.sender.type", "WEB");
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
			ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
	this.context.refresh();

	then(this.context.getBean(Sender.class).getClass().getName())
			.contains("RestTemplateSender");

	this.context.close();
}
 
Example 9
@Test
public void rabbitWinsWhenKafkaPresent() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.sender.type", "rabbit");
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
			ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
	this.context.refresh();

	then(this.context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);

	this.context.close();
}
 
Example 10
@Test
public void supportsMultipleReporters() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.base-url",
			this.server.url("/").toString());
	this.context.register(ZipkinAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
			Config.class, MultipleReportersConfig.class);
	this.context.refresh();

	then(this.context.getBeansOfType(Sender.class)).hasSize(2);
	then(this.context.getBeansOfType(Sender.class))
			.containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME, "otherSender");

	then(this.context.getBeansOfType(Reporter.class)).hasSize(2);
	then(this.context.getBeansOfType(Reporter.class)).containsKeys(
			ZipkinAutoConfiguration.REPORTER_BEAN_NAME, "otherReporter");

	Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
			.tag("foo", "bar").start();

	span.finish();

	Awaitility.await().untilAsserted(
			() -> then(this.server.getRequestCount()).isGreaterThan(1));
	// first request is for health check
	this.server.takeRequest();
	// second request is the span one
	RecordedRequest request = this.server.takeRequest();
	then(request.getPath()).isEqualTo("/api/v2/spans");
	then(request.getBody().readUtf8()).contains("localEndpoint");

	MultipleReportersConfig.OtherSender sender = this.context
			.getBean(MultipleReportersConfig.OtherSender.class);
	Awaitility.await().untilAsserted(() -> then(sender.isSpanSent()).isTrue());
}
 
Example 11
@Test
public void shouldOverrideDefaultBeans() {
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ZipkinAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
			Config.class, MyConfig.class);
	this.context.refresh();

	then(this.context.getBeansOfType(Sender.class)).hasSize(1);
	then(this.context.getBeansOfType(Sender.class))
			.containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME);

	then(this.context.getBeansOfType(Reporter.class)).hasSize(1);
	then(this.context.getBeansOfType(Reporter.class))
			.containsKeys(ZipkinAutoConfiguration.REPORTER_BEAN_NAME);

	Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
			.tag("foo", "bar").start();

	span.finish();

	Awaitility.await()
			.untilAsserted(() -> then(this.server.getRequestCount()).isEqualTo(0));

	MyConfig.MySender sender = this.context.getBean(MyConfig.MySender.class);
	Awaitility.await().untilAsserted(() -> then(sender.isSpanSent()).isTrue());
}
 
Example 12
private ApplicationContextRunner contextRunner(String... propertyValues) {
	return new ApplicationContextRunner().withPropertyValues(propertyValues)
			.withConfiguration(AutoConfigurations.of(TraceAutoConfiguration.class,
					TraceHttpAutoConfiguration.class,
					SkipPatternConfiguration.class));
}
 
Example 13
private ApplicationContextRunner contextRunner(String... propertyValues) {
	return new ApplicationContextRunner().withPropertyValues(propertyValues)
			.withConfiguration(AutoConfigurations.of(TraceAutoConfiguration.class,
					TraceRpcAutoConfiguration.class));
}
 
Example 14
private ApplicationContextRunner contextRunner(String... propertyValues) {
	return new ApplicationContextRunner().withPropertyValues(propertyValues)
			.withConfiguration(AutoConfigurations.of(TraceAutoConfiguration.class,
					TraceMessagingAutoConfiguration.class));
}