Skip to content

Commit 4909383

Browse files
committed
add telemetry
1 parent 98dd527 commit 4909383

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-service-explorer/src/main/java/com/microsoft/azure/toolkit/intellij/explorer/azd/AzdNode.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ public AzdNode(Project project) {
3030

3131
public void addChildren() {
3232
if (isAzdInstalled()) {
33+
AzdUtils.logTelemetryEvent("azd-installed");
3334
if (isAzdSignedIn()) {
35+
AzdUtils.logTelemetryEvent("azd-signed-in");
3436
withDescription("Signed In");
3537
addChild(getCreateFromTemplatesNode());
3638
addChild(getInitializeFromSourceNode());
3739
addChild(getProvisionResourcesNode());
3840
addChild(getDeployToAzureNode());
3941
addChild(getProvisionAndDeployToAzureNode());
4042
} else {
43+
AzdUtils.logTelemetryEvent("azd-not-signed-in");
4144
withDescription("Not Signed In");
4245
onClicked(e -> {
4346
final ConfirmAndRunDialog confirmAndRunDialog = new ConfirmAndRunDialog(project, "Sign in", "Do you want to sign in to Azure Developer CLI (azd)?", "azd auth login");
@@ -46,6 +49,7 @@ public void addChildren() {
4649
});
4750
}
4851
} else {
52+
AzdUtils.logTelemetryEvent("azd-not-installed");
4953
withDescription("Install azd");
5054
onClicked(e -> {
5155
final String command;
@@ -93,7 +97,10 @@ private Node<String> getInitializeFromSourceNode() {
9397
private Node<String> getCreateFromTemplatesNode() {
9498
return new Node<>("Create from templates")
9599
.withIcon(AzureIcons.Common.CREATE)
96-
.onClicked(e -> new AzdTemplatesDialog(project).show());
100+
.onClicked(e -> {
101+
AzdUtils.logTelemetryEvent("azd-show-templates");
102+
new AzdTemplatesDialog(project).show();
103+
});
97104
}
98105

99106
private static boolean isAzdInstalled() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.microsoft.azure.toolkit.intellij.explorer.azd;
2+
3+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter;
4+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry;
5+
6+
import java.util.Map;
7+
8+
public final class AzdUtils {
9+
10+
private static final String AZURE_DEVELOPER_CLI = "azd";
11+
12+
private AzdUtils() {
13+
// Utility class, no instantiation allowed
14+
}
15+
16+
public static void logTelemetryEvent(String eventName) {
17+
Map<String, String> properties = Map.of(
18+
AzureTelemeter.OP_NAME, eventName,
19+
AzureTelemeter.OP_PARENT_ID, AZURE_DEVELOPER_CLI,
20+
AzureTelemeter.OPERATION_NAME, eventName, // what's the difference between OP_NAME and OPERATION_NAME?
21+
AzureTelemeter.SERVICE_NAME, AZURE_DEVELOPER_CLI
22+
);
23+
AzureTelemeter.log(AzureTelemetry.Type.INFO, properties);
24+
}
25+
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-service-explorer/src/main/java/com/microsoft/azure/toolkit/intellij/explorer/azd/ConfirmAndRunDialog.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,27 @@
88

99
import javax.swing.*;
1010
import java.awt.*;
11+
import java.util.Locale;
12+
import java.util.Objects;
1113

1214
public class ConfirmAndRunDialog extends DialogWrapper {
1315

1416
private final Project project;
1517
private final String label;
1618
private final String command;
19+
private final String eventName;
1720

1821
public ConfirmAndRunDialog(Project project, String title, String label, String command) {
1922
super(true);
2023
this.project = project;
21-
setTitle(title);
24+
setTitle(Objects.requireNonNull(title, "Title must not be null"));
2225
setOKButtonText("Run");
2326
this.label = label;
2427
init();
2528
setSize(300, 150);
2629
this.command = command;
30+
this.eventName = title.toLowerCase(Locale.ROOT).replace(" ", "-");
31+
AzdUtils.logTelemetryEvent("azd-" + eventName);
2732
}
2833

2934
public void setOkButtonText(String okButtonText) {
@@ -46,7 +51,14 @@ public void setOkButtonText(String okButtonText) {
4651

4752
@Override
4853
protected void doOKAction() {
54+
AzdUtils.logTelemetryEvent("azd-" + eventName + "-ok");
4955
super.doOKAction();
5056
TerminalUtils.executeInTerminal(project, command, "azd");
5157
}
58+
59+
@Override
60+
public void doCancelAction() {
61+
AzdUtils.logTelemetryEvent("azd-" + eventName + "-cancel");
62+
super.doCancelAction();
63+
}
5264
}

0 commit comments

Comments
 (0)