Skip to content

Commit ff75352

Browse files
Report the scanner app using telemetry
1 parent 0065cd0 commit ff75352

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

java-frontend/src/main/java/org/sonar/java/TelemetryKey.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
* Telemetry keys used by the Java analyzer.
2121
*/
2222
public enum TelemetryKey {
23-
JAVA_LANGUAGE_VERSION("java.language.version");
23+
JAVA_LANGUAGE_VERSION("java.language.version"),
24+
JAVA_SCANNER_APP("java.scanner_app");
2425

2526
private final String key;
2627

sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
import static org.sonar.api.rules.RuleAnnotationUtils.getRuleKey;
5555
import static org.sonar.java.TelemetryKey.JAVA_LANGUAGE_VERSION;
56+
import static org.sonar.java.TelemetryKey.JAVA_SCANNER_APP;
5657

5758
@Phase(name = Phase.Name.PRE)
5859
@DependedUpon("org.sonar.plugins.java.JavaSensor")
@@ -110,6 +111,8 @@ public void execute(SensorContext context) {
110111
JavaVersion javaVersion = getJavaVersion();
111112
telemetry.addMetric(JAVA_LANGUAGE_VERSION, javaVersion.toString());
112113

114+
telemetry.addMetric(JAVA_SCANNER_APP, settings.get("sonar.scanner.app").orElse("none"));
115+
113116
JavaFrontend frontend = new JavaFrontend(javaVersion, sonarComponents, measurer, javaResourceLocator, postAnalysisIssueFilter,
114117
sonarComponents.mainChecks().toArray(new JavaCheck[0]));
115118
frontend.scan(getSourceFiles(), getTestFiles(), runJasper(context));

sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ void test_issues_creation_on_test_file() throws IOException { // NOSONAR require
122122
private void testIssueCreation(InputFile.Type onType, int expectedIssues) throws IOException {
123123
MapSettings settings = new MapSettings();
124124
settings.setProperty(JavaVersion.SOURCE_VERSION, "22");
125+
settings.setProperty("sonar.scanner.app", "ScannerJavaSensorTest");
126+
125127
NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
126128
SensorContextTester context = spy(createContext(onType).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7))));
127129
DefaultFileSystem fs = context.fileSystem();
@@ -135,6 +137,7 @@ private void testIssueCreation(InputFile.Type onType, int expectedIssues) throws
135137
verify(noSonarFilter, times(1)).noSonarInFile(fs.inputFiles().iterator().next(), Collections.singleton(118));
136138
verify(sonarComponents, times(expectedIssues)).reportIssue(any(AnalyzerMessage.class));
137139
verify(context).addTelemetryProperty("java.language.version", "22");
140+
verify(context).addTelemetryProperty("java.scanner_app", "ScannerJavaSensorTest");
138141

139142

140143
settings.setProperty(JavaVersion.SOURCE_VERSION, "wrongFormat");

0 commit comments

Comments
 (0)