in aws-xray-recorder-sdk-sql/src/main/java/com/amazonaws/xray/sql/TracingStatement.java [103:138]
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Subsegment subsegment = null;
if (isExecution(method)) {
// only trace on execution methods
subsegment = createSubsegment();
}
logger.debug(
String.format("Invoking statement execution with X-Ray tracing. Tracing active: %s", subsegment != null));
try {
// execute the query "wrapped" in a XRay Subsegment
return method.invoke(delegate, args);
} catch (Throwable t) {
Throwable rootThrowable = t;
if (t instanceof InvocationTargetException) {
// the reflection may wrap the actual error with an InvocationTargetException.
// we want to use the root cause to make the instrumentation seamless
InvocationTargetException ite = (InvocationTargetException) t;
if (ite.getTargetException() != null) {
rootThrowable = ite.getTargetException();
} else if (ite.getCause() != null) {
rootThrowable = ite.getCause();
}
}
if (subsegment != null) {
subsegment.addException(rootThrowable);
}
throw rootThrowable;
} finally {
if (subsegment != null && isExecution(method)) {
AWSXRay.endSubsegment();
}
}
}