com.github.kristofa.brave.Sampler Java Examples

The following examples show how to use com.github.kristofa.brave.Sampler. 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: TracingConfig.java    From x7 with Apache License 2.0 6 votes vote down vote up
@ConditionalOnMissingBean(Brave.class)
@ConditionalOnBean(SpanCollector.class)
@Bean
public Brave brave(SpanCollector spanCollector, Environment env) {
    String applicationName = env.getProperty("spring.application.name");
    if (StringUtil.isNullOrEmpty(applicationName))
        throw new RuntimeException("spring.application.name=null, config it or #tracing.zipkin.url=");
    Brave.Builder builder = new Brave.Builder(applicationName);
    builder.spanCollector(spanCollector);
    builder.traceSampler(Sampler.create(properties.getSampleRate()));
    logger.info("Tracing(ZipKin): Brave instance created, default add tracing to ReyClient" );
    logger.info("Config Zipkin Servlet Tracing by: @EnableTracingServlet");
    logger.info("create more tracing filter or interceptor for spring boot project, by parameter (Brave brave), like code as follows: ");
    logger.info("       @ConditionalOnMissingBean(BraveServletFilter.class)");
    logger.info("       @ConditionalOnBean(Brave.class)");
    logger.info("       @Bean");
    logger.info("       public BraveServletFilter braveServletFilter(Brave brave) {");

    return builder.build();
}
 
Example #2
Source File: ZipkinConfig.java    From spring-cloud-k8s-sample with Apache License 2.0 5 votes vote down vote up
@Bean
public Brave brave(SpanCollector spanCollector) {
	Brave.Builder builder = new Brave.Builder(applicationName);// 指定serviceName
	builder.spanCollector(spanCollector);
	builder.traceSampler(Sampler.create(1));// 采集率
	return builder.build();
}
 
Example #3
Source File: ZipkinConfig.java    From spring-cloud-k8s-sample with Apache License 2.0 5 votes vote down vote up
@Bean
public Brave brave(SpanCollector spanCollector) {
	Brave.Builder builder = new Brave.Builder(applicationName);// 指定serviceName
	builder.spanCollector(spanCollector);
	builder.traceSampler(Sampler.create(1));// 采集率
	return builder.build();
}
 
Example #4
Source File: ZipkinConfig.java    From spring-cloud-k8s-sample with Apache License 2.0 5 votes vote down vote up
@Bean
public Brave brave(SpanCollector spanCollector) {
	Brave.Builder builder = new Brave.Builder(applicationName);// 指定serviceName
	builder.spanCollector(spanCollector);
	builder.traceSampler(Sampler.create(1));// 采集率
	return builder.build();
}
 
Example #5
Source File: ZipkinConfig.java    From spring-cloud-k8s-sample with Apache License 2.0 5 votes vote down vote up
@Bean
public Brave brave(SpanCollector spanCollector) {
	Brave.Builder builder = new Brave.Builder(applicationName);// 指定serviceName
	builder.spanCollector(spanCollector);
	builder.traceSampler(Sampler.create(1));// 采集率
	return builder.build();
}
 
Example #6
Source File: BraveConfig.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
Brave.Builder braveBuilder(Sampler sampler) {
    com.twitter.zipkin.gen.Endpoint localEndpoint = com.twitter.zipkin.gen.Endpoint.builder()
            .ipv4(local.ipv4)
            .ipv6(local.ipv6)
            .port(local.port)
            .serviceName(local.serviceName)
            .build();
    return new Brave.Builder(new InheritableServerClientAndLocalSpanState(localEndpoint))
            .reporter(new Slf4jLogReporter("zipkin"))
            .traceSampler(sampler);
}
 
Example #7
Source File: ApplicationConfiguration.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
Brave.Builder braveBuilder(Sampler sampler) {
    com.twitter.zipkin.gen.Endpoint localEndpoint = com.twitter.zipkin.gen.Endpoint.builder()
            .ipv4(local.ipv4)
            .ipv6(local.ipv6)
            .port(local.port)
            .serviceName(local.serviceName)
            .build();
    return new Brave.Builder(new InheritableServerClientAndLocalSpanState(localEndpoint))
            .reporter(new Slf4jLogReporter("zipkin"))
            .traceSampler(sampler);
}
 
Example #8
Source File: BraveConfig.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
Brave.Builder braveBuilder(Sampler sampler) {
    com.twitter.zipkin.gen.Endpoint localEndpoint = com.twitter.zipkin.gen.Endpoint.builder()
            .ipv4(local.ipv4)
            .ipv6(local.ipv6)
            .port(local.port)
            .serviceName(local.serviceName)
            .build();
    return new Brave.Builder(new InheritableServerClientAndLocalSpanState(localEndpoint))
            .reporter(new Slf4jLogReporter("zipkin"))
            .traceSampler(sampler);
}
 
Example #9
Source File: ZipkinFraction.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public Brave getBraveInstance() {

        Brave.Builder builder = new Brave.Builder(name.get());

        if (this.url.isDefault()) {
            builder.reporter(new LoggingReporter())
                           .traceSampler(Sampler.create(1.0f));
        } else {
            AsyncReporter<Span> asyncReporter = AsyncReporter.builder(URLConnectionSender.create(url.get())).build();
            builder.reporter(asyncReporter)
                    .traceSampler(Sampler.create(rate.get()));
        }
        return builder.build();
    }
 
Example #10
Source File: BraveFactory.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public Brave create() {
    final Brave.Builder builder = new Brave.Builder();
    final Brave brave = builder
            .reporter(new LoggingReporter())
            .traceSampler(Sampler.create(1.0f)) // retain 100% of traces
            .build();
    return brave;
}
 
Example #11
Source File: Constant.java    From grpc-by-example-java with Apache License 2.0 5 votes vote down vote up
public static Brave brave(String serviceName) {
  return new Brave.Builder(serviceName)
      .traceSampler(Sampler.ALWAYS_SAMPLE)
      .reporter(AsyncReporter.builder(URLConnectionSender.builder()
          .endpoint("http://docker-machine.dev:8080/api/v1/spans")
          .build()).build())
      .build();
}
 
Example #12
Source File: BraveConfig.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
@Bean
public Brave brave() {
    //default reporter LoggingSpanCollector
    Brave.Builder builder = braveBuilder(Sampler.ALWAYS_SAMPLE);
    return builder.build();
}
 
Example #13
Source File: ApplicationConfiguration.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
@Bean
public Brave brave() {
    //default reporter LoggingSpanCollector
    Brave.Builder builder = braveBuilder(Sampler.ALWAYS_SAMPLE);
    return builder.build();
}
 
Example #14
Source File: BraveConfig.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
@Bean
public Brave brave() {
    //default reporter LoggingSpanCollector
    Brave.Builder builder = braveBuilder(Sampler.ALWAYS_SAMPLE);
    return builder.build();
}
 
Example #15
Source File: TracingEndpointCaller.java    From odata with Apache License 2.0 4 votes vote down vote up
public TracingEndpointCaller(Properties properties) {
    Integer timeout = getIntegerProperty(properties, CLIENT_CONNECTION_TIMEOUT, CLIENT_TIMEOUT_DEFAULT);

    String proxyServerHostName = getStringProperty(properties, CLIENT_SERVICE_PROXY_HOST_NAME);
    Integer proxyPort = getIntegerProperty(properties, CLIENT_SERVICE_PROXY_PORT);
    Integer proxyServerPort = proxyPort == null ? CLIENT_PROXY_PORT_DEFAULT : proxyPort;

    RequestConfig config = RequestConfig.custom()
            .setConnectTimeout(timeout)
            .setConnectionRequestTimeout(timeout)
            .setSocketTimeout(timeout)
            .build();

    HttpClientBuilder httpClientBuilder = HttpClients.custom()
            .setConnectionManager(new PoolingHttpClientConnectionManager())
            .setDefaultRequestConfig(config);
    if (!isBlank(proxyServerHostName) && proxyServerPort > 0) {
        httpClientBuilder.setProxy(new HttpHost(proxyServerHostName, proxyServerPort));
    }

    // load application.properties to know zipkin host, service name and how often to collect spans
    Properties applicationProperties = new Properties();
    try (InputStream stream = this.getClass().getResourceAsStream(APPLICATION_PROPERTIES_FILE_NAME)) {
        if (stream != null) {
            applicationProperties.load(stream);
        }
    } catch (IOException e) {
        LOG.warn("'{}' file is not available in the classpath", APPLICATION_PROPERTIES_FILE_NAME);
    }

    Brave brave = new Brave.Builder(applicationProperties.getProperty("spring.application.name", "cil-call"))
            .traceSampler(Sampler.create(
                    Float.valueOf(applicationProperties.getProperty("spring.sleuth.sampler.percentage", "1.0"))))
            .reporter(AsyncReporter.builder(URLConnectionSender.builder().endpoint(
                    applicationProperties.getProperty("spring.zipkin.baseUrl", DEFAULT_ZIPKIN_HOSTNAME)).build())
                    .build()).build();

    closeableHttpClient = httpClientBuilder
            .addInterceptorFirst(BraveHttpRequestInterceptor.builder(brave).build())
                    //new BraveHttpRequestInterceptor(brave.clientRequestInterceptor(),
                    //new DefaultSpanNameProvider()))
            .addInterceptorFirst(BraveHttpResponseInterceptor.builder(brave).build())
                    //new BraveHttpResponseInterceptor(brave.clientResponseInterceptor()))
            .build();
}