io.jaegertracing.internal.JaegerTracer Java Examples

The following examples show how to use io.jaegertracing.internal.JaegerTracer. 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 vote down vote up
@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: JaegerAutoConfiguration.java    From java-spring-jaeger with Apache License 2.0 6 votes vote down vote up
@Bean
public io.opentracing.Tracer tracer(Sampler sampler,
                                    Reporter reporter,
                                    Metrics metrics,
                                    JaegerConfigurationProperties properties) {

  final JaegerTracer.Builder builder =
      new JaegerTracer.Builder(properties.getServiceName())
          .withReporter(reporter)
          .withSampler(sampler)
          .withTags(properties.determineTags())
          .withMetrics(metrics);

  tracerCustomizers.forEach(c -> c.customize(builder));

  return builder.build();
}
 
Example #3
Source File: TracingPropagationTest.java    From tchannel-java with MIT License 6 votes vote down vote up
@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 #4
Source File: Formatter.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("dw.server.applicationConnectors[0].port", "8081");
    System.setProperty("dw.server.adminConnectors[0].port", "9081");
    try (JaegerTracer tracer = Tracing.init("formatter")) {
        new Formatter(tracer).run(args);
    }
}
 
Example #5
Source File: OpenTracingTracingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: TraceBehaviorTest.java    From tchannel-java with MIT License 5 votes vote down vote up
@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 #7
Source File: Server.java    From tchannel-java with MIT License 5 votes vote down vote up
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 #8
Source File: InboundRequestTraceTest.java    From tchannel-java with MIT License 5 votes vote down vote up
@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: Tracing.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
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 #10
Source File: Hello.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 1) {
        throw new IllegalArgumentException("Expecting one argument");
    }

    String helloTo = args[0];
    try (JaegerTracer tracer = Tracing.init("hello-world")) {
        new Hello(tracer).sayHello(helloTo);
    }
}
 
Example #11
Source File: Hello.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 1) {
        throw new IllegalArgumentException("Expecting one argument");
    }

    String helloTo = args[0];
    try (JaegerTracer tracer = Tracing.init("hello-world")) {
        new Hello(tracer).sayHello(helloTo);
    }
}
 
Example #12
Source File: Hello.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 1) {
        throw new IllegalArgumentException("Expecting one argument");
    }

    String helloTo = args[0];
    try (JaegerTracer tracer = Tracing.init("hello-world")) {
        new Hello(tracer).sayHello(helloTo);
    }
}
 
Example #13
Source File: Publisher.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("dw.server.applicationConnectors[0].port", "8082");
    System.setProperty("dw.server.adminConnectors[0].port", "9082");
    try (JaegerTracer tracer = Tracing.init("publisher")) {
        new Publisher(tracer).run(args);
    }
}
 
Example #14
Source File: Hello.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 2) {
        throw new IllegalArgumentException("Expecting two arguments, helloTo and greeting");
    }
    String helloTo = args[0];
    String greeting = args[1];
    try (JaegerTracer tracer = Tracing.init("hello-world")) {
        new Hello(tracer).sayHello(helloTo, greeting);
    }
}
 
Example #15
Source File: Publisher.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("dw.server.applicationConnectors[0].port", "8082");
    System.setProperty("dw.server.adminConnectors[0].port", "9082");
    try (JaegerTracer tracer = Tracing.init("publisher")) {
        new Publisher(tracer).run(args);
    }
}
 
Example #16
Source File: TracingUtil.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the tracing with the given service name.
 */
public static void initTracing(
    String serviceName, ConfigurationSource conf) {
  if (!GlobalTracer.isRegistered() && isTracingEnabled(conf)) {
    Configuration config = Configuration.fromEnv(serviceName);
    JaegerTracer tracer = config.getTracerBuilder()
        .registerExtractor(StringCodec.FORMAT, new StringCodec())
        .registerInjector(StringCodec.FORMAT, new StringCodec())
        .build();
    GlobalTracer.register(tracer);
  }
}
 
Example #17
Source File: HelloManual.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 1) {
        throw new IllegalArgumentException("Expecting one argument");
    }

    String helloTo = args[0];
    try (JaegerTracer tracer = Tracing.init("hello-world")) {
        new HelloManual(tracer).sayHello(helloTo);
    }
}
 
Example #18
Source File: HelloActive.java    From opentracing-tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 1) {
        throw new IllegalArgumentException("Expecting one argument");
    }

    String helloTo = args[0];
    try (JaegerTracer tracer = Tracing.init("hello-world")) {
        new HelloActive(tracer).sayHello(helloTo);
    }
}
 
Example #19
Source File: B3CodecTracerBuilderCustomizer.java    From java-spring-jaeger with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(JaegerTracer.Builder builder) {
  B3TextMapCodec injector = new B3TextMapCodec.Builder().build();

  builder.registerInjector(Format.Builtin.HTTP_HEADERS, injector)
      .registerExtractor(Format.Builtin.HTTP_HEADERS, injector);

  builder.registerInjector(Format.Builtin.TEXT_MAP, injector)
      .registerExtractor(Format.Builtin.TEXT_MAP, injector);
}
 
Example #20
Source File: JaegerTraceFactory.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
public JaegerTraceFactory() {
    Map<String, Object> global = GlobalContext.getContext();
    Object obj = global.get(TRACE_JAEGER);
    if (obj instanceof JaegerTracer) {
        //判断是否有全局的变量
        tracer = (JaegerTracer) obj;
    } else {
        Parametric parametric = Variable.VARIABLE;
        Configuration configuration = new Configuration(parametric.getString("appService", KEY_APPNAME, "unknown"));
        configuration.withSampler(buildSamplerConfiguration(parametric));
        configuration.withReporter(buildReporterConfiguration(parametric));
        tracer = configuration.getTracer();
    }
}
 
Example #21
Source File: JaegerAllInOne.java    From jaeger-analytics-java with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: ActivityTracingWithSplitTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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 #23
Source File: ExpandExceptionLogsTracerBuilderCustomizer.java    From java-spring-jaeger with Apache License 2.0 4 votes vote down vote up
@Override
public void customize(JaegerTracer.Builder builder) {
  builder.withExpandExceptionLogs();
}
 
Example #24
Source File: AsyncTracingContextTestBase.java    From tchannel-java with MIT License 4 votes vote down vote up
@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 #25
Source File: HigherBitTracerBuilderCustomizer.java    From java-spring-jaeger with Apache License 2.0 4 votes vote down vote up
@Override
public void customize(JaegerTracer.Builder builder) {
  builder.withTraceId128Bit();
}
 
Example #26
Source File: JaegerTraceFactory.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
public ProviderTracer(final JaegerTracer tracer,
                      final RequestMessage<Invocation> request) {
    super(tracer, request);
}
 
Example #27
Source File: JaegerTraceFactory.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
public ConsumerTracer(final JaegerTracer tracer,
                      final RequestMessage<Invocation> request) {
    super(tracer, request);
}
 
Example #28
Source File: JaegerTraceFactory.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
public AbstractTracer(final JaegerTracer tracer,
                      final RequestMessage<Invocation> request) {
    this.tracer = tracer;
    this.request = request;
    this.invocation = request.getPayLoad();
}
 
Example #29
Source File: Tracing.java    From TeaStore with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}
 
Example #30
Source File: TracerBuilderCustomizer.java    From java-spring-jaeger with Apache License 2.0 2 votes vote down vote up
/**
 * Provides the ability to execute arbitrary operations on the builder The customizer should NOT
 * call the build method
 */
void customize(JaegerTracer.Builder builder);