zipkin2.reporter.okhttp3.OkHttpSender Java Examples

The following examples show how to use zipkin2.reporter.okhttp3.OkHttpSender. 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: 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 #2
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 #3
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 #4
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 #5
Source File: TracingConfiguration.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Bean
Sender sender(DynamicProperties dynamicProperties) {
  apiVersion = dynamicProperties.getStringProperty(CONFIG_TRACING_COLLECTOR_API_VERSION,
      CONFIG_TRACING_COLLECTOR_API_V2).toLowerCase();
  // use default value if the user set value is invalid
  if (apiVersion.compareTo(CONFIG_TRACING_COLLECTOR_API_V1) != 0) {
    apiVersion = CONFIG_TRACING_COLLECTOR_API_V2;
  }

  String path = MessageFormat.format(CONFIG_TRACING_COLLECTOR_PATH, apiVersion);
  return OkHttpSender.create(
      dynamicProperties.getStringProperty(
          CONFIG_TRACING_COLLECTOR_ADDRESS,
          DEFAULT_TRACING_COLLECTOR_ADDRESS)
          .trim()
          .replaceAll("/+$", "")
          .concat(path));
}
 
Example #6
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void maxRequests() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"maxRequests\" value=\"4\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("client.dispatcher.maxRequests")
      .isEqualTo(4);
}
 
Example #7
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void readTimeout() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"readTimeout\" value=\"1000\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("client.readTimeout")
      .isEqualTo(1000);
}
 
Example #8
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void writeTimeout() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"writeTimeout\" value=\"1000\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("client.writeTimeout")
      .isEqualTo(1000);
}
 
Example #9
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void connectTimeout() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"connectTimeout\" value=\"1000\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("client.connectTimeout")
      .isEqualTo(1000);
}
 
Example #10
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void endpoint() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("endpoint")
      .isEqualTo(HttpUrl.parse("http://localhost:9411/api/v2/spans"));
}
 
Example #11
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void compressionEnabled() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"compressionEnabled\" value=\"false\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("compressionEnabled")
      .isEqualTo(false);
}
 
Example #12
Source File: OkHttpSenderFactoryBeanTest.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=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"messageMaxBytes\" value=\"1024\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("messageMaxBytes")
      .isEqualTo(1024);
}
 
Example #13
Source File: OkHttpSenderFactoryBean.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Override protected OkHttpSender createInstance() {
  OkHttpSender.Builder builder = OkHttpSender.newBuilder();
  if (endpoint != null) builder.endpoint(endpoint);
  if (encoding != null) builder.encoding(encoding);
  if (connectTimeout != null) builder.connectTimeout(connectTimeout);
  if (readTimeout != null) builder.readTimeout(readTimeout);
  if (writeTimeout != null) builder.writeTimeout(writeTimeout);
  if (maxRequests != null) builder.maxRequests(maxRequests);
  if (compressionEnabled != null) builder.compressionEnabled(compressionEnabled);
  if (messageMaxBytes != null) builder.messageMaxBytes(messageMaxBytes);
  return builder.build();
}
 
Example #14
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void encoding() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "  <property name=\"encoding\" value=\"PROTO3\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", OkHttpSender.class))
      .extracting("encoding")
      .isEqualTo(Encoding.PROTO3);
}
 
Example #15
Source File: OkHttpSenderFactoryBeanTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class) public void close_closesSender() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.OkHttpSenderFactoryBean\">\n"
      + "  <property name=\"endpoint\" value=\"http://localhost:9411/api/v2/spans\"/>\n"
      + "</bean>"
  );

  OkHttpSender sender = context.getBean("sender", OkHttpSender.class);
  context.close();

  sender.sendSpans(Arrays.asList(new byte[] {'{', '}'}));
}
 
Example #16
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 #17
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 #18
Source File: HaystackKafkaForwarderTest.java    From pitchfork with Apache License 2.0 5 votes vote down vote up
/**
 * Create reporter.
 */
private AsyncReporter<zipkin2.Span> setupReporter() {
    var sender = OkHttpSender.newBuilder()
            .encoding(Encoding.PROTO3)
            .endpoint("http://localhost:" + localServerPort + "/api/v2/spans")
            .build();
    return AsyncReporter.create(sender);
}
 
Example #19
Source File: HaystackKinesisForwarderTest.java    From pitchfork with Apache License 2.0 5 votes vote down vote up
/**
 * Create reporter.
 */
private AsyncReporter<zipkin2.Span> setupReporter() {
    var sender = OkHttpSender.newBuilder()
            .encoding(Encoding.PROTO3)
            .endpoint("http://localhost:" + localServerPort + "/api/v2/spans")
            .build();
    return AsyncReporter.create(sender);
}
 
Example #20
Source File: ZipkinForwarderTest.java    From pitchfork with Apache License 2.0 5 votes vote down vote up
/**
 * Create reporter.
 */
private AsyncReporter<zipkin2.Span> setupReporter(Encoding encoding, boolean compressionEnabled) {
    var sender = OkHttpSender.newBuilder()
            .encoding(encoding)
            .compressionEnabled(compressionEnabled)
            .endpoint("http://localhost:" + localServerPort + "/api/v2/spans")
            .build();
    return AsyncReporter.create(sender);
}
 
Example #21
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 #22
Source File: ZipkinTraceFactory.java    From pampas with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    byte[] arr = new byte[10];
    Arrays.fill(arr, Byte.MAX_VALUE);
    try (Sender sender = OkHttpSender.create("http://192.168.20.131:9411/api/v2/spans")) {
        sender.sendSpans(Collections.singletonList(arr));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #23
Source File: TracingBuilderTest.java    From brave-kafka-interceptor with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldBuildHttpSender() {
  // Given
  Map<String, String> map = new HashMap<>();
  map.put(SENDER_TYPE_CONFIG, TracingBuilder.SenderBuilder.SenderType.HTTP.name());
  TracingConfiguration config = new TracingConfiguration(map);
  // When
  Sender sender = new TracingBuilder.SenderBuilder(config).build();
  // Then
  assertTrue(sender instanceof OkHttpSender);
}
 
Example #24
Source File: TracingConfiguration.java    From brave-webmvc-example with MIT License 4 votes vote down vote up
/** Configuration for how to send spans to Zipkin */
@Bean Sender sender() {
  return OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
}
 
Example #25
Source File: TracingConfiguration.java    From txle with Apache License 2.0 4 votes vote down vote up
@Bean
Sender sender() {
    return OkHttpSender.create(zipkinServer);
}
 
Example #26
Source File: TracingConfiguration.java    From brave-webmvc-example with MIT License 4 votes vote down vote up
/** Configuration for how to send spans to Zipkin */
@Bean Sender sender() {
  return OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
}
 
Example #27
Source File: OkHttpSenderFactoryBean.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
@Override protected void destroyInstance(Object instance) {
  ((OkHttpSender) instance).close();
}
 
Example #28
Source File: OkHttpSenderFactoryBean.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
@Override public Class<? extends OkHttpSender> getObjectType() {
  return OkHttpSender.class;
}
 
Example #29
Source File: OkHttpSenderBenchmarks.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
@Override Sender newHttpSender(String endpoint) {
  return OkHttpSender.create(endpoint);
}
 
Example #30
Source File: TracingConfiguration.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
/** Configuration for how to send spans to Zipkin */
@Bean
Sender sender() {
    return OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
}