From 17e2914f27cc6a9b0994213cb5424e6d47520c21 Mon Sep 17 00:00:00 2001 From: Kirill Knize Date: Tue, 12 Nov 2024 14:38:47 +0100 Subject: [PATCH 1/4] sentry IO reference --- backend/core/pom.xml | 5 +++++ .../sonarsource/sonarlint/core/analysis/AnalysisService.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/backend/core/pom.xml b/backend/core/pom.xml index 427e15cd82..9a55111b86 100644 --- a/backend/core/pom.xml +++ b/backend/core/pom.xml @@ -153,6 +153,11 @@ logback-classic test + + io.sentry + sentry + 7.16.0 + diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java index 44dfdf03c1..8d7b757d52 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java @@ -20,6 +20,7 @@ package org.sonarsource.sonarlint.core.analysis; import com.google.common.util.concurrent.MoreExecutors; +import io.sentry.Sentry; import java.net.URI; import java.nio.file.FileSystemNotFoundException; import java.nio.file.Files; @@ -644,6 +645,9 @@ public boolean shouldUseEnterpriseCSharpAnalyzer(String configurationScopeId) { public CompletableFuture analyze(SonarLintCancelMonitor cancelMonitor, String configurationScopeId, UUID analysisId, List filePathsToAnalyze, Map extraProperties, long startTime, boolean enableTracking, boolean shouldFetchServerIssues, boolean hotspotsOnly) { + LOG.info("Sending Sentry message"); + Sentry.init("https://ad1c1fe3cb2b12fc2d191ecd25f89866@o1316750.ingest.us.sentry.io/4508201175089152"); + Sentry.captureException(new Exception("Test Error From SLCore")); var analysisEngine = engineCache.getOrCreateAnalysisEngine(configurationScopeId); var analysisConfig = getAnalysisConfigForEngine(configurationScopeId, filePathsToAnalyze, extraProperties, hotspotsOnly); From 193bfc7ac72e8ae6daae855d4f645caa813c6d71 Mon Sep 17 00:00:00 2001 From: Sophio Japharidze Date: Tue, 10 Dec 2024 16:26:40 +0100 Subject: [PATCH 2/4] SLCORE-1055 initialize Sentry service with relevant info --- .../core/analysis/AnalysisService.java | 4 -- .../DogfoodEnvironmentDetectionService.java | 34 ++++++++++ .../core/monitoring/MonitoringService.java | 68 +++++++++++++++++++ .../core/spring/SonarLintSpringAppConfig.java | 6 +- 4 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/DogfoodEnvironmentDetectionService.java create mode 100644 backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java index 8d7b757d52..44dfdf03c1 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java @@ -20,7 +20,6 @@ package org.sonarsource.sonarlint.core.analysis; import com.google.common.util.concurrent.MoreExecutors; -import io.sentry.Sentry; import java.net.URI; import java.nio.file.FileSystemNotFoundException; import java.nio.file.Files; @@ -645,9 +644,6 @@ public boolean shouldUseEnterpriseCSharpAnalyzer(String configurationScopeId) { public CompletableFuture analyze(SonarLintCancelMonitor cancelMonitor, String configurationScopeId, UUID analysisId, List filePathsToAnalyze, Map extraProperties, long startTime, boolean enableTracking, boolean shouldFetchServerIssues, boolean hotspotsOnly) { - LOG.info("Sending Sentry message"); - Sentry.init("https://ad1c1fe3cb2b12fc2d191ecd25f89866@o1316750.ingest.us.sentry.io/4508201175089152"); - Sentry.captureException(new Exception("Test Error From SLCore")); var analysisEngine = engineCache.getOrCreateAnalysisEngine(configurationScopeId); var analysisConfig = getAnalysisConfigForEngine(configurationScopeId, filePathsToAnalyze, extraProperties, hotspotsOnly); diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/DogfoodEnvironmentDetectionService.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/DogfoodEnvironmentDetectionService.java new file mode 100644 index 0000000000..d6b2ba1b71 --- /dev/null +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/DogfoodEnvironmentDetectionService.java @@ -0,0 +1,34 @@ +/* + * SonarLint Core - Implementation + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarsource.sonarlint.core.monitoring; + +import javax.inject.Named; +import javax.inject.Singleton; +import org.apache.commons.lang3.SystemUtils; + +@Named +@Singleton +public class DogfoodEnvironmentDetectionService { + private static final String SONARSOURCE_DOGFOODING_ENV_VAR_KEY = "SONARSOURCE_DOGFOODING"; + + public boolean isDogfoodEnvironment() { + return "1".equals(SystemUtils.getEnvironmentVariable(SONARSOURCE_DOGFOODING_ENV_VAR_KEY, "0")); + } +} diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java new file mode 100644 index 0000000000..368f5b942b --- /dev/null +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java @@ -0,0 +1,68 @@ +/* + * SonarLint Core - Implementation + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarsource.sonarlint.core.monitoring; + +import io.sentry.Sentry; +import javax.inject.Named; +import javax.inject.Singleton; +import org.apache.commons.lang3.SystemUtils; +import org.sonarsource.sonarlint.core.commons.SonarLintCoreVersion; +import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger; +import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.InitializeParams; + +@Named +@Singleton +public class MonitoringService { + private static final SonarLintLogger LOG = SonarLintLogger.get(); + + private InitializeParams initializeParams; + private DogfoodEnvironmentDetectionService dogfoodEnvDetectionService; + + public MonitoringService(InitializeParams initializeParams, DogfoodEnvironmentDetectionService dogfoodEnvDetectionService) { + this.initializeParams = initializeParams; + this.dogfoodEnvDetectionService = dogfoodEnvDetectionService; + + this.init(); + } + + public void init() { + var productKey = initializeParams.getTelemetryConstantAttributes().getProductKey(); + var environment = "dogfood"; + var sonarQubeForIDEVersion = initializeParams.getTelemetryConstantAttributes().getProductVersion(); + var ideVersion = initializeParams.getTelemetryConstantAttributes().getIdeVersion(); + var releaseVersion = SonarLintCoreVersion.get(); + var platform = SystemUtils.OS_NAME; + var architecture = SystemUtils.OS_ARCH; + + if (dogfoodEnvDetectionService.isDogfoodEnvironment()) { + LOG.info("Initializing Sentry"); + Sentry.init(sentryOptions -> { + sentryOptions.setDsn("https://ad1c1fe3cb2b12fc2d191ecd25f89866@o1316750.ingest.us.sentry.io/4508201175089152"); + sentryOptions.setRelease(releaseVersion); + sentryOptions.setEnvironment(environment); + sentryOptions.setTag("productKey", productKey); + sentryOptions.setTag("sonarQubeForIDEVersion", sonarQubeForIDEVersion); + sentryOptions.setTag("ideVersion", ideVersion); + sentryOptions.setTag("platform", platform); + sentryOptions.setTag("architecture", architecture); + }); + } + } +} diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java index c2e87e992e..9157c41ba4 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java @@ -45,9 +45,9 @@ import org.sonarsource.sonarlint.core.TokenGeneratorHelper; import org.sonarsource.sonarlint.core.VersionSoonUnsupportedHelper; import org.sonarsource.sonarlint.core.analysis.AnalysisEngineCache; -import org.sonarsource.sonarlint.core.analysis.UserAnalysisPropertiesRepository; import org.sonarsource.sonarlint.core.analysis.AnalysisService; import org.sonarsource.sonarlint.core.analysis.NodeJsService; +import org.sonarsource.sonarlint.core.analysis.UserAnalysisPropertiesRepository; import org.sonarsource.sonarlint.core.branch.SonarProjectBranchTrackingService; import org.sonarsource.sonarlint.core.commons.SonarLintUserHome; import org.sonarsource.sonarlint.core.embedded.server.AwaitingUserTokenFutureRepository; @@ -76,6 +76,7 @@ import org.sonarsource.sonarlint.core.languages.LanguageSupportRepository; import org.sonarsource.sonarlint.core.local.only.LocalOnlyIssueStorageService; import org.sonarsource.sonarlint.core.mode.SeverityModeService; +import org.sonarsource.sonarlint.core.monitoring.DogfoodEnvironmentDetectionService; import org.sonarsource.sonarlint.core.newcode.NewCodeService; import org.sonarsource.sonarlint.core.plugin.PluginsRepository; import org.sonarsource.sonarlint.core.plugin.PluginsService; @@ -191,7 +192,8 @@ FindingReportingService.class, PreviouslyRaisedFindingsRepository.class, UserAnalysisPropertiesRepository.class, - OpenFilesRepository.class + OpenFilesRepository.class, + DogfoodEnvironmentDetectionService.class }) public class SonarLintSpringAppConfig { From 6b8c94e95c859b18f643b9aa7dca947033bb7575 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Tue, 10 Dec 2024 17:03:51 +0100 Subject: [PATCH 3/4] SLCORE-1055 Manually trigger an event from analysis in a medium test --- .../core/analysis/AnalysisService.java | 3 + .../core/monitoring/MonitoringService.java | 6 ++ .../core/spring/SonarLintSpringAppConfig.java | 4 +- .../monitoring/MonitoringMediumTest.java | 96 +++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 medium-tests/src/test/java/mediumtest/monitoring/MonitoringMediumTest.java diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java index 44dfdf03c1..1f382f7b7e 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java @@ -20,6 +20,7 @@ package org.sonarsource.sonarlint.core.analysis; import com.google.common.util.concurrent.MoreExecutors; +import io.sentry.Sentry; import java.net.URI; import java.nio.file.FileSystemNotFoundException; import java.nio.file.Files; @@ -674,6 +675,8 @@ public CompletableFuture analyze(SonarLintCancelMonitor cancelM } else { LOG.error("Error during analysis", error); } + var testException = new Exception(); + Sentry.captureException(testException); }); } diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java index 368f5b942b..da69bd1cb6 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java @@ -62,6 +62,12 @@ public void init() { sentryOptions.setTag("ideVersion", ideVersion); sentryOptions.setTag("platform", platform); sentryOptions.setTag("architecture", architecture); + sentryOptions.addInAppInclude("org.sonarsource.sonarlint"); + + sentryOptions.setBeforeSend((event, hint) -> { + LOG.debug("Sending Sentry event" + event); + return event; + }); }); } } diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java index 9157c41ba4..1c49023a78 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java @@ -77,6 +77,7 @@ import org.sonarsource.sonarlint.core.local.only.LocalOnlyIssueStorageService; import org.sonarsource.sonarlint.core.mode.SeverityModeService; import org.sonarsource.sonarlint.core.monitoring.DogfoodEnvironmentDetectionService; +import org.sonarsource.sonarlint.core.monitoring.MonitoringService; import org.sonarsource.sonarlint.core.newcode.NewCodeService; import org.sonarsource.sonarlint.core.plugin.PluginsRepository; import org.sonarsource.sonarlint.core.plugin.PluginsService; @@ -193,7 +194,8 @@ PreviouslyRaisedFindingsRepository.class, UserAnalysisPropertiesRepository.class, OpenFilesRepository.class, - DogfoodEnvironmentDetectionService.class + DogfoodEnvironmentDetectionService.class, + MonitoringService.class }) public class SonarLintSpringAppConfig { diff --git a/medium-tests/src/test/java/mediumtest/monitoring/MonitoringMediumTest.java b/medium-tests/src/test/java/mediumtest/monitoring/MonitoringMediumTest.java new file mode 100644 index 0000000000..6c2757aa61 --- /dev/null +++ b/medium-tests/src/test/java/mediumtest/monitoring/MonitoringMediumTest.java @@ -0,0 +1,96 @@ +/* + * SonarLint Core - Medium Tests + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package mediumtest.monitoring; + +import java.nio.file.Path; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.ExecutionException; +import mediumtest.fixtures.SonarLintBackendFixture; +import mediumtest.fixtures.SonarLintTestRpcServer; +import mediumtest.fixtures.TestPlugin; +import org.assertj.core.api.Assumptions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonarsource.sonarlint.core.rpc.protocol.common.ClientFileDto; + +import static mediumtest.fixtures.SonarLintBackendFixture.newBackend; +import static mediumtest.fixtures.SonarLintBackendFixture.newFakeClient; +import static org.assertj.core.api.Assertions.assertThat; +import static testutils.AnalysisUtils.analyzeFileAndGetIssues; +import static testutils.AnalysisUtils.createFile; + +class MonitoringMediumTest { + + private static SonarLintBackendFixture.FakeSonarLintRpcClient client; + + private static final String A_JAVA_FILE_PATH = "Foo.java"; + private static final String CONFIGURATION_SCOPE_ID = "configScopeId"; + private static final List logs = new CopyOnWriteArrayList<>(); + private static SonarLintTestRpcServer backend; + // commercial plugins might not be available + // (if you pass -Dcommercial to maven, a profile will be activated that downloads the commercial plugins) + private static final boolean COMMERCIAL_ENABLED = System.getProperty("commercial") != null; + + @BeforeAll + static void checkDogfoodingVariableSet() { + Assumptions.assumeThat(System.getenv("SONARSOURCE_DOGFOODING")) + .withFailMessage("Dogfooding environment variable is not set, skipping tests") + .isEqualTo("1"); + } + + @AfterAll + static void stop() throws ExecutionException, InterruptedException { + Thread.sleep(5_000); + if (backend != null) { + backend.shutdown().get(); + } + } + + @AfterEach + void cleanup() { + client.cleanRaisedIssues(); + } + + @Test + void shouldPostMonitoringPingToSentry(@TempDir Path baseDir) throws Throwable { + var content = "function foo() {\n" + + " let x;\n" + + " let y; //NOSONAR\n" + + "}"; + var inputFile = createFile(baseDir, "foo.js", content); + + client = newFakeClient() + .withInitialFs(CONFIGURATION_SCOPE_ID, List.of( + new ClientFileDto(inputFile.toUri(), baseDir.relativize(inputFile), CONFIGURATION_SCOPE_ID, false, null, inputFile, null, null, true) + )) + .build(); + + backend = newBackend() + .withUnboundConfigScope(CONFIGURATION_SCOPE_ID) + .withStandaloneEmbeddedPluginAndEnabledLanguage(TestPlugin.JAVASCRIPT) + .build(client); + + analyzeFileAndGetIssues(inputFile.toUri(), client, backend, CONFIGURATION_SCOPE_ID); + } +} From 0b4f02c3b813eeb8392f3c9bd9bfb6da09551905 Mon Sep 17 00:00:00 2001 From: Sophio Japharidze Date: Thu, 12 Dec 2024 16:00:27 +0100 Subject: [PATCH 4/4] SLCORE-1055 capture Sentry exceptions before logging errors --- backend/commons/pom.xml | 13 ++++++ .../core/commons/log/LogOutputDelegator.java | 2 + .../DogfoodEnvironmentDetectionService.java | 4 +- .../MonitoringInitializationParams.java | 44 +++++++++++++++++++ .../monitoring/MonitoringService.java | 19 ++++---- backend/core/pom.xml | 5 --- .../core/analysis/AnalysisService.java | 3 -- .../core/spring/SonarLintSpringAppConfig.java | 12 ++++- 8 files changed, 81 insertions(+), 21 deletions(-) rename backend/{core/src/main/java/org/sonarsource/sonarlint/core => commons/src/main/java/org/sonarsource/sonarlint/core/commons}/monitoring/DogfoodEnvironmentDetectionService.java (93%) create mode 100644 backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/MonitoringInitializationParams.java rename backend/{core/src/main/java/org/sonarsource/sonarlint/core => commons/src/main/java/org/sonarsource/sonarlint/core/commons}/monitoring/MonitoringService.java (77%) diff --git a/backend/commons/pom.xml b/backend/commons/pom.xml index 63a957c2d7..1f9a2e2e67 100644 --- a/backend/commons/pom.xml +++ b/backend/commons/pom.xml @@ -55,6 +55,19 @@ logback-classic test + + io.sentry + sentry + 7.16.0 + + + javax.inject + javax.inject + + + org.apache.commons + commons-lang3 + diff --git a/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/log/LogOutputDelegator.java b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/log/LogOutputDelegator.java index 2025562e07..1832081268 100644 --- a/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/log/LogOutputDelegator.java +++ b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/log/LogOutputDelegator.java @@ -19,6 +19,7 @@ */ package org.sonarsource.sonarlint.core.commons.log; +import io.sentry.Sentry; import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -42,6 +43,7 @@ void log(@Nullable String formattedMessage, Level level, @Nullable String stackT void log(@Nullable String formattedMessage, Level level, @Nullable Throwable t) { String stacktrace = null; if (t != null) { + Sentry.captureException(t); stacktrace = LogOutput.stackTraceToString(t); } if (formattedMessage != null || t != null) { diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/DogfoodEnvironmentDetectionService.java b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/DogfoodEnvironmentDetectionService.java similarity index 93% rename from backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/DogfoodEnvironmentDetectionService.java rename to backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/DogfoodEnvironmentDetectionService.java index d6b2ba1b71..b828c4927e 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/DogfoodEnvironmentDetectionService.java +++ b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/DogfoodEnvironmentDetectionService.java @@ -1,5 +1,5 @@ /* - * SonarLint Core - Implementation + * SonarLint Core - Commons * Copyright (C) 2016-2024 SonarSource SA * mailto:info AT sonarsource DOT com * @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonarsource.sonarlint.core.monitoring; +package org.sonarsource.sonarlint.core.commons.monitoring; import javax.inject.Named; import javax.inject.Singleton; diff --git a/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/MonitoringInitializationParams.java b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/MonitoringInitializationParams.java new file mode 100644 index 0000000000..7a0cbda44b --- /dev/null +++ b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/MonitoringInitializationParams.java @@ -0,0 +1,44 @@ +/* + * SonarLint Core - Commons + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarsource.sonarlint.core.commons.monitoring; + +public class MonitoringInitializationParams { + private final String productKey; + private final String sonarQubeForIdeVersion; + private final String ideVersion; + + public MonitoringInitializationParams(String productKey, String sonarQubeForIdeVersion, String ideVersion) { + this.productKey = productKey; + this.sonarQubeForIdeVersion = sonarQubeForIdeVersion; + this.ideVersion = ideVersion; + } + + public String getProductKey() { + return productKey; + } + + public String getSonarQubeForIdeVersion() { + return sonarQubeForIdeVersion; + } + + public String getIdeVersion() { + return ideVersion; + } +} diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/MonitoringService.java similarity index 77% rename from backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java rename to backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/MonitoringService.java index da69bd1cb6..61a265ce0c 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/monitoring/MonitoringService.java +++ b/backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/monitoring/MonitoringService.java @@ -1,5 +1,5 @@ /* - * SonarLint Core - Implementation + * SonarLint Core - Commons * Copyright (C) 2016-2024 SonarSource SA * mailto:info AT sonarsource DOT com * @@ -17,25 +17,26 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonarsource.sonarlint.core.monitoring; +package org.sonarsource.sonarlint.core.commons.monitoring; import io.sentry.Sentry; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import org.apache.commons.lang3.SystemUtils; import org.sonarsource.sonarlint.core.commons.SonarLintCoreVersion; import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger; -import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.InitializeParams; @Named @Singleton public class MonitoringService { private static final SonarLintLogger LOG = SonarLintLogger.get(); - private InitializeParams initializeParams; - private DogfoodEnvironmentDetectionService dogfoodEnvDetectionService; + private final MonitoringInitializationParams initializeParams; + private final DogfoodEnvironmentDetectionService dogfoodEnvDetectionService; - public MonitoringService(InitializeParams initializeParams, DogfoodEnvironmentDetectionService dogfoodEnvDetectionService) { + @Inject + public MonitoringService(MonitoringInitializationParams initializeParams, DogfoodEnvironmentDetectionService dogfoodEnvDetectionService) { this.initializeParams = initializeParams; this.dogfoodEnvDetectionService = dogfoodEnvDetectionService; @@ -43,10 +44,10 @@ public MonitoringService(InitializeParams initializeParams, DogfoodEnvironmentDe } public void init() { - var productKey = initializeParams.getTelemetryConstantAttributes().getProductKey(); + var productKey = initializeParams.getProductKey(); var environment = "dogfood"; - var sonarQubeForIDEVersion = initializeParams.getTelemetryConstantAttributes().getProductVersion(); - var ideVersion = initializeParams.getTelemetryConstantAttributes().getIdeVersion(); + var sonarQubeForIDEVersion = initializeParams.getSonarQubeForIdeVersion(); + var ideVersion = initializeParams.getIdeVersion(); var releaseVersion = SonarLintCoreVersion.get(); var platform = SystemUtils.OS_NAME; var architecture = SystemUtils.OS_ARCH; diff --git a/backend/core/pom.xml b/backend/core/pom.xml index 9a55111b86..427e15cd82 100644 --- a/backend/core/pom.xml +++ b/backend/core/pom.xml @@ -153,11 +153,6 @@ logback-classic test - - io.sentry - sentry - 7.16.0 - diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java index 1f382f7b7e..44dfdf03c1 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java @@ -20,7 +20,6 @@ package org.sonarsource.sonarlint.core.analysis; import com.google.common.util.concurrent.MoreExecutors; -import io.sentry.Sentry; import java.net.URI; import java.nio.file.FileSystemNotFoundException; import java.nio.file.Files; @@ -675,8 +674,6 @@ public CompletableFuture analyze(SonarLintCancelMonitor cancelM } else { LOG.error("Error during analysis", error); } - var testException = new Exception(); - Sentry.captureException(testException); }); } diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java index 1c49023a78..fe7129078f 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/spring/SonarLintSpringAppConfig.java @@ -50,6 +50,9 @@ import org.sonarsource.sonarlint.core.analysis.UserAnalysisPropertiesRepository; import org.sonarsource.sonarlint.core.branch.SonarProjectBranchTrackingService; import org.sonarsource.sonarlint.core.commons.SonarLintUserHome; +import org.sonarsource.sonarlint.core.commons.monitoring.DogfoodEnvironmentDetectionService; +import org.sonarsource.sonarlint.core.commons.monitoring.MonitoringInitializationParams; +import org.sonarsource.sonarlint.core.commons.monitoring.MonitoringService; import org.sonarsource.sonarlint.core.embedded.server.AwaitingUserTokenFutureRepository; import org.sonarsource.sonarlint.core.embedded.server.EmbeddedServer; import org.sonarsource.sonarlint.core.embedded.server.GeneratedUserTokenHandler; @@ -76,8 +79,6 @@ import org.sonarsource.sonarlint.core.languages.LanguageSupportRepository; import org.sonarsource.sonarlint.core.local.only.LocalOnlyIssueStorageService; import org.sonarsource.sonarlint.core.mode.SeverityModeService; -import org.sonarsource.sonarlint.core.monitoring.DogfoodEnvironmentDetectionService; -import org.sonarsource.sonarlint.core.monitoring.MonitoringService; import org.sonarsource.sonarlint.core.newcode.NewCodeService; import org.sonarsource.sonarlint.core.plugin.PluginsRepository; import org.sonarsource.sonarlint.core.plugin.PluginsService; @@ -241,6 +242,13 @@ HttpClientProvider provideHttpClientProvider(InitializeParams params, @Named("us proxySelector, proxyCredentialsProvider); } + @Bean + MonitoringInitializationParams provideMonitoringInitParams(InitializeParams params) { + return new MonitoringInitializationParams(params.getTelemetryConstantAttributes().getProductKey(), + params.getTelemetryConstantAttributes().getProductVersion(), + params.getTelemetryConstantAttributes().getIdeVersion()); + } + private static HttpConfig adapt(HttpConfigurationDto dto, @Nullable Path sonarlintUserHome) { return new HttpConfig(adapt(dto.getSslConfiguration(), sonarlintUserHome), toTimeout(dto.getConnectTimeout()), toTimeout(dto.getSocketTimeout()), toTimeout(dto.getConnectionRequestTimeout()), toTimeout(dto.getResponseTimeout()));