public ElasticApmTracer build() { if (configurationRegistry == null) { final List<ConfigurationSource> configSources = getConfigSources(agentArguments); configurationRegistry = getDefaultConfigurationRegistry(configSources); } if (reporter == null) { reporter = new ReporterFactory().createReporter(configurationRegistry, null, null); } if (lifecycleListeners == null) { lifecycleListeners = ServiceLoader.load(LifecycleListener.class, getClass().getClassLoader()); } return new ElasticApmTracer(configurationRegistry, reporter, lifecycleListeners, activationListeners); }
public Reporter createReporter(ConfigurationRegistry configurationRegistry, @Nullable String frameworkName, @Nullable String frameworkVersion) { final ReporterConfiguration reporterConfiguration = configurationRegistry.getConfig(ReporterConfiguration.class); ExecutorService healthCheckExecutorService = Executors.newFixedThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { final Thread thread = new Thread(r); thread.setName("apm-server-healthcheck"); thread.setDaemon(true); return thread; } }); healthCheckExecutorService.submit(new ApmServerHealthChecker(reporterConfiguration)); healthCheckExecutorService.shutdown(); final ReportingEventHandler reportingEventHandler = getReportingEventHandler(configurationRegistry, frameworkName, frameworkVersion, reporterConfiguration); return new ApmServerReporter(true, reporterConfiguration, reportingEventHandler); }
@Test void testValidatingSslCertificate() throws Exception { when(reporterConfiguration.isVerifyServerCert()).thenReturn(true); final Reporter reporter = reporterFactory.createReporter(configuration, null, null); reporter.report(new Transaction(mock(ElasticApmTracer.class))); reporter.flush().get(); assertThat(requestHandled).isFalse(); } }
@Test void testNotValidatingSslCertificate() throws Exception { when(reporterConfiguration.isVerifyServerCert()).thenReturn(false); final Reporter reporter = reporterFactory.createReporter(configuration, null, null); reporter.report(new Transaction(mock(ElasticApmTracer.class))); reporter.flush().get(); assertThat(requestHandled).isTrue(); }