zipkin2.reporter.AsyncReporter Java Examples

The following examples show how to use zipkin2.reporter.AsyncReporter. 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: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void metrics() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"metrics\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".METRICS\"/>\n"
      + "  </property>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("metrics")
      .isEqualTo(METRICS);
}
 
Example #2
Source File: WingtipsToZipkinLifecycleListenerTest.java    From wingtips with Apache License 2.0 6 votes vote down vote up
@DataProvider(value = {
    "true",
    "false"
})
@Test
public void convenience_constructor_sets_fields_as_expected(boolean baseUrlTrailingSlash) throws MalformedURLException {
    // given
    String baseUrlWithoutTrailingSlash = "http://localhost:4242";
    String baseUrl = (baseUrlTrailingSlash)
                     ? baseUrlWithoutTrailingSlash + "/"
                     : baseUrlWithoutTrailingSlash;

    // when
    WingtipsToZipkinLifecycleListener listener = new WingtipsToZipkinLifecycleListener(serviceName, baseUrl);

    // then
    assertThat(listener.serviceName).isEqualTo(serviceName);
    assertThat(listener.zipkinEndpoint.serviceName()).isEqualTo(serviceName);
    assertThat(listener.zipkinSpanConverter).isInstanceOf(WingtipsToZipkinSpanConverterDefaultImpl.class);
    assertThat(listener.zipkinSpanReporter).isInstanceOf(AsyncReporter.class);
    Object spanSender = Whitebox.getInternalState(listener.zipkinSpanReporter, "sender");
    assertThat(spanSender).isInstanceOf(URLConnectionSender.class);
    assertThat(Whitebox.getInternalState(spanSender, "endpoint"))
        .isEqualTo(new URL(baseUrlWithoutTrailingSlash + "/api/v2/spans"));
}
 
Example #3
Source File: TarsTraceZipkinConfiguration.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void init() {
	isTrace = serverConfig.getSampleRate() > 0;
	if (isTrace) {
		try {
			createSender();
			reporter = AsyncReporter.builder(sender).build();
			Map<String, Tracer> traces = new HashMap<String, Tracer>();
			for (String servant : serverConfig.getServantAdapterConfMap().keySet()) {
				if (!servant.equals(OmConstants.AdminServant)) {
					Tracing tracing = Tracing.newBuilder().localServiceName(servant)
							.spanReporter(reporter).sampler(brave.sampler.Sampler.create(serverConfig.getSampleRate())).build();
					Tracer tracer = BraveTracer.create(tracing);
					traces.put(servant, tracer);
				}
			}
			TraceManager.getInstance().putTracers(traces);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
Example #4
Source File: TranslationService.java    From talk-kafka-zipkin with MIT License 6 votes vote down vote up
@Override
public void run(TranslationServiceConfiguration configuration,
		Environment environment) {

	/* START TRACING INSTRUMENTATION */
	final var sender = URLConnectionSender.newBuilder()
			.endpoint(configuration.getZipkinEndpoint()).build();
	final var reporter = AsyncReporter.builder(sender).build();
	final var tracing = Tracing.newBuilder().localServiceName("translation-service")
			.sampler(Sampler.ALWAYS_SAMPLE).spanReporter(reporter).build();
	final var httpTracing = HttpTracing.newBuilder(tracing).build();
	final var jerseyTracingFilter = TracingApplicationEventListener
			.create(httpTracing);
	environment.jersey().register(jerseyTracingFilter);
	/* END TRACING INSTRUMENTATION */

	final var repository = new TranslationRepository();
	final var translationResource = new TranslationResource(repository);
	environment.jersey().register(translationResource);

	final var healthCheck = new TranslationServiceHealthCheck();
	environment.healthChecks().register("translation-service", healthCheck);
}
 
Example #5
Source File: StackdriverTraceAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Bean(REPORTER_BEAN_NAME)
@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)
public Reporter<Span> stackdriverReporter(ReporterMetrics reporterMetrics,
		GcpTraceProperties trace, @Qualifier(SENDER_BEAN_NAME) Sender sender) {

	AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender)
			// historical constraint. Note: AsyncReporter supports memory bounds
			.queuedMaxSpans(1000)
			.messageTimeout(trace.getMessageTimeout(), TimeUnit.SECONDS)
			.metrics(reporterMetrics).build(StackdriverEncoder.V2);

	CheckResult checkResult = asyncReporter.check();
	if (!checkResult.ok()) {
		LOGGER.warn(
				"Error when performing Stackdriver AsyncReporter health check.", checkResult.error());
	}

	return asyncReporter;
}
 
Example #6
Source File: OpenTracingUtil.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #7
Source File: ZipkinTraceFactory.java    From pampas with Apache License 2.0 6 votes vote down vote up
@Override
public Tracer getTracer() {
    Sender sender = OkHttpSender.create("http://192.168.20.131:9411/api/v2/spans");

    Reporter spanReporter = AsyncReporter.create(sender);
    // If you want to support baggage, indicate the fields you'd like to
    // whitelist, in this case "country-code" and "user-id". On the wire,
    // they will be prefixed like "baggage-country-code"
    Propagation.Factory propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
            .addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id"))
            .build();
    Tracing braveTracing = Tracing.newBuilder()
            .localServiceName("gateway")
            .propagationFactory(propagationFactory)
            .spanReporter(spanReporter)
            .build();
    Tracer tracer = BraveTracer.create(braveTracing);

    return tracer;
}
 
Example #8
Source File: OpenTracingFilter.java    From flower with Apache License 2.0 6 votes vote down vote up
public Tracer getTracer() {
  if (tracer != null) {
    return tracer;
  }
  final String endpoint = "http://10.100.216.147:9411/api/v2/spans";
  tracer = BraveTracer.create(Tracing.newBuilder()
      // send to zipkin by okhttp
      .spanReporter(AsyncReporter.create(OkHttpSender.create(endpoint)))
      // log to the console
      .spanReporter(span -> {
        logger.info("flower report span : {}", span.toString());
      })
      //
      .localServiceName("flower-filter").build());
  return tracer;
}
 
Example #9
Source File: CatalogTracing.java    From cxf with Apache License 2.0 6 votes vote down vote up
public HttpTracing getHttpTracing() {
    HttpTracing result = httpTracing;
    
    if (result == null) {
        synchronized (this) {
            result = httpTracing;
            if (result == null) {
                sender = OkHttpSender.create("http://localhost:9411/api/v2/spans");
                reporter = AsyncReporter.create(sender);
                result = createHttpTracing(serviceName, reporter);
                httpTracing = result;
            }
        }
    }
    
    return result;
}
 
Example #10
Source File: XioTracing.java    From xio with Apache License 2.0 5 votes vote down vote up
Reporter<Span> buildReporter(@NonNull String zipkinUrl) {
  OkHttpClient.Builder clientBuilder = OkHttpClientBuilderFactory.createZipkinClientBuilder();
  OkHttpSender sender =
      OkHttpSenderBuilderFactory.createSenderBuilder(clientBuilder)
          .encoding(Encoding.JSON)
          .endpoint(zipkinUrl)
          .compressionEnabled(false)
          .build();
  return AsyncReporter.builder(sender).build();
}
 
Example #11
Source File: AsyncReporterStackdriverSenderTest.java    From zipkin-gcp with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  server.getServiceRegistry().addService(traceService);
  reporter =
      AsyncReporter.builder(
              StackdriverSender.newBuilder(server.getChannel()).projectId(projectId).build())
          .messageTimeout(0, TimeUnit.MILLISECONDS) // don't spawn a thread
          .build(StackdriverEncoder.V2);
}
 
Example #12
Source File: WingtipsToZipkinLifecycleListener.java    From wingtips with Apache License 2.0 5 votes vote down vote up
/**
 * @param postZipkinSpansBaseUrl The Zipkin base URL. This is everything except the endpoint path, i.e.
 * {@code http://foo.bar:9411}.
 * @return A new {@link AsyncReporter} that uses a basic {@link URLConnectionSender} for sending spans via HTTP to
 * the standard Zipkin {@code POST /api/v2/spans} endpoint.
 */
public static Reporter<zipkin2.Span> generateBasicZipkinReporter(String postZipkinSpansBaseUrl) {
    return AsyncReporter.create(
        URLConnectionSender.create(
            postZipkinSpansBaseUrl + (postZipkinSpansBaseUrl.endsWith("/") ? "" : "/") + "api/v2/spans"
        )
    );
}
 
Example #13
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void sender_proto3() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".PROTO3_SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("encoder")
      .isEqualTo(SpanBytesEncoder.PROTO3);
}
 
Example #14
Source File: ZipkinTracerTest.java    From zipkin-finagle with Apache License 2.0 5 votes vote down vote up
ZipkinTracer newTracer(AsyncReporter.Builder spanReporter, String localServiceName) {
  if (tracer != null) tracer.close();
  return ZipkinTracer.newBuilder(spanReporter.build())
      .initialSampleRate(1.0f)
      .localServiceName(localServiceName)
      .stats(stats)
      .build();
}
 
Example #15
Source File: ZipkinTracer.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public Tracer getTracer(String serviceName) {
    String hostname = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST) != null ?
            configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST)
            : TracingConstants.ZIPKIN_DEFAULT_HOST;

    int port = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT) != null ?
            Integer.parseInt(configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT))
            : TracingConstants.ZIPKIN_DEFAULT_PORT;

    boolean tracerLogEnabled =
            Boolean.parseBoolean(configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) != null ?
            configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED)
            : TracingConstants.DEFAULT_TRACER_LOG_ENABLED);

    OkHttpSender sender = OkHttpSender.create("http://" + hostname + ":" + port + TracingConstants.ZIPKIN_API_CONTEXT);
    Tracer tracer = BraveTracer.create(Tracing.newBuilder()
            .localServiceName(serviceName)
            .spanReporter(AsyncReporter.builder(sender).build())
            .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, TracingConstants.REQUEST_ID))
            .build());

    if (tracerLogEnabled) {
        Reporter reporter = new TracingReporter(LogFactory.getLog(TracingConstants.TRACER));
        Tracer tracerR = new TracerR(tracer, reporter, new ThreadLocalScopeManager());
        GlobalTracer.register(tracerR);
        return tracerR;
    } else {
        GlobalTracer.register(tracer);
        return tracer;
    }
}
 
Example #16
Source File: TracingUtil.java    From oxd with Apache License 2.0 5 votes vote down vote up
private static Tracer createTracer(OxdServerConfiguration configuration, String componentName) {
    String tracerName = configuration.getTracer();

    if (!configuration.getEnableTracing() || Strings.isNullOrEmpty(tracerName)) {
        return NoopTracerFactory.create();
    } else if ("jaeger".equals(tracerName)) {
        Configuration.SamplerConfiguration samplerConfig = new Configuration.SamplerConfiguration()
                .withType(ConstSampler.TYPE)
                .withParam(1);

        Configuration.SenderConfiguration senderConfig = new Configuration.SenderConfiguration()
                .withAgentHost(configuration.getTracerHost())
                .withAgentPort(configuration.getTracerPort());

        Configuration.ReporterConfiguration reporterConfig = new Configuration.ReporterConfiguration()
                .withLogSpans(true)
                .withFlushInterval(1000)
                .withMaxQueueSize(10000)
                .withSender(senderConfig);

        return new Configuration(componentName)
                .withSampler(samplerConfig)
                .withReporter(reporterConfig)
                .getTracer();
    } else if ("zipkin".equals(tracerName)) {
        OkHttpSender sender = OkHttpSender.create(
                "http://" + configuration.getTracerHost() + ":" + configuration.getTracerPort() + "/api/v1/spans");

        Reporter<Span> reporter = AsyncReporter.builder(sender).build();

        return BraveTracer.create(Tracing.newBuilder()
                .localServiceName(componentName)
                .spanReporter(reporter)
                .build());
    } else {
        return NoopTracerFactory.create();
    }
}
 
Example #17
Source File: RabbitMqIngressTest.java    From pitchfork with Apache License 2.0 5 votes vote down vote up
/**
 * Create reporter.
 */
private AsyncReporter<Span> setupReporter(Encoding encoding) {
    var sender = RabbitMQSender.newBuilder()
            .username("guest")
            .username("guest")
            .virtualHost("/")
            .encoding(encoding)
            .queue("zipkin")
            .addresses(rabbitMqContainer.getContainerIpAddress() + ":" + rabbitMqContainer.getFirstMappedPort())
            .build();
    return AsyncReporter.create(sender);
}
 
Example #18
Source File: CatalogTracingFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static Tracing create(final String serviceName, final AsyncReporter<zipkin2.Span> reporter) {
    return Tracing
        .newBuilder()
        .localServiceName(serviceName)
        .currentTraceContext(
            ThreadLocalCurrentTraceContext
                .newBuilder()
                .build()
          )
        .spanReporter(reporter)
        .build();
}
 
Example #19
Source File: ITStackdriverSender.java    From zipkin-gcp with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws IOException {
  // Application Default credential is configured using the GOOGLE_APPLICATION_CREDENTIALS env var
  // See: https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application

  String credentialsPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
  assumeThat(credentialsPath).isNotBlank();
  assumeThat(new File(credentialsPath)).exists();
  assumeThatCode(GoogleCredentials::getApplicationDefault).doesNotThrowAnyException();

  credentials = GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singletonList("https://www.googleapis.com/auth/trace.append"));

  // Setup the sender to authenticate the Google Stackdriver service
  sender = StackdriverSender.newBuilder()
          .projectId(projectId)
          .callOptions(CallOptions.DEFAULT.withCallCredentials(MoreCallCredentials.from(credentials)))
          .build();

  reporter =
      AsyncReporter.builder(sender)
          .messageTimeout(0, TimeUnit.MILLISECONDS) // don't spawn a thread
          .build(StackdriverEncoder.V2);

  traceServiceGrpcV1 = TraceServiceGrpc.newBlockingStub(sender.channel)
          .withCallCredentials(MoreCallCredentials.from(credentials.createScoped("https://www.googleapis.com/auth/cloud-platform")));

  senderNoPermission = StackdriverSender.newBuilder()
          .projectId(projectId)
          .build();

  reporterNoPermission =
          AsyncReporter.builder(senderNoPermission)
                  .messageTimeout(0, TimeUnit.MILLISECONDS)
                  .build(StackdriverEncoder.V2);
}
 
Example #20
Source File: ZipkinTest.java    From hippo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {
        URLConnectionSender sender = URLConnectionSender.create("http://103.10.0.67:9411/api/v2/spans");
        AsyncReporter reporter = AsyncReporter.builder(sender)
                .closeTimeout(100, TimeUnit.MILLISECONDS)
                .build(SpanBytesEncoder.JSON_V2);
        Tracing tracing = Tracing.newBuilder()
                .localServiceName("test1")
                .spanReporter(reporter)
                .propagationFactory(B3Propagation.FACTORY)
                .currentTraceContext(ThreadLocalCurrentTraceContext.create())
                .build();
        Tracer tracer = tracing.tracer();
        tracer.startScopedSpan("t1");
        Span span = tracer.newTrace().annotate("111").start();
        span.kind(Span.Kind.CLIENT);
       // span1.finish();
        // System.out.println(  span.context().traceId());
        //System.out.println(  span.context().spanId());
        //tracer.nextSpan().start();

       // Span span2=tracer.newChild(TraceContext.newBuilder().parentId(span.context().spanId()).traceId(span.context().traceId()).spanId(span.context().spanId()).build()).name("eeeee").annotate("222").start();
        // Span span2 = tracer.newChild(TraceContext.newBuilder().parentId(span.context().spanId()).traceId(span.context().traceId()).spanId(span.context().spanId()).build()).name("eeeee").start();
       // span2.kind(Span.Kind.SERVER);
//         System.out.println(  span.context().traceId());
//        System.out.println(  span.context().spanId());
        //System.out.println(span.annotate("").kind(Span.Kind.CLIENT));
        //Span action_1 = tracer.newChild(span.context()).name("action-1").start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            //span1.finish();
            span.finish();
            //    action_1.finish();
        }
        Thread.sleep(100000000L);
    }
 
Example #21
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void encoder() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".PROTO3_SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"encoder\" value=\"PROTO3\"/>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("encoder")
      .isEqualTo(SpanBytesEncoder.PROTO3);
}
 
Example #22
Source File: StackdriverSenderFactory.java    From micronaut-gcp with Apache License 2.0 5 votes vote down vote up
/**
 * A custom {@link AsyncReporter} that uses {@link StackdriverEncoder#V2}.
 *
 * @param configuration The configuration
 * @return The bean.
 */
@Singleton
@Requires(classes = StackdriverSender.class)
@Requires(beans = AsyncReporterConfiguration.class)
public AsyncReporter<Span> stackdriverReporter(@Nonnull AsyncReporterConfiguration configuration) {
    return configuration.getBuilder()
            .build(StackdriverEncoder.V2);
}
 
Example #23
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void queuedMaxBytes() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"queuedMaxBytes\" value=\"512\"/>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("pending.maxBytes")
      .isEqualTo(512);
}
 
Example #24
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void queuedMaxSpans() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"queuedMaxSpans\" value=\"10\"/>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("pending.maxSize")
      .isEqualTo(10);
}
 
Example #25
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void closeTimeout() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"closeTimeout\" value=\"500\"/>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("closeTimeoutNanos")
      .isEqualTo(TimeUnit.MILLISECONDS.toNanos(500));
}
 
Example #26
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void messageTimeout() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"messageTimeout\" value=\"500\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("messageTimeoutNanos")
      .isEqualTo(TimeUnit.MILLISECONDS.toNanos(500));
}
 
Example #27
Source File: InternalReporterTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
/**
 * Shows usage for {@code AsyncZipkinSpanHandler} which internally builds an async reporter with a
 * custom bytes encoder. This allows {@code AsyncZipkinSpanHandler.toBuilder()} to be safely
 * created as the there is no ambiguity on whether {@link AsyncReporter.Builder#build()} or {@link
 * AsyncReporter.Builder#build(BytesEncoder)} was called.
 */
@Test public void toBuilder() {
  AsyncReporter<String> input = AsyncReporter.builder(sender).build(bytesEncoder);
  assertThat(InternalReporter.instance.toBuilder(input).build(bytesEncoder))
      .usingRecursiveComparison()
      .isEqualTo(input);
}
 
Example #28
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void messageMaxBytes() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"messageMaxBytes\" value=\"512\"/>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("messageMaxBytes")
      .isEqualTo(512);
}
 
Example #29
Source File: AsyncReporterFactoryBean.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Override protected AsyncReporter createInstance() {
  AsyncReporter.Builder builder = AsyncReporter.builder(sender);
  if (metrics != null) builder.metrics(metrics);
  if (messageMaxBytes != null) builder.messageMaxBytes(messageMaxBytes);
  if (messageTimeout != null) builder.messageTimeout(messageTimeout, TimeUnit.MILLISECONDS);
  if (closeTimeout != null) builder.closeTimeout(closeTimeout, TimeUnit.MILLISECONDS);
  if (queuedMaxSpans != null) builder.queuedMaxSpans(queuedMaxSpans);
  if (queuedMaxBytes != null) builder.queuedMaxBytes(queuedMaxBytes);
  return encoder != null ? builder.build(encoder) : builder.build();
}
 
Example #30
Source File: AsyncReporterFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void sender() {
  context = new XmlBeans(""
      + "<bean id=\"asyncReporter\" class=\"zipkin2.reporter.beans.AsyncReporterFactoryBean\">\n"
      + "  <property name=\"sender\">\n"
      + "    <util:constant static-field=\"" + getClass().getName() + ".SENDER\"/>\n"
      + "  </property>\n"
      + "  <property name=\"messageTimeout\" value=\"0\"/>\n" // disable thread for test
      + "</bean>"
  );

  assertThat(context.getBean("asyncReporter", AsyncReporter.class))
      .extracting("sender")
      .isEqualTo(SENDER);
}