io.jaegertracing.internal.propagation.B3TextMapCodec Java Examples

The following examples show how to use io.jaegertracing.internal.propagation.B3TextMapCodec. 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: 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 #2
Source File: JaegerInitializer.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext sc = servletContextEvent.getServletContext();

    String serviceName = getProperty(sc, JAEGER_SERVICE_NAME);
    if (serviceName == null || serviceName.isEmpty()) {
        logger.warn("No Service Name set. Using default. Please change it.");
        serviceName = "thorntail/unknown";
    }

    Configuration configuration = new Configuration(serviceName)
            .withSampler(
                    new Configuration.SamplerConfiguration()
                            .withType(
                                    getProperty(sc, JAEGER_SAMPLER_TYPE))
                            .withParam(
                                    getPropertyAsNumber(sc, JAEGER_SAMPLER_PARAM))
                            .withManagerHostPort(
                                    getProperty(sc, JAEGER_SAMPLER_MANAGER_HOST_PORT)))
            .withReporter(
                    new ReporterConfiguration()
                            .withLogSpans(
                                    getPropertyAsBoolean(sc, JAEGER_REPORTER_LOG_SPANS))
                            .withSender(
                                    new SenderConfiguration()
                                            .withAuthUsername(getProperty(sc, JAEGER_USER))
                                            .withAuthPassword(getProperty(sc, JAEGER_PASSWORD))
                                            .withAgentHost(getProperty(sc, JAEGER_AGENT_HOST))
                                            .withAgentPort(getPropertyAsInt(sc, JAEGER_AGENT_PORT)))
                            .withFlushInterval(
                                    getPropertyAsInt(sc, JAEGER_REPORTER_FLUSH_INTERVAL))
                            .withMaxQueueSize(
                                    getPropertyAsInt(sc, JAEGER_REPORTER_MAX_QUEUE_SIZE)
                            )
            );

    String remoteEndpoint = getProperty(sc, JAEGER_ENDPOINT);
    if (remoteEndpoint != null && remoteEndpoint.trim().length() > 0) {
        configuration.getReporter()
                .withSender(new SenderConfiguration()
                                    .withEndpoint(remoteEndpoint));
    }

    String enableB3HeaderPropagation = getProperty(sc, "enableB3HeaderPropagation");
    if (enableB3HeaderPropagation != null && Boolean.parseBoolean(enableB3HeaderPropagation)) {
        logger.info("Enabling B3 Header Propagation for Jaeger");
        CodecConfiguration codecConfiguration = new CodecConfiguration();
        codecConfiguration.withCodec(Builtin.HTTP_HEADERS, new B3TextMapCodec.Builder().build());
        codecConfiguration.withCodec(Builtin.TEXT_MAP, new B3TextMapCodec.Builder().build());
        configuration.withCodec(codecConfiguration);
    }

    GlobalTracer.register(configuration.getTracer());
}
 
Example #3
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();
}