BaseTracingInterceptor implements Configurable { Sender buildSender(Map<String, ?> map) { final String zipkinApiUrl = extractString(map, TracingInterceptorConfig.ZIPKIN_API_URL_CONFIG); final String zipkinBootstrapServers = extractString(map, TracingInterceptorConfig.ZIPKIN_BOOTSTRAP_SERVERS_CONFIG); final Sender sender; if (Objects.isNull(zipkinApiUrl)) { if (Objects.isNull(zipkinBootstrapServers)) { final String kafkaBootstrapServers = extractString(map, CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG); if (Objects.nonNull(kafkaBootstrapServers)) { sender = KafkaSender.newBuilder().bootstrapServers(kafkaBootstrapServers).build(); LOGGER.info("Zipkin Interceptor: Kafka sender created with Bootstrap servers: {}", kafkaBootstrapServers); } else { final String kafkaBootstrapServersList = extractList(map, CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG); if (kafkaBootstrapServersList != null) { sender = KafkaSender.newBuilder().bootstrapServers(kafkaBootstrapServersList).build(); LOGGER.info("Brave Interceptor: Kafka sender created with Bootstrap servers: {}", kafkaBootstrapServersList); } else { sender = null; LOGGER.warn( "Zipkin Interceptor: No sender has been defined, spans will not be reported."); } } } else { sender = KafkaSender.newBuilder().bootstrapServers(zipkinBootstrapServers).build(); LOGGER.info("Zipkin Interceptor: Kafka sender created with Bootstrap servers: {}", zipkinBootstrapServers); } } else { sender = URLConnectionSender.create(zipkinApiUrl); LOGGER.info("Zipkin Interceptor: URL connection sender created with URL: {}", zipkinApiUrl); } return sender; }  @Override void configure(Map<String, ?> map);  }
@Test public void shouldCreateKafkaSenderWhenZipkinKafkaConfigProvided() { initialConfig.put(TracingInterceptorConfig.ZIPKIN_BOOTSTRAP_SERVERS_CONFIG, "kafka:9092"); BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); Sender sender = interceptor.buildSender(initialConfig); assertTrue(sender instanceof KafkaSender); }
@Test public void shouldBuildUrlSenderWhenZipkinApiUrlProvided() { initialConfig.put(TracingInterceptorConfig.ZIPKIN_LOCAL_SERVICE_NAME_CONFIG, "app"); initialConfig.put(TracingInterceptorConfig.ZIPKIN_API_URL_CONFIG, "http: BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); Sender sender = interceptor.buildSender(initialConfig); assertTrue(sender instanceof URLConnectionSender); }
@Test public void shouldCreateKafkaSenderWhenNoSenderConfigProvided() { BaseTracingInterceptor interceptor = new BaseTracingInterceptorImpl(); Sender sender = interceptor.buildSender(initialConfig); assertTrue(sender instanceof KafkaSender); }