Skip to content

Commit 4df0934

Browse files
SLLS-338 toolCalled telemetry
1 parent ec519ef commit 4df0934

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

src/main/java/org/sonarsource/sonarlint/ls/SonarLintExtendedLanguageServer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ public String getId() {
387387
@JsonNotification("sonarlint/helpAndFeedbackLinkClicked")
388388
CompletableFuture<Void> helpAndFeedbackLinkClicked(HelpAndFeedbackLinkClickedNotificationParams params);
389389

390+
record ToolCalledParams(String toolName, boolean success) {
391+
}
392+
393+
@JsonNotification("sonarlint/toolCalled")
394+
void toolCalled(ToolCalledParams params);
395+
390396
class ScanFolderForHotspotsParams {
391397
private final String folderUri;
392398

src/main/java/org/sonarsource/sonarlint/ls/SonarLintLanguageServer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ public CompletableFuture<Void> helpAndFeedbackLinkClicked(HelpAndFeedbackLinkCli
736736
return CompletableFuture.completedFuture(null);
737737
}
738738

739+
@Override
740+
public void toolCalled(ToolCalledParams params) {
741+
telemetry.toolCalled(params.toolName(), params.success());
742+
}
743+
739744
public Map<String, Path> getEmbeddedPluginsToPath() {
740745
var plugins = new HashMap<String, Path>();
741746
addPluginPathOrWarn("cfamily", Language.C, plugins);

src/main/java/org/sonarsource/sonarlint/ls/telemetry/SonarLintTelemetry.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.DevNotificationsClickedParams;
2727
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.FixSuggestionResolvedParams;
2828
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.HelpAndFeedbackClickedParams;
29+
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.ToolCalledParams;
2930
import org.sonarsource.sonarlint.ls.backend.BackendServiceFacade;
3031
import org.sonarsource.sonarlint.ls.log.LanguageClientLogger;
3132
import org.sonarsource.sonarlint.ls.settings.WorkspaceSettings;
@@ -87,6 +88,10 @@ public void helpAndFeedbackLinkClicked(String itemId) {
8788
actIfEnabled(telemetryRpcService -> telemetryRpcService.helpAndFeedbackLinkClicked(new HelpAndFeedbackClickedParams(itemId)));
8889
}
8990

91+
public void toolCalled(String toolName, boolean success) {
92+
actIfEnabled(telemetryRpcService -> telemetryRpcService.toolCalled(new ToolCalledParams(toolName, success)));
93+
}
94+
9095
public void addedAutomaticBindings() {
9196
actIfEnabled(TelemetryRpcService::addedAutomaticBindings);
9297
}

src/test/java/org/sonarsource/sonarlint/ls/mediumtests/LanguageServerMediumTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ void test_analysis_logs_enabled() throws Exception {
823823
"[Info] [org.sonarsource.analyzer.commons.ProgressReport : rules execution progress] 1 source file to be analyzed",
824824
"[Info] [sonarlint : sonarlint-analysis-scheduler] Analysis detected 1 issue and 0 Security Hotspots in XXXms"));
825825
}
826-
826+
827827
@Test
828828
void test_analysis_with_debug_logs_enabled() throws Exception {
829829
setShowVerboseLogs(client.globalSettings, true);

src/test/java/org/sonarsource/sonarlint/ls/telemetry/SonarLintTelemetryTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.FixSuggestionResolvedParams;
3535
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.FixSuggestionStatus;
3636
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.HelpAndFeedbackClickedParams;
37+
import org.sonarsource.sonarlint.core.rpc.protocol.client.telemetry.ToolCalledParams;
3738
import org.sonarsource.sonarlint.ls.backend.BackendService;
3839
import org.sonarsource.sonarlint.ls.backend.BackendServiceFacade;
3940
import org.sonarsource.sonarlint.ls.settings.WorkspaceSettings;
@@ -176,6 +177,24 @@ void helpAndFeedbackLinkClicked_when_disabled() {
176177
verify(telemetryService, never()).helpAndFeedbackLinkClicked(any());
177178
}
178179

180+
@Test
181+
void toolCalled_when_enabled() {
182+
ArgumentCaptor<ToolCalledParams> argument = ArgumentCaptor.forClass(ToolCalledParams.class);
183+
telemetry.toolCalled("lm.sonarqube_list_potential_security_issues", true);
184+
185+
verify(telemetryService).toolCalled(argument.capture());
186+
assertThat(argument.getValue().getToolName()).isEqualTo("lm.sonarqube_list_potential_security_issues");
187+
assertThat(argument.getValue().isSucceeded()).isTrue();
188+
}
189+
190+
@Test
191+
void toolCalled_when_disabled() {
192+
System.setProperty(SonarLintTelemetry.DISABLE_PROPERTY_KEY, "true");
193+
telemetry.toolCalled("lm.sonarqube_list_potential_security_issues", true);
194+
195+
verify(telemetryService, never()).toolCalled(any());
196+
}
197+
179198
@Test
180199
void addedAutomaticBindings_when_enabled() {
181200
telemetry.addedAutomaticBindings();

0 commit comments

Comments
 (0)