com.github.kristofa.brave.Brave Java Examples
The following examples show how to use
com.github.kristofa.brave.Brave.
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: App.java From hawkular-apm with Apache License 2.0 | 6 votes |
@Override public void run(AppConfiguration configuration, Environment environment) throws Exception { configuration.getZipkinClient().setTimeout(Duration.seconds(50)); configuration.getZipkinClient().setConnectionRequestTimeout(Duration.seconds(50)); Brave brave = configuration.getZipkinFactory().build(environment).get(); final Client client = new ZipkinClientBuilder(environment, brave) .build(configuration.getZipkinClient()); new MySQLStatementInterceptorManagementBean(brave.clientTracer()); /** * Database */ createDatabase(); DatabaseUtils.executeDatabaseScript("init.sql"); UserDAO userDAO = new UserDAO(); // Register resources environment.jersey().register(new HelloHandler()); environment.jersey().register(new SyncHandler(client)); environment.jersey().register(new AsyncHandler(client, brave)); environment.jersey().register(new UsersHandler(userDAO, client, brave)); }
Example #2
Source File: TracingConfig.java From x7 with Apache License 2.0 | 6 votes |
@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 #3
Source File: GoodbyeServer.java From grpc-by-example-java with Apache License 2.0 | 6 votes |
static public void main(String[] args) throws IOException, InterruptedException { Brave brave = Constant.brave("goodbye-service"); ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext() .intercept(new BraveGrpcClientInterceptor(brave)) .build(); GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(channel); Server goodbyeServer = ServerBuilder.forPort(9090) .addService(ServerInterceptors.intercept(new GoodbyeServiceImpl(greetingStub), new BraveGrpcServerInterceptor(brave), MonitoringServerInterceptor.create(Configuration.allMetrics()))) .build(); goodbyeServer.start(); PrometheusServer prometheusServer = new PrometheusServer(CollectorRegistry.defaultRegistry, 8081); prometheusServer.start(); System.out.println("Server started!"); goodbyeServer.awaitTermination(); prometheusServer.shutdown(); }
Example #4
Source File: BraveFactory.java From thorntail with Apache License 2.0 | 5 votes |
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 #5
Source File: ApplicationConfiguration.java From j360-dubbo-app-all with Apache License 2.0 | 5 votes |
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 #6
Source File: BraveConfig.java From j360-dubbo-app-all with Apache License 2.0 | 5 votes |
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: MSF4JZipkinTracingInterceptor.java From msf4j with Apache License 2.0 | 5 votes |
/** * Constructor of the MSF4JTracingInterceptor. * * @param microServiceName Name of the Microservice * @param zipkinUrl Base URL of the Zipkin server */ public MSF4JZipkinTracingInterceptor(String microServiceName, String zipkinUrl) { Brave.Builder builder = new Brave.Builder(microServiceName); builder.spanCollector(HttpSpanCollector.create(zipkinUrl, new EmptySpanCollectorMetricsHandler())); Brave brave = builder.build(); reqInterceptor = brave.serverRequestInterceptor(); respInterceptor = brave.serverResponseInterceptor(); }
Example #8
Source File: FeginZipkinTracingClient.java From msf4j with Apache License 2.0 | 5 votes |
/** * Constructor of FeginZipkinTracingClient. * * @param client * @param instanceName * @param zipkinUrl URL of the receiver of DAS server. */ public FeginZipkinTracingClient(Client client, String instanceName, String zipkinUrl) { this.clientDelegate = client; Brave.Builder builder = new Brave.Builder(instanceName); builder.spanCollector(HttpSpanCollector.create(zipkinUrl, new EmptySpanCollectorMetricsHandler())); Brave brave = builder.build(); requestInterceptor = brave.clientRequestInterceptor(); responseInterceptor = brave.clientResponseInterceptor(); }
Example #9
Source File: ContextInducedBlock.java From Poseidon with Apache License 2.0 | 5 votes |
protected void shutdownAllContext() { endTrace(block, success); RequestContext.shutDown(); ServiceContext.shutDown(); HystrixRequestContext.setContextOnCurrentThread(existingState); MDC.clear(); Brave.getServerSpanThreadBinder().setCurrentSpan(null); }
Example #10
Source File: ZipkinFraction.java From thorntail with Apache License 2.0 | 5 votes |
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 #11
Source File: ContextInducedBlock.java From Poseidon with Apache License 2.0 | 5 votes |
protected void initAllContext(Request request) { existingState = HystrixRequestContext.getContextForCurrentThread(); RequestContext.initialize(parentContext); ServiceContext.initialize(serviceContextState); HystrixRequestContext.setContextOnCurrentThread(parentThreadState); if (mdcContext != null) { MDC.setContextMap(mdcContext); } // Parent thread span info is passed onto filter thread using Brave's ThreadLocal implementation if (serverSpan != null && serverSpan.getSpan() != null) { Brave.getServerSpanThreadBinder().setCurrentSpan(serverSpan); } startTrace(block, request); }
Example #12
Source File: ContextInducedBlock.java From Poseidon with Apache License 2.0 | 5 votes |
protected ContextInducedBlock(Block block) { this.block = block; parentContext = RequestContext.getContextMap(); serviceContextState = ServiceContext.getState(); parentThreadState = HystrixRequestContext.getContextForCurrentThread(); mdcContext = MDC.getCopyOfContextMap(); serverSpan = Brave.getServerSpanThreadBinder().getCurrentServerSpan(); }
Example #13
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@Bean public BraveServletFilter braveServletFilter(Brave brave) { /** * 设置sr、ss拦截器 */ return new BraveServletFilter(brave.serverRequestInterceptor(), brave.serverResponseInterceptor(), new DefaultSpanNameProvider()); }
Example #14
Source File: GreetingServer.java From grpc-by-example-java with Apache License 2.0 | 5 votes |
static public void main(String [] args) throws IOException, InterruptedException { Brave brave = Constant.brave("greeting-service"); Server greetingServer = ServerBuilder.forPort(8080) .addService(ServerInterceptors.intercept(new GreetingServiceImpl(), new BraveGrpcServerInterceptor(brave), MonitoringServerInterceptor.create(Configuration.allMetrics()))) .build(); greetingServer.start(); System.out.println("Server started!"); greetingServer.awaitTermination(); }
Example #15
Source File: Constant.java From grpc-by-example-java with Apache License 2.0 | 5 votes |
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 #16
Source File: TraceHelper.java From Poseidon with Apache License 2.0 | 5 votes |
public static void endTrace(Block block, boolean success) { if (!isTracingEnabledRequest() || !trace(block)) { return; } ClientTracer clientTracer = Brave.getClientTracer(SPAN_COLLECTOR, TRACING_ON_FILTERS); if (!success) { clientTracer.submitAnnotation(FAILURE_ANNOTATION); } clientTracer.setClientReceived(); }
Example #17
Source File: TraceHelper.java From Poseidon with Apache License 2.0 | 5 votes |
public static void startTrace(Block block, Request request) { if (!isTracingEnabledRequest() || !trace(block)) { return; } String name = getName(block); ClientTracer clientTracer = Brave.getClientTracer(SPAN_COLLECTOR, TRACING_ON_FILTERS); clientTracer.startNewSpan(name); clientTracer.setCurrentClientServiceName(name); if (request != null) { clientTracer.submitBinaryAnnotation(REQUEST_ANNOTATION, request.toString()); } clientTracer.setClientSent(); }
Example #18
Source File: UserDAO.java From hawkular-apm with Apache License 2.0 | 5 votes |
@Inject public UserDAO(Brave brave) { this.brave = brave; Cluster cluster = Cluster.builder().addContactPoint("cassandra").build(); this.session = cluster.connect(); init(); }
Example #19
Source File: BraveProducer.java From hawkular-apm with Apache License 2.0 | 5 votes |
@Produces @Singleton public Brave getBrave() { String port = System.getenv("TRACING_PORT"); if (port == null) { throw new IllegalStateException("Environmental variable TRACING_PORT is not set!"); } return new Brave.Builder("wildfly-swarm") .reporter(AsyncReporter.builder(OkHttpSender.builder() .endpoint("http://tracing-server:" + port + "/api/v1/spans") .build()) .build()) .build(); }
Example #20
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@Bean public OkHttpClient okHttpClient(Brave brave) { /** * 设置cs、cr拦截器 */ return new OkHttpClient.Builder() .addInterceptor(new BraveOkHttpRequestResponseInterceptor(brave.clientRequestInterceptor(), brave.clientResponseInterceptor(), new DefaultSpanNameProvider())) .build(); }
Example #21
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@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 #22
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@Bean public BraveServletFilter braveServletFilter(Brave brave) { /** * 设置sr、ss拦截器 */ return new BraveServletFilter(brave.serverRequestInterceptor(), brave.serverResponseInterceptor(), new DefaultSpanNameProvider()); }
Example #23
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@Bean public OkHttpClient okHttpClient(Brave brave) { /** * 设置cs、cr拦截器 */ return new OkHttpClient.Builder() .addInterceptor(new BraveOkHttpRequestResponseInterceptor(brave.clientRequestInterceptor(), brave.clientResponseInterceptor(), new DefaultSpanNameProvider())) .build(); }
Example #24
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@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 #25
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@Bean public BraveServletFilter braveServletFilter(Brave brave) { /** * 设置sr、ss拦截器 */ return new BraveServletFilter(brave.serverRequestInterceptor(), brave.serverResponseInterceptor(), new DefaultSpanNameProvider()); }
Example #26
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@Bean public OkHttpClient okHttpClient(Brave brave) { /** * 设置cs、cr拦截器 */ return new OkHttpClient.Builder() .addInterceptor(new BraveOkHttpRequestResponseInterceptor(brave.clientRequestInterceptor(), brave.clientResponseInterceptor(), new DefaultSpanNameProvider())) .build(); }
Example #27
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@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 #28
Source File: ZipkinConfig.java From spring-cloud-k8s-sample with Apache License 2.0 | 5 votes |
@Bean public BraveServletFilter braveServletFilter(Brave brave) { /** * 设置sr、ss拦截器 */ return new BraveServletFilter(brave.serverRequestInterceptor(), brave.serverResponseInterceptor(), new DefaultSpanNameProvider()); }
Example #29
Source File: TracingConfig.java From x7 with Apache License 2.0 | 5 votes |
@ConditionalOnMissingBean(Brave.class) @ConditionalOnProperty( value = {"tracing.zipkin.url"}) @Bean public SpanCollector spanCollector() { HttpSpanCollector.Config config = HttpSpanCollector.Config.builder().compressionEnabled(properties.isCompressionEnabled()).connectTimeout(properties.getConnectTimeout()) .flushInterval(properties.getFlushInterval()).readTimeout(properties.getReadTimeout()).build(); return HttpSpanCollector.create(properties.getUrl(), config, new EmptySpanCollectorMetricsHandler()); }
Example #30
Source File: TracingConfig.java From x7 with Apache License 2.0 | 5 votes |
@ConditionalOnMissingBean(BraveHttpRequestInterceptor.class) @ConditionalOnBean(Brave.class) @Bean public BraveHttpRequestInterceptor requestInterceptor(Brave brave) { return new BraveHttpRequestInterceptor(brave.clientRequestInterceptor(), new DefaultSpanNameProvider()); }