Java源码示例:io.jaegertracing.Configuration.SenderConfiguration
示例1
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));
}
示例2
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);
}
示例3
@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();
}
示例4
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();
}
示例5
private void initTracer() {
Configuration config =
new Configuration(_settings.getServiceName())
.withSampler(new SamplerConfiguration().withType("const").withParam(1))
.withReporter(
new ReporterConfiguration()
.withSender(
SenderConfiguration.fromEnv()
.withAgentHost(_settings.getTracingAgentHost())
.withAgentPort(_settings.getTracingAgentPort()))
.withLogSpans(false));
GlobalTracer.registerIfAbsent(config.getTracer());
}
示例6
private void initTracer() {
Configuration config =
new Configuration(_settings.getServiceName())
.withSampler(new SamplerConfiguration().withType("const").withParam(1))
.withReporter(
new ReporterConfiguration()
.withSender(
SenderConfiguration.fromEnv()
.withAgentHost(_settings.getTracingAgentHost())
.withAgentPort(_settings.getTracingAgentPort()))
.withLogSpans(false));
GlobalTracer.registerIfAbsent(config.getTracer());
}
示例7
private static void initTracer() {
Configuration config =
new Configuration(_settings.getServiceName())
.withSampler(new SamplerConfiguration().withType("const").withParam(1))
.withReporter(
new ReporterConfiguration()
.withSender(
SenderConfiguration.fromEnv()
.withAgentHost(_settings.getTracingAgentHost())
.withAgentPort(_settings.getTracingAgentPort()))
.withLogSpans(false));
GlobalTracer.registerIfAbsent(config.getTracer());
}
示例8
private static void initTracer() {
io.jaegertracing.Configuration config =
new io.jaegertracing.Configuration(_mainSettings.getServiceName())
.withSampler(new SamplerConfiguration().withType("const").withParam(1))
.withReporter(
new ReporterConfiguration()
.withSender(
SenderConfiguration.fromEnv()
.withAgentHost(_mainSettings.getTracingAgentHost())
.withAgentPort(_mainSettings.getTracingAgentPort()))
.withLogSpans(false));
GlobalTracer.registerIfAbsent(config.getTracer());
}
示例9
@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();
}
示例10
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();
}