Skip to content

Commit 387c959

Browse files
authored
feat: add telemetry (#39)
Fixes #27 Signed-off-by: Jeff MAURY <[email protected]>
1 parent 2e49ef7 commit 387c959

File tree

6 files changed

+88
-9
lines changed

6 files changed

+88
-9
lines changed

USAGE_DATA.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## [Dependency Analytics](https://github.com/redhat-developer/intellij-dependency-analytics)
2+
3+
### Usage Data
4+
5+
* when plugin is started
6+
* when server is downloaded
7+
* when a component analysis is done
8+
* when plugin is shut down
9+

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ targetCompatibility = '1.8'
2222
intellij {
2323
version ideaVersion //for a full list of IntelliJ IDEA releases please see https://www.jetbrains.com/intellij-repository/releases
2424
pluginName 'org.jboss.tools.intellij.analytics'
25+
plugins 'com.redhat.devtools.intellij.telemetry:0.0.1.9'
2526
updateSinceUntilBuild false
2627
}
2728

@@ -39,5 +40,13 @@ dependencies {
3940
testImplementation("junit:junit:4.12")
4041
}
4142

43+
runIde {
44+
systemProperties['com.redhat.devtools.intellij.telemetry.mode'] = 'debug'
45+
}
46+
47+
runIdeForUiTests {
48+
systemProperties['com.redhat.devtools.intellij.telemetry.mode'] = 'debug'
49+
}
50+
4251
group 'org.jboss.tools.intellij'
4352
version projectVersion // Plugin version

src/main/java/org/jboss/tools/intellij/analytics/AnalyticsLanguageClient.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,49 @@
33
import com.intellij.notification.Notification;
44
import com.intellij.notification.NotificationType;
55
import com.intellij.notification.Notifications;
6+
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
7+
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage;
68
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
79
import org.jetbrains.annotations.NotNull;
810
import org.wso2.lsp4intellij.client.ClientContext;
911
import org.wso2.lsp4intellij.client.DefaultLanguageClient;
1012

13+
import java.net.URI;
14+
import java.net.URISyntaxException;
15+
import java.net.URL;
16+
import java.nio.file.Paths;
1117
import java.util.Map;
1218

1319
public class AnalyticsLanguageClient extends DefaultLanguageClient {
1420
public AnalyticsLanguageClient(@NotNull ClientContext context) {
1521
super(context);
1622
}
1723

24+
private static String getFilename(Map<String, Object> info) {
25+
String filename = null;
26+
String url = (String) info.get("uri");
27+
if (url != null) {
28+
try {
29+
filename = Paths.get(new URI(url)).getFileName().toString();
30+
} catch (URISyntaxException e) {}
31+
}
32+
return filename;
33+
}
34+
1835
@JsonNotification("caNotification")
1936
public void caNotify(Object payload) {
2037
if (payload instanceof Map) {
2138
Map<String, Object> info = (Map<String, Object>) payload;
2239
if (info.containsKey("data") && info.containsKey("diagCount")) {
40+
ActionMessage telemetry = TelemetryService.instance().action("lsp:component_analysis_done");
41+
String filename = getFilename(info);
42+
if (filename != null) {
43+
telemetry.property("filename", filename);
44+
}
45+
telemetry.send();
2346
Notifications.Bus.notify(new Notification("Analytics", "Analytics", (String) info.get("data"), NotificationType.INFORMATION));
2447
}
2548
}
2649
}
50+
2751
}

src/main/java/org/jboss/tools/intellij/analytics/GitHubReleaseDownloader.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
import com.intellij.openapi.application.ApplicationManager;
99
import com.intellij.openapi.components.Service;
1010
import com.intellij.openapi.components.ServiceManager;
11-
import com.intellij.openapi.diagnostic.Logger;
1211
import com.intellij.openapi.extensions.PluginId;
1312
import com.intellij.openapi.progress.ProgressIndicator;
1413
import com.intellij.openapi.project.Project;
1514
import com.intellij.util.io.HttpRequests;
15+
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
16+
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
1619

1720
public final class GitHubReleaseDownloader {
21+
private static Logger LOGGER = LoggerFactory.getLogger(GitHubReleaseDownloader.class);
1822
private final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("org.jboss.tools.intellij.analytics"));
1923
private final String fileName;
2024
private final ICookie cookies;
@@ -37,14 +41,22 @@ public File download(final ProgressIndicator indicator) throws IOException {
3741
if (!isNewRelease(latestReleaseTag) && dest.exists()) {
3842
return dest;
3943
}
40-
final String url = this.release.getDownloadUri(latestReleaseTag, this.fileName);
41-
HttpRequests
42-
.request(url)
43-
.productNameAsUserAgent()
44-
.saveToFile(dest, indicator);
44+
final ActionMessage telemetry = TelemetryService.instance().action("lsp:download").property("lspVersion", latestReleaseTag);
45+
try {
46+
final String url = this.release.getDownloadUri(latestReleaseTag, this.fileName);
47+
HttpRequests
48+
.request(url)
49+
.productNameAsUserAgent()
50+
.saveToFile(dest, indicator);
4551

46-
dest.setExecutable(true);
47-
cookies.setValue(ICookie.Name.LSPVersion, latestReleaseTag);
48-
return dest;
52+
dest.setExecutable(true);
53+
cookies.setValue(ICookie.Name.LSPVersion, latestReleaseTag);
54+
telemetry.send();
55+
return dest;
56+
} catch (IOException e) {
57+
telemetry.error(e).send();
58+
LOGGER.warn(e.getLocalizedMessage(), e);
59+
throw e;
60+
}
4961
}
5062
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package org.jboss.tools.intellij.analytics;
12+
13+
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
14+
import com.redhat.devtools.intellij.telemetry.core.util.Lazy;
15+
16+
public class TelemetryService {
17+
private static final TelemetryService INSTANCE = new TelemetryService();
18+
19+
private final Lazy<TelemetryMessageBuilder> builder = new Lazy<>(() -> new TelemetryMessageBuilder(TelemetryService.class.getClassLoader()));
20+
21+
public static TelemetryMessageBuilder instance() {
22+
return INSTANCE.builder.get();
23+
}
24+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
8989
on how to target different products -->
9090
<depends>com.intellij.modules.lang</depends>
91+
<depends>com.redhat.devtools.intellij.telemetry</depends>
9192

9293
<extensions defaultExtensionNs="com.intellij">
9394
<externalAnnotator id="LSPAnnotator-xml" language="XML" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>

0 commit comments

Comments
 (0)