Skip to content

Commit 903e0fe

Browse files
committed
Track root exception in event util
1 parent 45b32bf commit 903e0fe

File tree

1 file changed

+7
-0
lines changed
  • Utils/azure-toolkit-ide-libs/azure-toolkit-ide-common-lib/src/main/java/com/microsoft/azuretools/telemetrywrapper

1 file changed

+7
-0
lines changed

Utils/azure-toolkit-ide-libs/azure-toolkit-ide-common-lib/src/main/java/com/microsoft/azuretools/telemetrywrapper/EventUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
import com.azure.core.management.AzureEnvironment;
99
import com.microsoft.azure.toolkit.lib.Azure;
1010
import com.microsoft.azure.toolkit.lib.account.IAzureAccount;
11+
import org.apache.commons.lang3.StringUtils;
1112
import org.apache.commons.lang3.exception.ExceptionUtils;
1213

1314
import java.util.HashMap;
1415
import java.util.Map;
16+
import java.util.Optional;
1517
import java.util.UUID;
1618
import java.util.function.Consumer;
1719

1820
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CLASSNAME;
1921
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CODE;
2022
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_MSG;
23+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_ROOT_CLASSNAME;
24+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_ROOT_MSG;
2125
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_STACKTRACE;
2226
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_TYPE;
2327
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.OPERATION_NAME;
@@ -213,14 +217,17 @@ public static boolean isAbleToCollectErrorStacks() {
213217
private static void logError(String serviceName, String operName, ErrorType errorType, Throwable e,
214218
Map<String, String> properties, Map<String, Double> metrics, boolean logErrorTraces) {
215219
try {
220+
final Throwable rootCause = Optional.ofNullable(e).map(ExceptionUtils::getRootCause).orElse(null);
216221
Map<String, String> mutableProps = properties == null ? new HashMap<>() : new HashMap<>(properties);
217222
mutableProps.put(OPERATION_NAME, operName);
218223
mutableProps.put(OPERATION_ID, UUID.randomUUID().toString());
219224
mutableProps.put(ERROR_CODE, "1");
220225
mutableProps.put(ERROR_CLASSNAME, e != null ? e.getClass().getName() : "");
221226
mutableProps.put(ERROR_TYPE, errorType.name());
227+
mutableProps.put(ERROR_ROOT_CLASSNAME, Optional.ofNullable(rootCause).map(Throwable::getClass).map(Class::getName).orElse(StringUtils.EMPTY));
222228
if (logErrorTraces && isAbleToCollectErrorStacks()) {
223229
mutableProps.put(ERROR_MSG, e != null ? e.getMessage() : "");
230+
mutableProps.put(ERROR_ROOT_MSG, Optional.ofNullable(rootCause).map(Throwable::getMessage).orElse(StringUtils.EMPTY));
224231
mutableProps.put(ERROR_STACKTRACE, ExceptionUtils.getStackTrace(e));
225232
}
226233
sendTelemetry(EventType.error, serviceName, mergeProperties(mutableProps), metrics);

0 commit comments

Comments
 (0)