ThriftSenderFactory implements SenderFactory { @Override public Sender getSender(Configuration.SenderConfiguration conf) { if (null != conf.getEndpoint() && !conf.getEndpoint().isEmpty()) { HttpSender.Builder httpSenderBuilder = new HttpSender.Builder(conf.getEndpoint()); if (null != conf.getAuthUsername() && !conf.getAuthUsername().isEmpty() && null != conf.getAuthPassword() && !conf.getAuthPassword().isEmpty()) { log.debug("Using HTTP Basic authentication with data from the environment variables."); httpSenderBuilder.withAuth(conf.getAuthUsername(), conf.getAuthPassword()); } else if (null != conf.getAuthToken() && !conf.getAuthToken().isEmpty()) { log.debug("Auth Token environment variable found."); httpSenderBuilder.withAuth(conf.getAuthToken()); } log.debug("Using the HTTP Sender to send spans directly to the endpoint."); return httpSenderBuilder.build(); } log.debug("Using the UDP Sender to send spans to the agent."); return new UdpSender( stringOrDefault(conf.getAgentHost(), UdpSender.DEFAULT_AGENT_UDP_HOST), numberOrDefault(conf.getAgentPort(), UdpSender.DEFAULT_AGENT_UDP_COMPACT_PORT).intValue(), 0 ); }  @Override Sender getSender(Configuration.SenderConfiguration conf); @Override String getType();  }
@Test public void testSenderWithEndpointWithoutAuthData() { System.setProperty(Configuration.JAEGER_ENDPOINT, "https: Sender sender = Configuration.SenderConfiguration.fromEnv().getSender(); assertTrue(sender instanceof HttpSender); }
@Test public void testSenderWithAgentDataFromEnv() { System.setProperty(Configuration.JAEGER_AGENT_HOST, "jaeger-agent"); System.setProperty(Configuration.JAEGER_AGENT_PORT, "6832"); Sender sender = Configuration.SenderConfiguration.fromEnv().getSender(); assertTrue(sender instanceof UdpSender); }
@Test public void testSenderWithBasicAuthUsesHttpSender() { Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration() .withEndpoint("https: .withAuthUsername("username") .withAuthPassword("password"); assertTrue(senderConfiguration.getSender() instanceof HttpSender); }
@Test public void testSenderWithAuthTokenUsesHttpSender() { Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration() .withEndpoint("https: .withAuthToken("authToken"); assertTrue(senderConfiguration.getSender() instanceof HttpSender); }
@Test public void testSenderWithAllPropertiesReturnsHttpSender() { System.setProperty(Configuration.JAEGER_ENDPOINT, "https: System.setProperty(Configuration.JAEGER_AGENT_HOST, "jaeger-agent"); System.setProperty(Configuration.JAEGER_AGENT_PORT, "6832"); assertTrue(Configuration.SenderConfiguration.fromEnv().getSender() instanceof HttpSender); }
@Test public void testDefaultConfigurationReturnsUdpSender() { assertTrue(Configuration.SenderConfiguration.fromEnv().getSender() instanceof UdpSender); }