@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(); } }
/** * Called when the container shuts down. * Cleans up thread pools and other resources. */ public void stop() { try { configurationRegistry.close(); reporter.close(); transactionPool.close(); spanPool.close(); errorPool.close(); for (LifecycleListener lifecycleListener : lifecycleListeners) { lifecycleListener.stop(); } } catch (Exception e) { logger.warn("Suppressed exception while calling stop()", e); } }
@SuppressWarnings("ReferenceEquality") public void endTransaction(Transaction transaction) { if (logger.isDebugEnabled()) { logger.debug("} endTransaction {}", transaction); if (logger.isTraceEnabled()) { logger.trace("ending transaction at", new RuntimeException("this exception is just used to record where the transaction has been ended from")); } } if (!transaction.isNoop()) { // we do report non-sampled transactions (without the context) reporter.report(transaction); } else { transaction.recycle(); } }
activationListener.init(this); reporter.scheduleMetricReporting(metricRegistry, configurationRegistry.getConfig(ReporterConfiguration.class).getMetricsIntervalMs());
@SuppressWarnings("ReferenceEquality") public void endSpan(Span span) { if (span.isSampled()) { long spanFramesMinDurationMs = stacktraceConfiguration.getSpanFramesMinDurationMs(); if (spanFramesMinDurationMs != 0 && span.isSampled()) { if (span.getDuration() >= spanFramesMinDurationMs) { span.withStacktrace(new Throwable()); } } reporter.report(span); } else { span.recycle(); } }
@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(); }
public void captureException(long epochMicros, @Nullable Throwable e, @Nullable TraceContextHolder<?> active) { if (e != null) { ErrorCapture error = errorPool.createInstance(); error.withTimestamp(epochMicros); error.setException(e); Transaction currentTransaction = currentTransaction(); if (currentTransaction != null) { error.setTransactionType(currentTransaction.getType()); error.setTransactionSampled(currentTransaction.isSampled()); } if (active != null) { if (active instanceof Transaction) { Transaction transaction = (Transaction) active; // The error might have occurred in a different thread than the one the transaction was recorded // That's why we have to ensure the visibility of the transaction properties error.getContext().copyFrom(transaction.getContextEnsureVisibility()); } else if (active instanceof Span) { Span span = (Span) active; error.getContext().getTags().putAll(span.getContext().getTags()); } error.asChildOf(active.getTraceContext()); } else { error.getTraceContext().getId().setToRandomValue(); } reporter.report(error); } }