brave.opentracing.BraveTracer Java Examples

The following examples show how to use brave.opentracing.BraveTracer. 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: 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 #2
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 #3
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 #4
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 #5
Source File: XioTracing.java    From xio with Apache License 2.0 6 votes vote down vote up
public XioTracing(TracingConfig config) {
  name = config.getApplicationName();
  TracingConfig.TracingType type = config.getType();

  switch (type) {
    case ZIPKIN:
      String zipkinUrl = config.getZipkinUrl();
      float samplingRate = config.getZipkinSamplingRate();
      Tracing tracing = buildZipkinTracing(this.name, zipkinUrl, samplingRate);
      if (tracing != null) {
        tracer = BraveTracer.create(tracing);
      }
      break;
    case DATADOG:
      if (GlobalTracer.isRegistered()) {
        tracer = GlobalTracer.get();
      } else {
        tracer = new DDTracer();
        GlobalTracer.register(tracer);
      }
      break;
  }
  log.info("Configured tracer type: {}", type.toString());
}
 
Example #6
Source File: ImplementationsJFRTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
public void brave() throws IOException {

	Factory propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
			.addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id")).build();

	Tracing braveTracing = Tracing.newBuilder().localServiceName("my-service")
			.propagationFactory(propagationFactory).build();
	innerTest(BraveTracer.create(braveTracing));
}
 
Example #7
Source File: ImplementationsJFRTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
public void brave() throws IOException {

	Factory propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
			.addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id")).build();

	Tracing braveTracing = Tracing.newBuilder().localServiceName("my-service")
			.propagationFactory(propagationFactory).build();
	innerTest(BraveTracer.create(braveTracing));
}
 
Example #8
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 #9
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 #10
Source File: OpentracingAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "brave.opentracing.BraveTracer")
Tracer sleuthOpenTracing(brave.Tracing braveTracing) {
	return BraveTracer.create(braveTracing);
}
 
Example #11
Source File: HttpServerTracingHandlerTest.java    From xio with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
  httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).build());
  BraveTracer braveTracer = BraveTracer.create(httpTracing.tracing());
  httpTracingState = new HttpServerTracingDispatch("test", braveTracer);
}