brave.http.HttpRequest Java Examples

The following examples show how to use brave.http.HttpRequest. 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: ITHttpServer.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void customSampler() throws IOException {
  String path = "/foo";

  SamplerFunction<HttpRequest> sampler = HttpRuleSampler.newBuilder()
    .putRule(pathStartsWith(path), Sampler.NEVER_SAMPLE)
    .build();

  httpTracing = httpTracing.toBuilder().serverSampler(sampler).build();
  init();

  Request request = new Request.Builder().url(url(path)).build();
  try (Response response = client.newCall(request).execute()) {
    assertThat(response.isSuccessful()).isTrue();
  }

  // @After will check that nothing is reported
}
 
Example #2
Source File: ITHttpClient.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void customSampler() throws IOException {
  String path = "/foo";

  closeClient(client);

  SamplerFunction<HttpRequest> sampler = HttpRuleSampler.newBuilder()
    .putRule(pathStartsWith(path), Sampler.NEVER_SAMPLE)
    .build();

  httpTracing = httpTracing.toBuilder().clientSampler(sampler).build();
  client = newClient(server.getPort());

  server.enqueue(new MockResponse());
  get(client, path);

  assertThat(extract(takeRequest()).sampled()).isFalse();
}
 
Example #3
Source File: TraceHttpAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
private SamplerFunction<HttpRequest> combineUserProvidedSamplerWithSkipPatternSampler(
		@Nullable SamplerFunction<HttpRequest> serverSampler,
		@Nullable SkipPatternProvider provider) {
	SamplerFunction<HttpRequest> skipPatternSampler = provider != null
			? new SkipPatternHttpServerSampler(provider) : null;
	if (serverSampler == null && skipPatternSampler == null) {
		return SamplerFunctions.deferDecision();
	}
	else if (serverSampler == null) {
		return skipPatternSampler;
	}
	else if (skipPatternSampler == null) {
		return serverSampler;
	}
	return new CompositeHttpSampler(skipPatternSampler, serverSampler);
}
 
Example #4
Source File: TraceHttpAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean trySample(HttpRequest request) {
	// If either decision is false, return false
	Boolean leftDecision = this.left.trySample(request);
	if (Boolean.FALSE.equals(leftDecision)) {
		return false;
	}
	Boolean rightDecision = this.right.trySample(request);
	if (Boolean.FALSE.equals(rightDecision)) {
		return false;
	}
	// If either decision is null, return the other
	if (leftDecision == null) {
		return rightDecision;
	}
	if (rightDecision == null) {
		return leftDecision;
	}
	// Neither are null and at least one is true
	return rightDecision;
}
 
Example #5
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
private ContextConsumer<AssertableApplicationContext> thenCompositeHttpServerSamplerOf(
		SamplerFunction<HttpRequest> instance) {
	return (context) -> {

		SamplerFunction<HttpRequest> serverSampler = context
				.getBean(HttpTracing.class).serverRequestSampler();

		then(serverSampler).isInstanceOf(CompositeHttpSampler.class);

		then(((CompositeHttpSampler) serverSampler).left)
				.isInstanceOf(SkipPatternHttpServerSampler.class);
		then(((CompositeHttpSampler) serverSampler).right).isSameAs(instance);
	};
}
 
Example #6
Source File: TraceHttpAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(name = HttpClientSampler.NAME)
SamplerFunction<HttpRequest> sleuthHttpClientSampler(
		SleuthWebProperties sleuthWebProperties) {
	String skipPattern = sleuthWebProperties.getClient().getSkipPattern();
	if (skipPattern == null) {
		return SamplerFunctions.deferDecision();
	}

	return new SkipPatternHttpClientSampler(Pattern.compile(skipPattern));
}
 
Example #7
Source File: TraceFilterWebIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean(name = HttpServerSampler.NAME)
SamplerFunction<HttpRequest> myHttpSampler(SkipPatternProvider provider) {
	Pattern pattern = provider.skipPattern();
	return request -> {
		String url = request.path();
		boolean shouldSkip = pattern.matcher(url).matches();
		if (shouldSkip) {
			return false;
		}
		return null;
	};
}
 
Example #8
Source File: SkipPatternSampler.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Override
public final Boolean trySample(HttpRequest request) {
	String url = request.path();
	boolean shouldSkip = pattern().matcher(url).matches();
	if (shouldSkip) {
		return false;
	}
	return null;
}
 
Example #9
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultsClientSamplerToDefer() {
	contextRunner().run((context) -> {
		SamplerFunction<HttpRequest> clientSampler = context
				.getBean(HttpTracing.class).clientRequestSampler();

		then(clientSampler).isSameAs(SamplerFunctions.deferDecision());
	});
}
 
Example #10
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void configuresClientSkipPattern() throws Exception {
	contextRunner()
			.withPropertyValues("spring.sleuth.web.client.skip-pattern=foo.*|bar.*")
			.run((context) -> {
				SamplerFunction<HttpRequest> clientSampler = context
						.getBean(HttpTracing.class).clientRequestSampler();

				then(clientSampler).isInstanceOf(SkipPatternHttpClientSampler.class);
			});
}
 
Example #11
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void configuresUserProvidedHttpClientSampler() {
	contextRunner().withUserConfiguration(HttpClientSamplerConfig.class)
			.run((context) -> {
				SamplerFunction<HttpRequest> clientSampler = context
						.getBean(HttpTracing.class).clientRequestSampler();

				then(clientSampler).isSameAs(HttpClientSamplerConfig.INSTANCE);
			});
}
 
Example #12
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultsServerSamplerToSkipPattern() {
	contextRunner().run((context) -> {
		SamplerFunction<HttpRequest> serverSampler = context
				.getBean(HttpTracing.class).serverRequestSampler();

		then(serverSampler).isInstanceOf(SkipPatternHttpServerSampler.class);
	});
}
 
Example #13
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultsServerSamplerToDeferWhenSkipPatternCleared() {
	contextRunner().withPropertyValues("spring.sleuth.web.skip-pattern")
			.run((context) -> {
				SamplerFunction<HttpRequest> clientSampler = context
						.getBean(HttpTracing.class).serverRequestSampler();

				then(clientSampler).isSameAs(SamplerFunctions.deferDecision());
			});
}
 
Example #14
Source File: ManuallyCreatedLoadBalancerFeignClientTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean(name = HttpClientSampler.NAME)
@HttpClientSampler
public SamplerFunction<HttpRequest> clientHttpSampler() {
	return arg -> true;
}
 
Example #15
Source File: CompositeHttpSamplerTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean trySample(HttpRequest arg) {
	return null;
}
 
Example #16
Source File: Issue502Tests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean(name = HttpClientSampler.NAME)
@HttpClientSampler
public SamplerFunction<HttpRequest> clientHttpSampler() {
	return arg -> true;
}
 
Example #17
Source File: HttpTracingFactoryBean.java    From brave with Apache License 2.0 4 votes vote down vote up
public void setServerSampler(SamplerFunction<HttpRequest> serverSampler) {
  this.serverSampler = serverSampler;
}
 
Example #18
Source File: ManuallyCreatedDelegateLoadBalancerFeignClientTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean(name = HttpClientSampler.NAME)
@HttpClientSampler
public SamplerFunction<HttpRequest> clientHttpSampler() {
	return arg -> true;
}
 
Example #19
Source File: HttpTracingFactoryBean.java    From brave with Apache License 2.0 4 votes vote down vote up
public void setClientSampler(SamplerFunction<HttpRequest> clientSampler) {
  this.clientSampler = clientSampler;
}
 
Example #20
Source File: AbstractZipkinFactory.java    From dropwizard-zipkin with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public SamplerFunction<HttpRequest> getClientSampler() {
  return clientSampler;
}
 
Example #21
Source File: CompositeHttpSamplerTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean trySample(HttpRequest arg) {
	return false;
}
 
Example #22
Source File: CompositeHttpSamplerTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean trySample(HttpRequest arg) {
	return true;
}
 
Example #23
Source File: CompositeHttpSamplerTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@MethodSource("falseArgs")
void should_return_false_on_any_false(SamplerFunction<HttpRequest> left,
		SamplerFunction<HttpRequest> right) {
	then(new CompositeHttpSampler(left, right).trySample(this.request)).isFalse();
}
 
Example #24
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean(HttpServerSampler.NAME)
SamplerFunction<HttpRequest> sleuthHttpServerSampler() {
	return INSTANCE;
}
 
Example #25
Source File: TraceHttpAutoConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean(HttpClientSampler.NAME)
SamplerFunction<HttpRequest> sleuthHttpClientSampler() {
	return INSTANCE;
}
 
Example #26
Source File: TraceHttpAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
CompositeHttpSampler(SamplerFunction<HttpRequest> left,
		SamplerFunction<HttpRequest> right) {
	this.left = left;
	this.right = right;
}
 
Example #27
Source File: TraceHttpAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
// NOTE: stable bean name as might be used outside sleuth
HttpTracing httpTracing(Tracing tracing, @Nullable SkipPatternProvider provider,
		@Nullable @HttpClientRequestParser HttpRequestParser httpClientRequestParser,
		@Nullable @HttpClientResponseParser HttpResponseParser httpClientResponseParser,
		@Nullable brave.http.HttpClientParser clientParser,
		@Nullable @HttpServerRequestParser HttpRequestParser httpServerRequestParser,
		@Nullable @HttpServerResponseParser HttpResponseParser httpServerResponseParser,
		@Nullable brave.http.HttpServerParser serverParser,
		@HttpClientSampler SamplerFunction<HttpRequest> httpClientSampler,
		@Nullable @HttpServerSampler SamplerFunction<HttpRequest> httpServerSampler,
		@Nullable List<HttpTracingCustomizer> httpTracingCustomizers) {
	SamplerFunction<HttpRequest> combinedSampler = combineUserProvidedSamplerWithSkipPatternSampler(
			httpServerSampler, provider);
	HttpTracing.Builder builder = HttpTracing.newBuilder(tracing)
			.clientSampler(httpClientSampler).serverSampler(combinedSampler);

	if (httpClientRequestParser != null || httpClientResponseParser != null) {
		if (httpClientRequestParser != null) {
			builder.clientRequestParser(httpClientRequestParser);
		}
		if (httpClientResponseParser != null) {
			builder.clientResponseParser(httpClientResponseParser);
		}
	}
	else if (clientParser != null) { // consider deprecated last
		builder.clientParser(clientParser);
	}

	if (httpServerRequestParser != null || httpServerResponseParser != null) {
		if (httpServerRequestParser != null) {
			builder.serverRequestParser(httpServerRequestParser);
		}
		if (httpServerResponseParser != null) {
			builder.serverResponseParser(httpServerResponseParser);
		}
	}
	else if (serverParser != null) { // consider deprecated last
		builder.serverParser(serverParser);
	}

	if (httpTracingCustomizers != null) {
		for (HttpTracingCustomizer customizer : httpTracingCustomizers) {
			customizer.customize(builder);
		}
	}
	return builder.build();
}
 
Example #28
Source File: AbstractZipkinFactory.java    From dropwizard-zipkin with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public void setServerSampler(SamplerFunction<HttpRequest> sampler) {
  this.serverSampler = sampler;
}
 
Example #29
Source File: AbstractZipkinFactory.java    From dropwizard-zipkin with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public SamplerFunction<HttpRequest> getServerSampler() {
  return serverSampler;
}
 
Example #30
Source File: AbstractZipkinFactory.java    From dropwizard-zipkin with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public void setClientSampler(SamplerFunction<HttpRequest> sampler) {
  this.clientSampler = sampler;
}