io.jaegertracing.internal.samplers.ConstSampler Java Examples
The following examples show how to use
io.jaegertracing.internal.samplers.ConstSampler.
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: OpenTracingTracingTest.java From cxf with Apache License 2.0 | 6 votes |
@Override protected void run() { final Tracer tracer = new JaegerTracer.Builder("tracer-jaxrs") .withSampler(new ConstSampler(true)) .withReporter(REPORTER) .build(); final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookStore.class); sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore<Scope>())); sf.setAddress("http://localhost:" + PORT); sf.setProvider(new JacksonJsonProvider()); sf.setProvider(new OpenTracingFeature(tracer)); sf.setProvider(new NullPointerExceptionMapper()); server = sf.create(); }
Example #2
Source File: OpenTracingUtil.java From problematic-microservices with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void configureOpenTracing(Properties configuration, String serviceName) { Tracer tracer = null; String tracerName = configuration.getProperty("tracer"); if ("jaeger".equals(tracerName)) { SamplerConfiguration samplerConfig = new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1); SenderConfiguration senderConfig = new SenderConfiguration() .withAgentHost(configuration.getProperty("jaeger.reporter.host")) .withAgentPort(Integer.decode(configuration.getProperty("jaeger.reporter.port"))); ReporterConfiguration reporterConfig = new ReporterConfiguration().withLogSpans(true) .withFlushInterval(1000).withMaxQueueSize(10000).withSender(senderConfig); tracer = new Configuration(serviceName).withSampler(samplerConfig).withReporter(reporterConfig).getTracer(); } else if ("zipkin".equals(tracerName)) { OkHttpSender sender = OkHttpSender.create("http://" + configuration.getProperty("zipkin.reporter.host") + ":" + configuration.getProperty("zipkin.reporter.port") + "/api/v2/spans"); Reporter<Span> reporter = AsyncReporter.builder(sender).build(); tracer = BraveTracer .create(Tracing.newBuilder().localServiceName(serviceName).spanReporter(reporter).build()); } GlobalTracer.register(new DelegatingJfrTracer(tracer)); }
Example #3
Source File: TracingConfig.java From Mastering-Distributed-Tracing with MIT License | 6 votes |
@Bean public io.opentracing.Tracer tracer(CollectorRegistry collector) { Configuration configuration = Configuration.fromEnv(app.name); Tracer jaegerTracer = configuration.getTracerBuilder() // .withSampler(new ConstSampler(true)) // .withScopeManager(new MDCScopeManager()) // .build(); PrometheusMetricsReporter reporter = PrometheusMetricsReporter // .newMetricsReporter() // .withCollectorRegistry(collector) // .withConstLabel("service", app.name) // .withBaggageLabel("callpath", "") // .build(); return io.opentracing.contrib.metrics.Metrics.decorate(jaegerTracer, reporter); }
Example #4
Source File: Client.java From cxf with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { final Tracer tracer = new Configuration("tracer-client") .withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1)) .withReporter(new ReporterConfiguration().withSender( new SenderConfiguration() { @Override public Sender getSender() { return new Slf4jLogSender(); } } )) .getTracer(); final OpenTracingClientProvider provider = new OpenTracingClientProvider(tracer); final Response response = WebClient .create("http://localhost:9000/catalog", Arrays.asList(provider)) .accept(MediaType.APPLICATION_JSON) .get(); System.out.println(response.readEntity(String.class)); response.close(); }
Example #5
Source File: Server.java From cxf with Apache License 2.0 | 6 votes |
@Bean Tracer tracer() { return new Configuration("camel-server") .withSampler( new SamplerConfiguration() .withType(ConstSampler.TYPE) .withParam(1)) .withReporter(new ReporterConfiguration().withSender( new SenderConfiguration() .withEndpoint("http://localhost:14268/api/traces") )) .withCodec( new CodecConfiguration() .withCodec(Builtin.TEXT_MAP, new TextMapCodec(true)) ) .getTracer(); }
Example #6
Source File: TracingPropagationTest.java From tchannel-java with MIT License | 6 votes |
@BeforeClass public static void setUp() throws Exception { reporter = new InMemoryReporter(); Sampler sampler = new ConstSampler(true); tracer = new JaegerTracer.Builder("tchannel-name") .withReporter(reporter) .withSampler(sampler) .build(); tracingContext = new CustomTracingContext(); tchannel = new TChannel.Builder("tchannel-name") .setServerHost(InetAddress.getByName(null)) .setTracer(tracer) .setTracingContext(tracingContext) .build(); subChannel = tchannel.makeSubChannel("tchannel-name") .register("endpoint", new JSONHandler()) .register("Behavior::trace", new ThriftHandler()) .register("Behavior::asynctrace", new ThriftAsyncHandler()); tchannel.listen(); }
Example #7
Source File: Client.java From cxf with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { final Tracer tracer = new Configuration("cxf-client") .withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1)) .withReporter(new ReporterConfiguration().withSender( new SenderConfiguration() .withEndpoint("http://localhost:14268/api/traces") )) .getTracer(); final OpenTracingClientProvider provider = new OpenTracingClientProvider(tracer); final javax.ws.rs.client.Client client = ClientBuilder.newClient().register(provider); final Response response = client .target("http://localhost:8084/catalog") .request() .accept(MediaType.APPLICATION_JSON) .get(); LOG.info("Response: {}", response.readEntity(String.class)); response.close(); // Allow Tracer to flush Thread.sleep(1000); }
Example #8
Source File: InboundRequestTraceTest.java From tchannel-java with MIT License | 5 votes |
@Before public void setUp() { tracer = new JaegerTracer.Builder("tchannel-name") .withReporter(new InMemoryReporter()) .withSampler(new ConstSampler(true)) .build(); request = new JsonRequest .Builder<String>("tchannel-name", "endpoint") .setTimeout(1000, TimeUnit.MILLISECONDS) .setRetryLimit(0) .setBody("foo") .build(); }
Example #9
Source File: OpenTracingTracingTest.java From cxf with Apache License 2.0 | 5 votes |
@Override protected void run() { final Tracer tracer = new JaegerTracer.Builder("tracer-jaxws") .withSampler(new ConstSampler(true)) .withReporter(REPORTER) .build(); GlobalTracer.registerIfAbsent(tracer); final JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean(); sf.setServiceClass(BookStore.class); sf.setAddress("http://localhost:" + PORT); sf.getFeatures().add(new OpenTracingFeature(tracer)); server = sf.create(); }
Example #10
Source File: Server.java From cxf with Apache License 2.0 | 5 votes |
protected Server() throws Exception { org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000); // Register and map the dispatcher servlet final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); servletHolder.setInitParameter("javax.ws.rs.Application", CatalogApplication.class.getName()); final Tracer tracer = new Configuration("tracer-server") .withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1)) .withReporter(new ReporterConfiguration().withSender( new SenderConfiguration() { @Override public Sender getSender() { return new Slf4jLogSender(); } } )) .getTracer(); GlobalTracer.registerIfAbsent(tracer); server.setHandler(context); server.start(); server.join(); }
Example #11
Source File: Server.java From cxf with Apache License 2.0 | 5 votes |
@Bean @Qualifier("cxf") Tracer cxfTracer() { return new Configuration("cxf-service") .withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1)) .withReporter(new ReporterConfiguration().withSender( new SenderConfiguration() .withEndpoint("http://localhost:14268/api/traces") )) .getTracer(); }
Example #12
Source File: TraceBehaviorTest.java From tchannel-java with MIT License | 5 votes |
@Before public void setUp() throws Exception { reporter = new InMemoryReporter(); Sampler sampler = new ConstSampler(false); Reporter compositeReporter = new CompositeReporter(reporter, new LoggingReporter()); tracer = new JaegerTracer.Builder(SERVER_NAME).withSampler(sampler).withReporter(compositeReporter).build(); server = new Server("127.0.0.1", tracer); server.start(); tchannel = server.tchannel; traceBehavior = server.traceBehavior; }
Example #13
Source File: Server.java From tchannel-java with MIT License | 5 votes |
public static void main(String[] args) throws UnknownHostException, InterruptedException { InMemoryReporter reporter = new InMemoryReporter(); Sampler sampler = new ConstSampler(true); Tracer tracer = new JaegerTracer.Builder(SERVER_NAME).withReporter(reporter).withSampler(sampler).build(); HTTPServer httpServer = new HTTPServer(); Thread httpThread = new Thread(httpServer); httpThread.setDaemon(true); httpThread.start(); Server server = new Server("0.0.0.0", tracer); server.start().sync(); server.shutdown(); }
Example #14
Source File: JaegerAllInOne.java From jaeger-analytics-java with Apache License 2.0 | 5 votes |
public JaegerTracer createTracer(String serviceName) { String endpoint = String.format("http://localhost:%d/api/traces", getCollectorThriftPort()); Sender sender = new HttpSender.Builder(endpoint) .build(); Reporter reporter = new RemoteReporter.Builder() .withSender(sender) .build(); Builder tracerBuilder = new Builder(serviceName) .withSampler(new ConstSampler(true)) .withReporter(reporter); return tracerBuilder.build(); }
Example #15
Source File: Tracing.java From opentracing-tutorial with Apache License 2.0 | 5 votes |
public static JaegerTracer init(String service) { SamplerConfiguration samplerConfig = SamplerConfiguration.fromEnv() .withType(ConstSampler.TYPE) .withParam(1); ReporterConfiguration reporterConfig = ReporterConfiguration.fromEnv() .withLogSpans(true); Configuration config = new Configuration(service) .withSampler(samplerConfig) .withReporter(reporterConfig); return config.getTracer(); }
Example #16
Source File: JaegerAutoConfiguration.java From java-spring-jaeger with Apache License 2.0 | 5 votes |
/** * Decide on what Sampler to use based on the various configuration options in * JaegerConfigurationProperties Fallback to ConstSampler(true) when no Sampler is configured */ @ConditionalOnMissingBean @Bean public Sampler sampler(JaegerConfigurationProperties properties, Metrics metrics) { if (properties.getConstSampler().getDecision() != null) { return new ConstSampler(properties.getConstSampler().getDecision()); } if (properties.getProbabilisticSampler().getSamplingRate() != null) { return new ProbabilisticSampler(properties.getProbabilisticSampler().getSamplingRate()); } if (properties.getRateLimitingSampler().getMaxTracesPerSecond() != null) { return new RateLimitingSampler(properties.getRateLimitingSampler().getMaxTracesPerSecond()); } if (!StringUtils.isEmpty(properties.getRemoteControlledSampler().getHostPort())) { JaegerConfigurationProperties.RemoteControlledSampler samplerProperties = properties.getRemoteControlledSampler(); String hostPort = samplerProperties.getHostPort(); if (samplerProperties.getHost() != null && !samplerProperties.getHost().isEmpty()) { hostPort = samplerProperties.getHost() + ":" + samplerProperties.getPort(); } return new RemoteControlledSampler.Builder(properties.getServiceName()) .withSamplingManager(new HttpSamplingManager(hostPort)) .withInitialSampler( new ProbabilisticSampler(samplerProperties.getSamplingRate())) .withMetrics(metrics) .build(); } //fallback to sampling every trace return new ConstSampler(true); }
Example #17
Source File: AsyncTracingContextTestBase.java From tchannel-java with MIT License | 4 votes |
@Test public void test() throws InterruptedException, TChannelError, ExecutionException, TimeoutException { Tracer tracer = new JaegerTracer.Builder(SERVICE) .withReporter(new NoopReporter()) .withSampler(new ConstSampler(false)) .build(); final TracingContext tracingContext = tracingContext(tracer); try ( final TestChannel service = new TestChannel(SERVICE, tracer, tracingContext); ) { final SubChannel clientChannel = service.clientChannel(SERVICE, service.addresses()); service.register(META_HEALTH, new HealthCheckRequestHandler()); service.register(META_TEST, new ThriftAsyncRequestHandler<Meta.health_args, Meta.health_result>() { @Override public ListenableFuture<ThriftResponse<Meta.health_result>> handleImpl( ThriftRequest<Meta.health_args> request ) { final SettableFuture<ThriftResponse<Meta.health_result>> resultFuture = SettableFuture.create(); try { final Span span = tracingContext.currentSpan(); ListenableFuture<ThriftResponse<Meta.health_result>> responseFuture = clientChannel.send( new ThriftRequest .Builder<Meta.health_args>(SERVICE, META_HEALTH) .setBody(new Meta.health_args()) .setTimeout(1000) .setRetryLimit(0) .build() ); Futures.addCallback( responseFuture, new FutureCallback<ThriftResponse<Meta.health_result>>() { @Override public void onSuccess( @Nullable ThriftResponse<Meta.health_result> result ) { try { Assert.assertThat( "Response callback context must have a current span", tracingContext.hasSpan(), is(true) ); Assert.assertThat( "Response callback current span must be the same as the callback creator's", tracingContext.currentSpan(), sameInstance(span) ); resultFuture.set(result); } catch (AssertionError testFailure) { // assertion error (if any) will re-surface when the future result is accessed resultFuture.setException(testFailure); } } @Override public void onFailure(@NotNull Throwable t) { resultFuture.setException(t); } }, service.executor() ); } catch (TChannelError tChannelError) { resultFuture.setException(tChannelError); } return resultFuture; } }); TFuture<ThriftResponse<Meta.health_result>> testResponseFuture = clientChannel.send( new ThriftRequest .Builder<Meta.health_args>(SERVICE, META_TEST) .setBody(new Meta.health_args()) .setTimeout(1000) .setRetryLimit(0) .build() ); try (ThriftResponse<Meta.health_result> testResponse = testResponseFuture.get()) { Assert.assertThat( "Response must have no errors", testResponse.getError(), CoreMatchers.nullValue(ErrorResponse.class) ); } } }
Example #18
Source File: JaegerTracerConfigurator.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void init(@SuppressWarnings({"rawtypes"})NamedList args) { Object host = args.get(AGENT_HOST); if (!(host instanceof String)) { throw new IllegalArgumentException("Expected a required string for param '" + AGENT_HOST + "'"); } Object portArg = args.get(AGENT_PORT); if (!(portArg instanceof Integer)) { throw new IllegalArgumentException("Expected a required int for param '" + AGENT_PORT + "'"); } int port = (Integer) portArg; Boolean logSpans = args.getBooleanArg(LOG_SPANS); if (logSpans == null) logSpans = true; Object flushIntervalArg = args.get(FLUSH_INTERVAL); if (flushIntervalArg != null && !(flushIntervalArg instanceof Integer)) { throw new IllegalArgumentException("Expected a required int for param '" + FLUSH_INTERVAL +"'"); } int flushInterval = flushIntervalArg == null ? 1000 : (Integer) flushIntervalArg; Object maxQueueArgs = args.get(MAX_QUEUE_SIZE); if (maxQueueArgs != null && !(maxQueueArgs instanceof Integer)) { throw new IllegalArgumentException("Expected a required int for param '" + MAX_QUEUE_SIZE +"'"); } int maxQueue = maxQueueArgs == null ? 10000 : (Integer) maxQueueArgs; Configuration.SamplerConfiguration samplerConfig = new Configuration.SamplerConfiguration() .withType(ConstSampler.TYPE) .withParam(1); Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv(); Configuration.SenderConfiguration senderConfig = reporterConfig.getSenderConfiguration() .withAgentHost(host.toString()) .withAgentPort(port); reporterConfig.withLogSpans(logSpans) .withFlushInterval(flushInterval) .withMaxQueueSize(maxQueue) .withSender(senderConfig); tracer = new Configuration("solr") .withSampler(samplerConfig) .withReporter(reporterConfig) .getTracer(); }
Example #19
Source File: ActivityTracingWithSplitTest.java From syndesis with Apache License 2.0 | 4 votes |
@Before public void before() throws Exception { activityEvents = new ArrayList<>(); Tracer tracer = new JaegerTracer.Builder(getClass().getName()).withReporter(new Reporter() { @Override public void report(JaegerSpan span) { activityEvents.add(span); } @Override public void close() { // no resource to dispose } }).withSampler(new ConstSampler(true)).build(); final RouteBuilder routeBuilder = new IntegrationRouteBuilder("", Resources.loadServices(IntegrationStepHandler.class), Arrays.asList(new TracingActivityTrackingPolicyFactory(tracer))) { @Override protected Integration loadIntegration() { return newIntegration( new Step.Builder() .id("source") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("direct") .putConfiguredProperty("name", "start") .build()) .build()) .build(), new Step.Builder() .stepKind(StepKind.split) .build(), new Step.Builder() .id("step-1") .stepKind(StepKind.log) .putConfiguredProperty("contextLoggingEnabled", "true") .putConfiguredProperty("customText", "Log me baby one more time").build(), new Step.Builder() .id("step-2") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("class") .putConfiguredProperty("beanName", TestBean.class.getName()) .build()) .build()) .build(), new Step.Builder() .id("step-3") .stepKind(StepKind.log) .putConfiguredProperty("contextLoggingEnabled", "true") .putConfiguredProperty("customText", "Log me baby one more time").build(), new Step.Builder() .id("step-4") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("mock") .putConfiguredProperty("name", "end") .build()) .build()) .build()); } }; context = new DefaultCamelContext(); context.setUuidGenerator(KeyGenerator::createKey); context.addLogListener(new TracingLogListener(tracer)); context.addInterceptStrategy(new TracingInterceptStrategy(tracer)); context.addRoutes(routeBuilder); context.getShutdownStrategy().setTimeout(1); context.start(); dumpRoutes(context, routeBuilder.getRouteCollection()); }
Example #20
Source File: Tracing.java From TeaStore with Apache License 2.0 | 2 votes |
/** * This function is used to create an Tracer instance to be used as the * GlobalTracer. * * @param service is usually the name of the service * @return Tracer intended to be used as GlobalTracer */ public static Tracer init(String service) { return new JaegerTracer.Builder(service).withSampler(new ConstSampler(true)).withZipkinSharedRpcSpan() .registerInjector(Format.Builtin.HTTP_HEADERS, new B3TextMapCodec.Builder().build()) .registerExtractor(Format.Builtin.HTTP_HEADERS, new B3TextMapCodec.Builder().build()).build(); }