Skip to content

Commit 11537ae

Browse files
authored
Merge pull request #6261 from microsoft/error-telemetry-properties
Unify telemetry properties with azure toolkit lib
2 parents 97e25d9 + 2fbff59 commit 11537ae

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/intellij/AzureActionsListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@
7373
import java.util.logging.Level;
7474
import java.util.logging.SimpleFormatter;
7575

76+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.OPERATION_NAME;
77+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.SERVICE_NAME;
7678
import static com.microsoft.azuretools.Constants.FILE_NAME_CORE_LIB_LOG;
7779
import static com.microsoft.azuretools.telemetry.TelemetryConstants.PROXY;
7880
import static com.microsoft.azuretools.telemetry.TelemetryConstants.SYSTEM;
79-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.OPERATION_NAME;
80-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.SERVICE_NAME;
8181

8282
@Slf4j
8383
public class AzureActionsListener implements AppLifecycleListener, PluginComponent {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@
1515
import java.util.List;
1616
import java.util.Map;
1717

18+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.SERVICE_NAME;
19+
1820
public class CommonUtil {
1921

20-
public static final String OPERATION_NAME = "operationName";
21-
public static final String OPERATION_ID = "operationId";
22-
public static final String ERROR_CODE = "error.code";
23-
public static final String ERROR_MSG = "error.message";
24-
public static final String ERROR_TYPE = "error.type";
25-
public static final String ERROR_CLASSNAME = "error.class_name";
26-
public static final String ERROR_STACKTRACE = "error.stack";
2722
public static final String DURATION = "duration";
28-
public static final String SERVICE_NAME = "serviceName";
23+
public static final String OPERATION_ID = "operationId";
2924
public static final String TIMESTAMP = "timestamp";
3025
public static AzureTelemetryClient client;
3126
private static List<MutableTriple<EventType, Map, Map>> cachedEvents = new ArrayList<>();

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import java.util.Map;
1313
import java.util.UUID;
1414

15+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CLASSNAME;
16+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CODE;
17+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_MSG;
18+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_STACKTRACE;
19+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_TYPE;
20+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.OPERATION_NAME;
1521
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.DURATION;
16-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.ERROR_CLASSNAME;
17-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.ERROR_CODE;
18-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.ERROR_MSG;
19-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.ERROR_STACKTRACE;
20-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.ERROR_TYPE;
2122
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.OPERATION_ID;
22-
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.OPERATION_NAME;
2323
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.mergeProperties;
2424
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.sendTelemetry;
2525
import static com.microsoft.azuretools.telemetrywrapper.EventUtil.isAbleToCollectErrorStacks;
@@ -40,7 +40,7 @@ public DefaultOperation(String serviceName, String operationName) {
4040
this.operationId = UUID.randomUUID().toString();
4141
this.properties = new HashMap<>();
4242
properties.put(CommonUtil.OPERATION_ID, operationId);
43-
properties.put(CommonUtil.OPERATION_NAME, operationName);
43+
properties.put(OPERATION_NAME, operationName);
4444
}
4545

4646
public void logEvent(EventType eventType, Map<String, String> properties, Map<String, Double> metrics) {

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
import java.util.UUID;
1616
import java.util.function.Consumer;
1717

18+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CLASSNAME;
19+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_CODE;
20+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_MSG;
21+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_STACKTRACE;
22+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.ERROR_TYPE;
23+
import static com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter.OPERATION_NAME;
24+
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.OPERATION_ID;
1825
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.mergeProperties;
1926
import static com.microsoft.azuretools.telemetrywrapper.CommonUtil.sendTelemetry;
2027

@@ -25,8 +32,8 @@ public static void logEvent(EventType eventType, String serviceName, String oper
2532
try {
2633
// Parameter properties might be a ImmutableMap, which means calling properties.put will lead to UnsupportedOperationException
2734
Map<String, String> mutableProps = properties == null ? new HashMap<>() : new HashMap<>(properties);
28-
mutableProps.put(CommonUtil.OPERATION_NAME, operName);
29-
mutableProps.put(CommonUtil.OPERATION_ID, UUID.randomUUID().toString());
35+
mutableProps.put(OPERATION_NAME, operName);
36+
mutableProps.put(OPERATION_ID, UUID.randomUUID().toString());
3037
sendTelemetry(eventType, serviceName, mergeProperties(mutableProps), metrics);
3138
} catch (Exception ignore) {
3239
}
@@ -207,14 +214,14 @@ private static void logError(String serviceName, String operName, ErrorType erro
207214
Map<String, String> properties, Map<String, Double> metrics, boolean logErrorTraces) {
208215
try {
209216
Map<String, String> mutableProps = properties == null ? new HashMap<>() : new HashMap<>(properties);
210-
mutableProps.put(CommonUtil.OPERATION_NAME, operName);
211-
mutableProps.put(CommonUtil.OPERATION_ID, UUID.randomUUID().toString());
212-
mutableProps.put(CommonUtil.ERROR_CODE, "1");
213-
mutableProps.put(CommonUtil.ERROR_CLASSNAME, e != null ? e.getClass().getName() : "");
214-
mutableProps.put(CommonUtil.ERROR_TYPE, errorType.name());
217+
mutableProps.put(OPERATION_NAME, operName);
218+
mutableProps.put(OPERATION_ID, UUID.randomUUID().toString());
219+
mutableProps.put(ERROR_CODE, "1");
220+
mutableProps.put(ERROR_CLASSNAME, e != null ? e.getClass().getName() : "");
221+
mutableProps.put(ERROR_TYPE, errorType.name());
215222
if (logErrorTraces && isAbleToCollectErrorStacks()) {
216-
mutableProps.put(CommonUtil.ERROR_MSG, e != null ? e.getMessage() : "");
217-
mutableProps.put(CommonUtil.ERROR_STACKTRACE, ExceptionUtils.getStackTrace(e));
223+
mutableProps.put(ERROR_MSG, e != null ? e.getMessage() : "");
224+
mutableProps.put(ERROR_STACKTRACE, ExceptionUtils.getStackTrace(e));
218225
}
219226
sendTelemetry(EventType.error, serviceName, mergeProperties(mutableProps), metrics);
220227
} catch (Exception ignore) {

0 commit comments

Comments
 (0)