Skip to content

Commit 00c828a

Browse files
authored
Intellij telemetry use the new telemetry method (#2940)
This commit only include "app service" part
1 parent ddfe923 commit 00c828a

File tree

5 files changed

+77
-6
lines changed

5 files changed

+77
-6
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/AzureRunProfileState.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
import com.intellij.openapi.project.Project;
3434
import com.microsoft.azuretools.core.mvp.ui.base.SchedulerProviderFactory;
3535
import com.microsoft.azuretools.telemetry.AppInsightsClient;
36+
import com.microsoft.azuretools.telemetrywrapper.ErrorType;
37+
import com.microsoft.azuretools.telemetrywrapper.EventType;
38+
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
39+
import com.microsoft.azuretools.telemetrywrapper.Operation;
40+
import java.util.HashMap;
41+
import java.util.Map;
3642
import org.jetbrains.annotations.NotNull;
3743
import org.jetbrains.annotations.Nullable;
3844
import rx.Observable;
3945

40-
import java.util.HashMap;
41-
import java.util.Map;
42-
4346
public abstract class AzureRunProfileState <T> implements RunProfileState {
4447
protected final Project project;
4548

@@ -57,22 +60,39 @@ public ExecutionResult execute(Executor executor, @NotNull ProgramRunner program
5760
processHandler.startNotify();
5861
consoleView.attachToProcess(processHandler);
5962
Map<String, String> telemetryMap = new HashMap<>();
63+
final Operation operation = createOperation();
6064
Observable.fromCallable(
6165
() -> {
66+
if (operation != null) {
67+
operation.start();
68+
EventUtil.logEvent(EventType.info, operation, telemetryMap);
69+
}
6270
return this.executeSteps(processHandler, telemetryMap);
6371
}).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(
6472
(res) -> {
73+
if (operation != null) {
74+
operation.complete();
75+
}
6576
this.sendTelemetry(telemetryMap, true, null);
6677
this.onSuccess(res, processHandler);
6778
},
6879
(err) -> {
6980
err.printStackTrace();
81+
if (operation != null) {
82+
EventUtil.logError(operation, ErrorType.userError, new Exception(err.getMessage(), err),
83+
telemetryMap, null);
84+
operation.complete();
85+
}
7086
this.onFail(err.getMessage(), processHandler);
7187
this.sendTelemetry(telemetryMap, false, err.getMessage());
7288
});
7389
return new DefaultExecutionResult(consoleView, processHandler);
7490
}
7591

92+
protected Operation createOperation() {
93+
return null;
94+
}
95+
7696
protected void updateTelemetryMap(@NotNull Map<String, String> telemetryMap){}
7797

7898
private void sendTelemetry(@NotNull Map<String, String> telemetryMap, boolean success, @Nullable String errorMsg) {

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/WebAppRunState.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import com.microsoft.azure.management.appservice.WebAppBase;
3333
import com.microsoft.azuretools.azurecommons.util.FileUtil;
3434
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
35+
import com.microsoft.azuretools.telemetry.TelemetryConstants;
36+
import com.microsoft.azuretools.telemetrywrapper.Operation;
37+
import com.microsoft.azuretools.telemetrywrapper.TelemetryManager;
3538
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
3639
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
3740
import com.microsoft.azuretools.utils.WebAppUtils;
@@ -149,6 +152,11 @@ private void openWebAppInBrowser(String url, RunProcessHandler processHandler) {
149152
}
150153
}
151154

155+
@Override
156+
protected Operation createOperation() {
157+
return TelemetryManager.createOperation(TelemetryConstants.WEBAPP, TelemetryConstants.DEPLOY_WEBAPP);
158+
}
159+
152160
@Override
153161
protected void onSuccess(WebAppBase result, @NotNull RunProcessHandler processHandler) {
154162
if (webAppSettingModel.isCreatingNew() && AzureUIRefreshCore.listeners != null) {

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/creation/WebAppCreationDialog.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.microsoft.intellij.runner.webapp.webappconfig.slimui.creation;
22

33

4+
import static com.microsoft.azuretools.telemetry.TelemetryConstants.CREATE_WEBAPP;
5+
import static com.microsoft.azuretools.telemetry.TelemetryConstants.WEBAPP;
6+
47
import com.intellij.openapi.application.ApplicationManager;
58
import com.intellij.openapi.options.ConfigurationException;
69
import com.intellij.openapi.progress.ProgressIndicator;
@@ -20,6 +23,8 @@
2023
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
2124
import com.microsoft.azuretools.core.mvp.model.webapp.JdkModel;
2225
import com.microsoft.azuretools.telemetry.AppInsightsClient;
26+
import com.microsoft.azuretools.telemetrywrapper.EventType;
27+
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
2328
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
2429
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
2530
import com.microsoft.azuretools.utils.WebAppUtils;
@@ -427,8 +432,10 @@ private void createWebApp() {
427432
ProgressManager.getInstance().run(new Task.Modal(null, "Creating New WebApp...", true) {
428433
@Override
429434
public void run(ProgressIndicator progressIndicator) {
430-
try {
435+
Map<String, String> properties = webAppConfiguration.getModel().getTelemetryProperties(null);
436+
EventUtil.executeWithLog(WEBAPP, CREATE_WEBAPP, properties, null, (operation) -> {
431437
progressIndicator.setIndeterminate(true);
438+
EventUtil.logEvent(EventType.info, operation, properties);
432439
result = AzureWebAppMvpModel.getInstance().createWebApp(webAppConfiguration.getModel());
433440
ApplicationManager.getApplication().invokeLater(() -> {
434441
sendTelemetry(true, null);
@@ -438,11 +445,11 @@ public void run(ProgressIndicator progressIndicator) {
438445
}
439446
});
440447
dispose();
441-
} catch (Exception ex) {
448+
}, (ex) -> {
442449
JOptionPane.showMessageDialog(null, "Create WebApp Failed : " + ex.getMessage(),
443450
"Create WebApp Failed", JOptionPane.ERROR_MESSAGE);
444451
sendTelemetry(false, ex.getMessage());
445-
}
452+
});
446453
}
447454
});
448455
}

Utils/azuretools-core/src/com/microsoft/azuretools/core/mvp/model/webapp/WebAppSettingModel.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import com.microsoft.azure.management.appservice.JavaVersion;
2727
import com.microsoft.azure.management.appservice.OperatingSystem;
2828
import com.microsoft.azure.management.appservice.RuntimeStack;
29+
import com.microsoft.azuretools.telemetry.TelemetryConstants;
30+
import com.microsoft.azuretools.utils.WebAppUtils;
31+
import java.util.HashMap;
32+
import java.util.Map;
2933

3034
public class WebAppSettingModel {
3135

@@ -247,4 +251,24 @@ public void setOS(final OperatingSystem value) {
247251
this.os = value;
248252
}
249253

254+
public Map<String, String> getTelemetryProperties(Map<String, String> properties) {
255+
Map<String, String> result = new HashMap<>();
256+
try {
257+
if (properties != null) {
258+
result.putAll(properties);
259+
}
260+
result.put(TelemetryConstants.RUNTIME,
261+
os == OperatingSystem.LINUX ? "linux-" + getLinuxRuntime()
262+
.toString() : "windows-" + getWebContainer());
263+
result.put(TelemetryConstants.WEBAPP_DEPLOY_TO_SLOT, String.valueOf(isDeployToSlot()));
264+
result.put(TelemetryConstants.SUBSCRIPTIONID, getSubscriptionId());
265+
result.put(TelemetryConstants.CREATE_NEWWEBAPP, String.valueOf(isCreatingNew()));
266+
result.put(TelemetryConstants.CREATE_NEWASP, String.valueOf(isCreatingAppServicePlan()));
267+
result.put(TelemetryConstants.CREATE_NEWRG, String.valueOf(isCreatingResGrp()));
268+
result.put(TelemetryConstants.FILETYPE, WebAppUtils.getFileType(getTargetName()));
269+
} catch (Exception ignore) {
270+
}
271+
return result;
272+
}
273+
250274
}

Utils/azuretools-core/src/com/microsoft/azuretools/utils/WebAppUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,16 @@ public static List<RuntimeStack> getAllJavaLinuxRuntimeStacks() {
521521
RuntimeStack.WILDFLY_14_JRE8,
522522
RuntimeStack.JAVA_8_JRE8});
523523
}
524+
525+
public static String getFileType(String fileName) {
526+
if (StringUtils.isBlank(fileName)) {
527+
return "";
528+
}
529+
String fileType = "";
530+
int index = fileName.lastIndexOf(".");
531+
if (index >= 0 && (index + 1) < fileName.length()) {
532+
fileType = fileName.substring(index + 1);
533+
}
534+
return fileType;
535+
}
524536
}

0 commit comments

Comments
 (0)