brave.test.TestSpanHandler Java Examples

The following examples show how to use brave.test.TestSpanHandler. 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
Source File: FlatMapTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
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"))
			.map(MutableSpan::traceId).collect(Collectors.toList());
	then(traceIdOfFlatMap).hasSize(1);
	return traceIdOfFlatMap.get(0);
}
 
Example #2
Source File: TraceWebFluxTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
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")
			.containsEntry("mvc.controller.class", "Controller2");
}
 
Example #3
Source File: TraceWebFluxTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
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$"));
}
 
Example #4
Source File: Issue943Tests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_pass_tracing_context_via_spring_integration() {
	try (ConfigurableApplicationContext applicationContext = SpringApplication.run(
			HelloSpringIntegration.class, "--spring.jmx.enabled=false",
			"--server.port=0")) {
		// 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);
			// when
			object = restTemplate
					.getForObject(
							"http://localhost:"
									+ applicationContext.getEnvironment()
											.getProperty("local.server.port")
									+ "/getHelloWorldMessage",
							String.class);
		}

		// then
		TestSpanHandler spans = applicationContext.getBean(TestSpanHandler.class);
		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");
	}
}
 
Example #5
Source File: TraceWebFluxTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
private void thenNoSpanWasReported(TestSpanHandler spans, ClientResponse response,
		Controller2 controller2) {
	Awaitility.await().untilAsserted(() -> {
		then(response.statusCode().value()).isEqualTo(200);
		then(spans).isEmpty();
	});
	then(controller2.span).isNotNull();
	then(controller2.span.context().traceIdString()).isEqualTo(EXPECTED_TRACE_ID);
}
 
Example #6
Source File: TraceMongoDbAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
void should_record_a_span_when_working_with_mongodb_commands(
		@Autowired TestSpanHandler handler) {
	then(handler.spans()).isNotEmpty();
	MutableSpan span = handler.get(0);
	then(span.traceId()).isNotEmpty();
	then(span.tags()).containsKey("mongodb.command");
	then(span.remoteServiceName()).contains("mongodb");
}
 
Example #7
Source File: TraceRpcAutoConfigurationIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #8
Source File: GH1102Tests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #9
Source File: TraceWebFluxTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@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();
	TestSpanHandler spans = context.getBean(TestSpanHandler.class);
	int port = context.getBean(Environment.class).getProperty("local.server.port",
			Integer.class);
	Controller2 controller2 = context.getBean(Controller2.class);
	clean(spans, controller2);

	// when
	ClientResponse response = whenRequestIsSent(port, "/api/c2/10");
	// then
	thenSpanWasReportedWithTags(spans, response);
	clean(spans, controller2);

	// when
	response = whenRequestIsSent(port, "/api/fn/20");
	// then
	thenFunctionalSpanWasReportedWithTags(spans, response);
	spans.clear();

	// when
	ClientResponse nonSampledResponse = whenNonSampledRequestIsSent(port);
	// then
	thenNoSpanWasReported(spans, nonSampledResponse, controller2);
	spans.clear();

	// when
	ClientResponse skippedPatternResponse = whenRequestIsSentToSkippedPattern(port);
	// then
	thenNoSpanWasReported(spans, skippedPatternResponse, controller2);

	// cleanup
	context.close();
}
 
Example #10
Source File: TraceWebFluxTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
private void clean(TestSpanHandler spans, Controller2 controller2) {
	spans.clear();
	controller2.span = null;
}
 
Example #11
Source File: TraceWebFluxTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #12
Source File: TracingOnScheduledTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #13
Source File: Issue502Tests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
public SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #14
Source File: ManuallyCreatedLoadBalancerFeignClientTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
public SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #15
Source File: Issue362Tests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
public SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #16
Source File: Issue393Tests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
public SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #17
Source File: ManuallyCreatedDelegateLoadBalancerFeignClientTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
public SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #18
Source File: TraceContextPropagationChannelInterceptorTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #19
Source File: SleuthRxJavaTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #20
Source File: GrpcTracingIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #21
Source File: TraceFilterIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #22
Source File: Issue469.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #23
Source File: RestTemplateTraceAspectIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #24
Source File: TraceWebAsyncClientAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #25
Source File: Issue585Tests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #26
Source File: TraceFilterWebIntegrationMultipleFiltersTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #27
Source File: TraceAsyncIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #28
Source File: FlatMapTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
private void assertReactorTracing(ConfigurableApplicationContext context,
		CapturedOutput capture) {
	TestSpanHandler spans = context.getBean(TestSpanHandler.class);
	int port = context.getBean(Environment.class).getProperty("local.server.port",
			Integer.class);
	RequestSender sender = context.getBean(RequestSender.class);
	TestConfiguration config = context.getBean(TestConfiguration.class);
	FactoryUser factoryUser = context.getBean(FactoryUser.class);
	sender.port = port;
	spans.clear();

	Awaitility.await().untilAsserted(() -> {
		// when
		LOGGER.info("Start");
		spans.clear();
		String firstTraceId = flatMapTraceId(spans, callFlatMap(port).block());
		// then
		LOGGER.info("Checking first trace id");
		thenAllWebClientCallsHaveSameTraceId(firstTraceId, sender);
		thenSpanInFooHasSameTraceId(firstTraceId, config);
		spans.clear();
		LOGGER.info("All web client calls have same trace id");

		// when
		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);
		LOGGER.info("Id was not reused between calls");
		thenSpanInFooHasSameTraceId(secondTraceId, config);
		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("");
		// and #866
		then(factoryUser.wasSchedulerWrapped).isTrue();
		LOGGER.info("Factory was wrapped");
	});
}
 
Example #29
Source File: FlatMapTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
SpanHandler testSpanHandler() {
	return new TestSpanHandler();
}
 
Example #30
Source File: TraceMongoDbAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
TestSpanHandler testSpanHandler() {
	return new TestSpanHandler();
}