|
8 | 8 | import com.azure.core.management.AzureEnvironment; |
9 | 9 | import com.microsoft.azure.toolkit.lib.Azure; |
10 | 10 | import com.microsoft.azure.toolkit.lib.account.IAzureAccount; |
| 11 | +import org.apache.commons.lang3.StringUtils; |
11 | 12 | import org.apache.commons.lang3.exception.ExceptionUtils; |
12 | 13 |
|
13 | 14 | import java.util.HashMap; |
14 | 15 | import java.util.Map; |
| 16 | +import java.util.Optional; |
15 | 17 | import java.util.UUID; |
16 | 18 | import java.util.function.Consumer; |
17 | 19 |
|
18 | 20 | import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CLASSNAME; |
19 | 21 | import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CODE; |
20 | 22 | 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; |
21 | 25 | import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_STACKTRACE; |
22 | 26 | import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_TYPE; |
23 | 27 | import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.OPERATION_NAME; |
@@ -213,14 +217,17 @@ public static boolean isAbleToCollectErrorStacks() { |
213 | 217 | private static void logError(String serviceName, String operName, ErrorType errorType, Throwable e, |
214 | 218 | Map<String, String> properties, Map<String, Double> metrics, boolean logErrorTraces) { |
215 | 219 | try { |
| 220 | + final Throwable rootCause = Optional.ofNullable(e).map(ExceptionUtils::getRootCause).orElse(null); |
216 | 221 | Map<String, String> mutableProps = properties == null ? new HashMap<>() : new HashMap<>(properties); |
217 | 222 | mutableProps.put(OPERATION_NAME, operName); |
218 | 223 | mutableProps.put(OPERATION_ID, UUID.randomUUID().toString()); |
219 | 224 | mutableProps.put(ERROR_CODE, "1"); |
220 | 225 | mutableProps.put(ERROR_CLASSNAME, e != null ? e.getClass().getName() : ""); |
221 | 226 | mutableProps.put(ERROR_TYPE, errorType.name()); |
| 227 | + mutableProps.put(ERROR_ROOT_CLASSNAME, Optional.ofNullable(rootCause).map(Throwable::getClass).map(Class::getName).orElse(StringUtils.EMPTY)); |
222 | 228 | if (logErrorTraces && isAbleToCollectErrorStacks()) { |
223 | 229 | mutableProps.put(ERROR_MSG, e != null ? e.getMessage() : ""); |
| 230 | + mutableProps.put(ERROR_ROOT_MSG, Optional.ofNullable(rootCause).map(Throwable::getMessage).orElse(StringUtils.EMPTY)); |
224 | 231 | mutableProps.put(ERROR_STACKTRACE, ExceptionUtils.getStackTrace(e)); |
225 | 232 | } |
226 | 233 | sendTelemetry(EventType.error, serviceName, mergeProperties(mutableProps), metrics); |
|
0 commit comments