Skip to content

Commit 25e4d38

Browse files
authored
Merge pull request #5034 from microsoft/temeletry/operation
[Telemetry #3] Deprecate old telemetry properties
2 parents e2d3c7f + 6c01501 commit 25e4d38

File tree

23 files changed

+152
-120
lines changed

23 files changed

+152
-120
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.jetbrains.annotations.Nullable;
2828
import rx.Observable;
2929

30-
import java.util.HashMap;
3130
import java.util.Map;
3231

3332
public abstract class AzureRunProfileState<T> implements RunProfileState {
@@ -45,24 +44,24 @@ public ExecutionResult execute(Executor executor, @NotNull ProgramRunner program
4544
ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(this.project).getConsole();
4645
processHandler.startNotify();
4746
consoleView.attachToProcess(processHandler);
48-
Map<String, String> telemetryMap = new HashMap<>();
4947
final Operation operation = createOperation();
5048
Observable.fromCallable(
5149
() -> {
5250
try {
53-
return this.executeSteps(processHandler, telemetryMap);
51+
operation.start();
52+
return this.executeSteps(processHandler, operation);
5453
} finally {
5554
// Once the operation done, whether success or not, `setText` should not throw new exception
5655
processHandler.setProcessTerminatedHandler(RunProcessHandler.DO_NOTHING);
5756
}
5857
}).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(
5958
(res) -> {
60-
this.sendTelemetry(operation, telemetryMap, null);
59+
this.sendTelemetry(operation, null);
6160
this.onSuccess(res, processHandler);
6261
},
6362
(err) -> {
6463
err.printStackTrace();
65-
this.sendTelemetry(operation, telemetryMap, err);
64+
this.sendTelemetry(operation, err);
6665
this.onFail(err, processHandler);
6766
});
6867
return new DefaultExecutionResult(consoleView, processHandler);
@@ -74,22 +73,20 @@ protected void setText(RunProcessHandler runProcessHandler, String text) {
7473
}
7574
}
7675

77-
private void sendTelemetry(Operation operation, @NotNull Map<String, String> telemetryMap, Throwable exception) {
78-
updateTelemetryMap(telemetryMap);
79-
operation.trackProperties(telemetryMap);
76+
private void sendTelemetry(Operation operation, Throwable exception) {
77+
operation.trackProperties(getTelemetryMap());
8078
if (exception != null) {
81-
EventUtil.logError(operation, ErrorType.userError, new Exception(exception.getMessage(), exception), telemetryMap, null);
79+
EventUtil.logError(operation, ErrorType.userError, new Exception(exception.getMessage(), exception), null, null);
8280
}
8381
operation.complete();
8482
}
8583

86-
protected abstract T executeSteps(@NotNull RunProcessHandler processHandler
87-
, @NotNull Map<String, String> telemetryMap) throws Exception;
84+
protected abstract T executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception;
8885

8986
@NotNull
9087
protected abstract Operation createOperation();
9188

92-
protected abstract void updateTelemetryMap(@NotNull Map<String, String> telemetryMap);
89+
protected abstract Map<String, String> getTelemetryMap();
9390

9491
protected abstract void onSuccess(T result, @NotNull RunProcessHandler processHandler);
9592

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/action/CreateFunctionAction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ protected PsiElement[] invokeDialog(Project project, PsiDirectory psiDirectory)
8282
PsiDirectory directory = ClassUtil.sourceRoot(psiDirectory);
8383
String newName = packageName.replace('.', '/');
8484
bindingTemplate = AzureFunctionsUtils.getFunctionTemplate(triggerType);
85-
EventUtil.logEvent(EventType.info, FUNCTION, CREATE_FUNCTION_TRIGGER, new HashMap<String, String>() {{
86-
put("triggerType", triggerType);
87-
}});
85+
operation.trackProperty("triggerType", triggerType);
8886
if (StringUtils.equalsIgnoreCase(triggerType, CreateFunctionForm.EVENT_HUB_TRIGGER)) {
8987
if (StringUtils.isBlank(connectionName)) {
9088
throw new AzureExecutionException(message("function.createFunction.error.connectionMissed"));

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.microsoft.azure.toolkit.intellij.function.runner.library.IFunctionContext;
1111
import com.microsoft.azuretools.authmanage.AuthMethodManager;
1212
import lombok.Data;
13+
import org.apache.commons.lang3.StringUtils;
1314

1415
import java.util.HashMap;
1516
import java.util.Map;
@@ -81,22 +82,16 @@ public IProject getProject() {
8182
return null;
8283
}
8384

84-
public Map<String, String> getTelemetryProperties(Map<String, String> properties) {
85-
HashMap result = new HashMap();
86-
85+
public Map<String, String> getTelemetryProperties() {
86+
final HashMap result = new HashMap();
8787
try {
88-
if (properties != null) {
89-
result.putAll(properties);
90-
}
91-
result.put("runtime", this.getRuntime().getOs());
88+
result.put("runtime", this.getOs());
9289
result.put("subscriptionId", this.getSubscription());
93-
result.put("pricingTier", this.getPricingTier());
9490
result.put("region", this.getRegion());
9591
result.put("functionJavaVersion", this.getJavaVersion());
9692
} catch (Exception e) {
9793
// swallow exception as telemetry should not break users operation
9894
}
99-
10095
return result;
10196
}
10297
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/deploy/FunctionDeploymentState.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import com.microsoft.azure.management.appservice.AppServicePlan;
1313
import com.microsoft.azure.management.appservice.FunctionApp;
1414
import com.microsoft.azure.management.appservice.WebAppBase;
15+
import com.microsoft.azure.toolkit.intellij.common.AzureRunProfileState;
16+
import com.microsoft.azure.toolkit.intellij.function.runner.core.FunctionUtils;
17+
import com.microsoft.azure.toolkit.intellij.function.runner.library.function.CreateFunctionHandler;
18+
import com.microsoft.azure.toolkit.intellij.function.runner.library.function.DeployFunctionHandler;
1519
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
1620
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1721
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
@@ -21,11 +25,7 @@
2125
import com.microsoft.azuretools.telemetrywrapper.TelemetryManager;
2226
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
2327
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
24-
import com.microsoft.azure.toolkit.intellij.common.AzureRunProfileState;
2528
import com.microsoft.intellij.RunProcessHandler;
26-
import com.microsoft.azure.toolkit.intellij.function.runner.core.FunctionUtils;
27-
import com.microsoft.azure.toolkit.intellij.function.runner.library.function.CreateFunctionHandler;
28-
import com.microsoft.azure.toolkit.intellij.function.runner.library.function.DeployFunctionHandler;
2929
import org.jetbrains.annotations.NotNull;
3030
import org.jetbrains.annotations.Nullable;
3131

@@ -38,7 +38,7 @@
3838

3939
public class FunctionDeploymentState extends AzureRunProfileState<WebAppBase> {
4040

41-
private FunctionDeployConfiguration functionDeployConfiguration;
41+
private final FunctionDeployConfiguration functionDeployConfiguration;
4242
private final FunctionDeployModel deployModel;
4343
private File stagingFolder;
4444

@@ -54,21 +54,16 @@ public FunctionDeploymentState(Project project, FunctionDeployConfiguration func
5454
@Nullable
5555
@Override
5656
@AzureOperation(name = "function.deploy.state", type = AzureOperation.Type.ACTION)
57-
public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler
58-
, @NotNull Map<String, String> telemetryMap) throws Exception {
59-
updateTelemetryMap(telemetryMap);
57+
public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
6058
// Update run time information by function app
6159
final FunctionApp functionApp;
6260
if (deployModel.isNewResource()) {
63-
functionApp = createFunctionApp(processHandler);
61+
functionApp = createFunctionApp(processHandler, operation);
6462
functionDeployConfiguration.setFunctionId(functionApp.id());
6563
} else {
6664
functionApp = AzureFunctionMvpModel.getInstance()
6765
.getFunctionById(functionDeployConfiguration.getSubscriptionId(), functionDeployConfiguration.getFunctionId());
6866
}
69-
if (functionApp == null) {
70-
throw new AzureExecutionException(message("function.deploy.error.functionNonexistent"));
71-
}
7267
final AppServicePlan appServicePlan = AppServiceUtils.getAppServicePlanByAppService(functionApp);
7368
functionDeployConfiguration.setOs(appServicePlan.operatingSystem().name());
7469
functionDeployConfiguration.setPricingTier(appServicePlan.pricingTier().toSkuDescription().size());
@@ -80,21 +75,22 @@ public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler
8075
if (processHandler.isProcessRunning()) {
8176
processHandler.setText(message);
8277
}
83-
});
78+
}, operation);
8479
return deployFunctionHandler.execute();
8580
}
8681

87-
private FunctionApp createFunctionApp(RunProcessHandler processHandler) {
82+
private FunctionApp createFunctionApp(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) {
8883
FunctionApp functionApp =
8984
AzureFunctionMvpModel.getInstance().getFunctionByName(functionDeployConfiguration.getSubscriptionId(),
9085
functionDeployConfiguration.getResourceGroup(),
9186
functionDeployConfiguration.getAppName());
87+
operation.trackProperty("isCreateNewApp", String.valueOf(functionApp == null));
9288
if (functionApp != null) {
9389
functionDeployConfiguration.setNewResource(false);
9490
return functionApp;
9591
}
9692
processHandler.setText(message("function.create.hint.creating", functionDeployConfiguration.getAppName()));
97-
final CreateFunctionHandler createFunctionHandler = new CreateFunctionHandler(functionDeployConfiguration.getModel());
93+
final CreateFunctionHandler createFunctionHandler = new CreateFunctionHandler(functionDeployConfiguration.getModel(), operation);
9894
functionApp = createFunctionHandler.execute();
9995
processHandler.setText(message("function.create.hint.created", functionDeployConfiguration.getAppName()));
10096
return functionApp;
@@ -105,14 +101,14 @@ private FunctionApp createFunctionApp(RunProcessHandler processHandler) {
105101
params = {"stagingFolder.getName()", "this.deployModel.getAppName()"},
106102
type = AzureOperation.Type.TASK
107103
)
108-
private void prepareStagingFolder(File stagingFolder, RunProcessHandler processHandler) throws Exception {
104+
private void prepareStagingFolder(File stagingFolder, RunProcessHandler processHandler) {
109105
AzureTaskManager.getInstance().read(() -> {
110106
final Path hostJsonPath = FunctionUtils.getDefaultHostJson(project);
111107
final PsiMethod[] methods = FunctionUtils.findFunctionsByAnnotation(functionDeployConfiguration.getModule());
112108
final Path folder = stagingFolder.toPath();
113109
try {
114110
FunctionUtils.prepareStagingFolder(folder, hostJsonPath, functionDeployConfiguration.getModule(), methods);
115-
} catch (AzureExecutionException | IOException e) {
111+
} catch (final AzureExecutionException | IOException e) {
116112
final String error = String.format("failed prepare staging folder[%s]", folder);
117113
throw new AzureToolkitRuntimeException(error, e);
118114
}
@@ -146,7 +142,7 @@ protected void onFail(@NotNull Throwable error, @NotNull RunProcessHandler proce
146142
}
147143

148144
@Override
149-
protected void updateTelemetryMap(@NotNull Map<String, String> telemetryMap) {
150-
telemetryMap.putAll(functionDeployConfiguration.getModel().getTelemetryProperties(telemetryMap));
145+
protected Map<String, String> getTelemetryMap() {
146+
return functionDeployConfiguration.getModel().getTelemetryProperties();
151147
}
152148
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/library/function/CreateFunctionHandler.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
2727
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
2828
import com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeployModel;
29+
import com.microsoft.azuretools.telemetrywrapper.Operation;
2930
import com.microsoft.tooling.msservices.helpers.azure.sdk.AzureSDKManager;
3031
import org.apache.commons.lang3.StringUtils;
3132

@@ -49,10 +50,12 @@ public class CreateFunctionHandler {
4950
private static final String APP_INSIGHTS_INSTRUMENTATION_KEY = "APPINSIGHTS_INSTRUMENTATIONKEY";
5051

5152
private FunctionDeployModel ctx;
53+
private Operation operation;
5254

53-
public CreateFunctionHandler(FunctionDeployModel ctx) {
55+
public CreateFunctionHandler(FunctionDeployModel ctx, Operation operation) {
5456
Preconditions.checkNotNull(ctx);
5557
this.ctx = ctx;
58+
this.operation = operation;
5659
}
5760

5861
public FunctionApp execute() {
@@ -92,6 +95,7 @@ private FunctionApp createFunctionApp() {
9295
withCreate.withAppSettings(appSettings);
9396

9497
FunctionApp result = withCreate.create();
98+
operation.trackProperty("pricingTier", ctx.getPricingTier());
9599
Log.prompt(message("function.create.hint.functionCreated", ctx.getAppName()));
96100
return result;
97101
}
@@ -112,7 +116,9 @@ private WithCreate configureApplicationLog(WithCreate withCreate) {
112116
type = AzureOperation.Type.SERVICE
113117
)
114118
private Map<String, String> bindingApplicationInsights() {
115-
if (StringUtils.isAllEmpty(ctx.getInsightsName(), ctx.getInstrumentationKey())) {
119+
final boolean disableAppInsights = StringUtils.isAllEmpty(ctx.getInsightsName(), ctx.getInstrumentationKey());
120+
operation.trackProperty("disableAppInsights", String.valueOf(disableAppInsights));
121+
if (disableAppInsights) {
116122
return Collections.emptyMap();
117123
}
118124
String instrumentationKey = ctx.getInstrumentationKey();

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/library/function/DeployFunctionHandler.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package com.microsoft.azure.toolkit.intellij.function.runner.library.function;
77

8-
import com.google.common.base.Preconditions;
98
import com.microsoft.azure.common.Utils;
109
import com.microsoft.azure.common.appservice.DeployTargetType;
1110
import com.microsoft.azure.common.appservice.DeploymentType;
@@ -26,12 +25,14 @@
2625
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
2726
import com.microsoft.azure.management.appservice.FunctionApp;
2827
import com.microsoft.azure.management.appservice.FunctionApp.Update;
29-
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
30-
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
3128
import com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeployModel;
3229
import com.microsoft.azure.toolkit.intellij.function.runner.library.IPrompter;
30+
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
31+
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
32+
import com.microsoft.azuretools.telemetrywrapper.Operation;
3333
import org.apache.commons.collections4.CollectionUtils;
3434
import org.apache.commons.lang3.StringUtils;
35+
import org.jetbrains.annotations.NotNull;
3536

3637
import java.io.IOException;
3738
import java.util.List;
@@ -59,11 +60,12 @@ public class DeployFunctionHandler {
5960
private static final OperatingSystemEnum DEFAULT_OS = OperatingSystemEnum.Windows;
6061
private FunctionDeployModel model;
6162
private IPrompter prompter;
63+
private Operation operation;
6264

63-
public DeployFunctionHandler(FunctionDeployModel model, IPrompter prompter) {
64-
Preconditions.checkNotNull(model);
65+
public DeployFunctionHandler(@NotNull FunctionDeployModel model, @NotNull IPrompter prompter, @NotNull Operation operation) {
6566
this.model = model;
6667
this.prompter = prompter;
68+
this.operation = operation;
6769
}
6870

6971
@AzureOperation(name = "function.deploy_artifact", type = AzureOperation.Type.SERVICE)
@@ -227,8 +229,8 @@ private void overrideDefaultAppSetting(Map result, String settingName, String se
227229

228230
private ArtifactHandler getArtifactHandler() throws AzureExecutionException {
229231
final ArtifactHandlerBase.Builder builder;
230-
231232
final DeploymentType deploymentType = getDeploymentType();
233+
operation.trackProperty("deploymentType", deploymentType.name());
232234
switch (deploymentType) {
233235
case MSDEPLOY:
234236
builder = new MSDeployArtifactHandlerImpl.Builder().functionAppName(this.model.getAppName());

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/localrun/FunctionRunState.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.microsoft.azure.common.function.bindings.BindingEnum;
2727
import com.microsoft.azure.common.function.configurations.FunctionConfiguration;
2828
import com.microsoft.azure.management.appservice.FunctionApp;
29+
import com.microsoft.azure.toolkit.intellij.common.AzureRunProfileState;
30+
import com.microsoft.azure.toolkit.intellij.function.runner.core.FunctionUtils;
2931
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
3032
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
3133
import com.microsoft.azure.toolkit.lib.common.task.AzureTask;
@@ -35,9 +37,7 @@
3537
import com.microsoft.azuretools.telemetrywrapper.TelemetryManager;
3638
import com.microsoft.azuretools.utils.CommandUtils;
3739
import com.microsoft.azuretools.utils.JsonUtils;
38-
import com.microsoft.azure.toolkit.intellij.common.AzureRunProfileState;
3940
import com.microsoft.intellij.RunProcessHandler;
40-
import com.microsoft.azure.toolkit.intellij.function.runner.core.FunctionUtils;
4141
import com.microsoft.intellij.util.ReadStreamLineThread;
4242
import org.apache.commons.lang.StringUtils;
4343
import org.apache.commons.lang3.ArrayUtils;
@@ -111,9 +111,8 @@ private void launchDebugger(final Project project, int debugPort) {
111111

112112
@Override
113113
@AzureOperation(name = "function.run.state", type = AzureOperation.Type.ACTION)
114-
protected FunctionApp executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Map<String, String> telemetryMap) throws Exception {
114+
protected FunctionApp executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
115115
// Prepare staging Folder
116-
updateTelemetryMap(telemetryMap);
117116
validateFunctionRuntime(processHandler);
118117
stagingFolder = FunctionUtils.getTempStagingFolder();
119118
addProcessTerminatedListener(processHandler);
@@ -335,8 +334,8 @@ private static int findFreePortForApi(int startPort) {
335334
}
336335

337336
@Override
338-
protected void updateTelemetryMap(@NotNull Map<String, String> telemetryMap) {
339-
telemetryMap.putAll(functionRunConfiguration.getModel().getTelemetryProperties(telemetryMap));
337+
protected Map<String, String> getTelemetryMap() {
338+
return functionRunConfiguration.getModel().getTelemetryProperties();
340339
}
341340

342341
@Override

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/wizard/module/FunctionsModuleBuilder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@ public void setupRootModel(@NotNull final ModifiableRootModel rootModel) {
119119
final String version = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_VERSION_KEY);
120120
final String packageName = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_PACKAGE_NAME_KEY);
121121
final String[] triggers = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_TRIGGERS_KEY);
122-
EventUtil.logEvent(EventType.info, FUNCTION, CREATE_FUNCTION_PROJECT, new HashMap<String, String>() {{
123-
put("tool", tool);
124-
put("triggerType", StringUtils.join(triggers, ","));
125-
}});
122+
operation.trackProperty("tool", tool);
123+
operation.trackProperty("triggerType", StringUtils.join(triggers, ","));
126124
File tempProjectFolder = null;
127125
try {
128126
tempProjectFolder = AzureFunctionsUtils.createFunctionProjectToTempFolder(groupId, artifactId, version, tool);

0 commit comments

Comments
 (0)