in apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java [480:525]
private ErrorCaptureImpl captureException(long epochMicros, @Nullable Throwable e, TraceStateImpl<?> parentContext, @Nullable ClassLoader initiatingClassLoader) {
if (!isRunning() || e == null) {
return null;
}
if (!coreConfiguration.captureExceptionDetails()) {
return null;
}
e = redactExceptionIfRequired(e);
while (e != null && WildcardMatcher.anyMatch(coreConfiguration.getUnnestExceptions(), e.getClass().getName()) != null) {
e = e.getCause();
}
// note: if we add inheritance support for exception filtering, caching would be required for performance
if (e != null && !WildcardMatcher.isAnyMatch(coreConfiguration.getIgnoreExceptions(), e.getClass().getName())) {
ErrorCaptureImpl error = errorPool.createInstance();
error.withTimestamp(epochMicros);
error.setException(e);
TransactionImpl currentTransaction = currentTransaction();
if (currentTransaction != null) {
if (currentTransaction.getNameForSerialization().length() > 0) {
error.setTransactionName(currentTransaction.getNameForSerialization());
}
error.setTransactionType(currentTransaction.getType());
error.setTransactionSampled(currentTransaction.isSampled());
}
AbstractSpanImpl<?> parent = parentContext.getSpan();
if (parent != null) {
error.asChildOf(parent);
// don't discard spans leading up to an error, otherwise they'd point to an invalid parent
parent.setNonDiscardable();
} else {
error.getTraceContext().getId().setToRandomValue();
ServiceInfo serviceInfo = getServiceInfoForClassLoader(initiatingClassLoader);
if (serviceInfo != null) {
error.getTraceContext().setServiceInfo(serviceInfo.getServiceName(), serviceInfo.getServiceVersion());
}
}
parentContext.getBaggage()
.storeBaggageInContext(error.getContext(), getConfig(CoreConfigurationImpl.class).getBaggageToAttach());
return error;
}
return null;
}