brave.spring.web.TracingClientHttpRequestInterceptor Java Examples

The following examples show how to use brave.spring.web.TracingClientHttpRequestInterceptor. 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: TraceRestTemplateInterceptorTests.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Test
public void notSampledHeaderAddedWhenNotSampled() {
	this.tracing.close();
	this.tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
			.addSpanHandler(this.spans).sampler(Sampler.NEVER_SAMPLE).build();
	this.template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
			TracingClientHttpRequestInterceptor.create(HttpTracing.create(tracing))));

	Span span = tracing.tracer().nextSpan().name("new trace");
	Map<String, String> headers;

	try (Tracer.SpanInScope ws = tracing.tracer().withSpanInScope(span.start())) {
		headers = this.template.getForEntity("/", Map.class).getBody();
	}
	finally {
		span.finish();
	}

	then(this.spans).isEmpty();
}
 
Example #2
Source File: TraceWebClientAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
private void assertInterceptorsOrder(
		List<ClientHttpRequestInterceptor> interceptors) {
	int traceInterceptorIndex = -1;
	int myInterceptorIndex = -1;
	int mySecondInterceptorIndex = -1;
	Map<Class, Integer> numberOfInstances = new HashMap<>();
	for (int i = 0; i < interceptors.size(); i++) {
		ClientHttpRequestInterceptor interceptor = interceptors.get(i);
		incrementNumberOfInstances(numberOfInstances, interceptor);
		if (interceptor instanceof TracingClientHttpRequestInterceptor
				|| interceptor instanceof LazyTracingClientHttpRequestInterceptor) {
			traceInterceptorIndex = i;
		}
		else if (interceptor instanceof MyClientHttpRequestInterceptor) {
			myInterceptorIndex = i;
		}
		else if (interceptor instanceof MySecondClientHttpRequestInterceptor) {
			mySecondInterceptorIndex = i;
		}
	}
	then(traceInterceptorIndex).isGreaterThanOrEqualTo(0)
			.isLessThan(myInterceptorIndex).isLessThan(mySecondInterceptorIndex);
	then(numberOfInstances.values())
			.as("Can't have duplicate entries for interceptors")
			.containsOnlyElementsOf(Collections.singletonList(1));
}
 
Example #3
Source File: RestTemplateConfig.java    From txle with Apache License 2.0 5 votes vote down vote up
@Bean
public RestTemplate restTemplate(@Autowired(required = false) OmegaContext context, @Autowired Tracing tracing) {
  RestTemplate template = new RestTemplate();
  List<ClientHttpRequestInterceptor> interceptors = template.getInterceptors();
  interceptors.add(new TransactionClientHttpRequestInterceptor(context));
  // add interceptor for rest's request server By Gannalyo
  interceptors.add(TracingClientHttpRequestInterceptor.create(tracing));
  template.setInterceptors(interceptors);
  return template;
}
 
Example #4
Source File: TraceWebClientAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
private boolean hasTraceInterceptor(RestTemplate restTemplate) {
	for (ClientHttpRequestInterceptor interceptor : restTemplate.getInterceptors()) {
		if (interceptor instanceof TracingClientHttpRequestInterceptor
				|| interceptor instanceof LazyTracingClientHttpRequestInterceptor) {
			return true;
		}
	}
	return false;
}
 
Example #5
Source File: TraceWebClientAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
private TracingClientHttpRequestInterceptor interceptor() {
	if (this.interceptor == null) {
		this.interceptor = this.beanFactory
				.getBean(TracingClientHttpRequestInterceptor.class);
	}
	return this.interceptor;
}
 
Example #6
Source File: TraceWebClientAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(OAuth2RestTemplate template) {
	final TracingClientHttpRequestInterceptor interceptor = this.beanFactory
			.getBean(TracingClientHttpRequestInterceptor.class);
	new RestTemplateInterceptorInjector(interceptor).inject(template);
	if (this.delegate != null) {
		((UserInfoRestTemplateCustomizer) this.delegate).customize(template);
	}
}
 
Example #7
Source File: RestTemplateBenchmark.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() {
	new SpringApplication(SleuthBenchmarkingSpringApp.class).run(
			"--spring.jmx.enabled=false", "--spring.application.name=withSleuth");
	this.mockMvc = MockMvcBuilders
			.standaloneSetup(
					this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
			.build();
	this.tracedTemplate = new RestTemplate(
			new MockMvcClientHttpRequestFactory(this.mockMvc));
	this.tracedTemplate.setInterceptors(Collections.singletonList(
			this.withSleuth.getBean(TracingClientHttpRequestInterceptor.class)));
	this.untracedTemplate = new RestTemplate(
			new MockMvcClientHttpRequestFactory(this.mockMvc));
}
 
Example #8
Source File: TraceWebClientAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
public TracingClientHttpRequestInterceptor tracingClientHttpRequestInterceptor(
		HttpTracing httpTracing) {
	return (TracingClientHttpRequestInterceptor) TracingClientHttpRequestInterceptor
			.create(httpTracing);
}
 
Example #9
Source File: TraceRestTemplateInterceptorTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
private void setInterceptors(HttpTracing httpTracing) {
	this.template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
			TracingClientHttpRequestInterceptor.create(httpTracing)));
}
 
Example #10
Source File: TraceRestTemplateInterceptorIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setup() {
	this.template.setInterceptors(Arrays
			.<ClientHttpRequestInterceptor>asList(TracingClientHttpRequestInterceptor
					.create(HttpTracing.create(this.tracing))));
}
 
Example #11
Source File: ITTracingClientHttpRequestInterceptor.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override protected ClientHttpRequestFactory newClient(int port) {
  return configureClient(TracingClientHttpRequestInterceptor.create(httpTracing));
}