BaseTracingInterceptor implements Configurable { @Override public void configure(Map<String, ?> map) { groupId = extractString(map, ConsumerConfig.GROUP_ID_CONFIG); clientId = extractString(map, ProducerConfig.CLIENT_ID_CONFIG); boolean traceId128bitEnabled = Optional.ofNullable(extractString(map, TracingInterceptorConfig.ZIPKIN_TRACE_ID_128BIT_ENABLED_CONFIG)) .map(Boolean::valueOf).orElse(TracingInterceptorConfig.ZIPKIN_TRACE_ID_128BIT_ENABLED_DEFAULT); final Reporter<Span> reporter = buildReporter(map); final String localServiceName = getLocalServiceName(map); final Float samplerRate = getSamplerRate(map); final Tracing.Builder tracingBuilder = Tracing.newBuilder() .localServiceName(localServiceName) .traceId128Bit(traceId128bitEnabled) .sampler(Sampler.create(samplerRate)); if (reporter != null) { tracingBuilder.spanReporter(reporter); } tracing = tracingBuilder.build(); injector = tracing.propagation().injector(KafkaPropagation.HEADER_SETTER); extractor = tracing.propagation().extractor(KafkaPropagation.HEADER_GETTER); remoteServiceName = getRemoteServiceName(map); LOGGER.info("Zipkin Interceptor configured with local service name {} and " + "remote service name {}", localServiceName, remoteServiceName); }  @Override void configure(Map<String, ?> map);  }
@Test public void shouldBuildWithoutSenderWhenNoProperties() { Map<String, String> noConfig = new HashMap<>(); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(noConfig); assertNotNull(interceptor.tracing); }
@Test public void shouldConfigureWhenProducerDefaultConfig() { initialConfig.put(ProducerConfig.CLIENT_ID_CONFIG, "producer-app"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(initialConfig); assertNotNull(interceptor.tracing); assertEquals(TracingInterceptorConfig.ZIPKIN_REMOTE_SERVICE_NAME_DEFAULT, interceptor.remoteServiceName); }
@Test public void shouldConfigureWhenConsumerDefaultConfig() { initialConfig.put(ConsumerConfig.GROUP_ID_CONFIG, "consumer-app"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(initialConfig); assertNotNull(interceptor.tracing); assertEquals(TracingInterceptorConfig.ZIPKIN_REMOTE_SERVICE_NAME_DEFAULT, interceptor.remoteServiceName); }
@Test public void shouldConfigureWhenLocalServiceNameProvided() { initialConfig.put(TracingInterceptorConfig.ZIPKIN_LOCAL_SERVICE_NAME_CONFIG, "app"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(initialConfig); assertNotNull(interceptor.tracing); assertEquals(TracingInterceptorConfig.ZIPKIN_REMOTE_SERVICE_NAME_DEFAULT, interceptor.remoteServiceName); }
@Test public void shouldConfigureWhenSamplingRateProvided() { initialConfig.put(TracingInterceptorConfig.ZIPKIN_SAMPLER_RATE_CONFIG, "0.5"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(initialConfig); assertNotNull(interceptor.tracing); assertEquals(TracingInterceptorConfig.ZIPKIN_REMOTE_SERVICE_NAME_DEFAULT, interceptor.remoteServiceName); }
@Test public void shouldNotConfigureWhenInvalidSamplingRateProvided() { initialConfig.put(TracingInterceptorConfig.ZIPKIN_SAMPLER_RATE_CONFIG, "1.5"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(initialConfig); assertNotNull(interceptor.tracing); assertEquals(TracingInterceptorConfig.ZIPKIN_REMOTE_SERVICE_NAME_DEFAULT, interceptor.remoteServiceName); }
@Test public void shouldNotConfigureWhenInvalidSamplingRate2Provided() { initialConfig.put(TracingInterceptorConfig.ZIPKIN_SAMPLER_RATE_CONFIG, "NaN"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(initialConfig); assertNotNull(interceptor.tracing); assertEquals(TracingInterceptorConfig.ZIPKIN_REMOTE_SERVICE_NAME_DEFAULT, interceptor.remoteServiceName); }
@Test public void shouldNotConfigureWhenInvalidSamplingRate3Provided() { initialConfig.put(TracingInterceptorConfig.ZIPKIN_SAMPLER_RATE_CONFIG, "-"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); interceptor.configure(initialConfig); assertNotNull(interceptor.tracing); assertEquals(TracingInterceptorConfig.ZIPKIN_REMOTE_SERVICE_NAME_DEFAULT, interceptor.remoteServiceName); }