From a56a611bbad92283ed88fc49eaa4f0b9fab66cc0 Mon Sep 17 00:00:00 2001 From: Vitaly Legchilkin Date: Wed, 11 Jun 2025 16:36:38 +0000 Subject: [PATCH] [python] add FUS collector for add local interpreter events (PY-81398) + make previously_configured field shared Merge-request: IJ-MR-165380 Merged-by: Vitaly Legchilkin GitOrigin-RevId: cfb1031bceaa21a633ac2a02b8064ed7bd74d4ea --- .../collector/PythonNewProjectWizardCollector.kt | 2 +- .../jetbrains/python/sdk/AddInterpreterActions.kt | 2 +- .../PythonNewInterpreterAddedCollector.kt | 15 +++++++++------ .../add/v2/PythonAddLocalInterpreterPresenter.kt | 3 +++ .../add/v2/PythonSdkPanelBuilderAndSdkCreator.kt | 2 ++ .../python/statistics/PyStatisticTools.kt | 3 +++ 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/python/src/com/jetbrains/python/newProjectWizard/collector/PythonNewProjectWizardCollector.kt b/python/src/com/jetbrains/python/newProjectWizard/collector/PythonNewProjectWizardCollector.kt index 4ca14c8049d4..ee19506f6a62 100644 --- a/python/src/com/jetbrains/python/newProjectWizard/collector/PythonNewProjectWizardCollector.kt +++ b/python/src/com/jetbrains/python/newProjectWizard/collector/PythonNewProjectWizardCollector.kt @@ -13,6 +13,7 @@ import com.jetbrains.python.psi.LanguageLevel import com.jetbrains.python.statistics.EXECUTION_TYPE import com.jetbrains.python.statistics.INTERPRETER_CREATION_MODE import com.jetbrains.python.statistics.INTERPRETER_TYPE +import com.jetbrains.python.statistics.PREVIOUSLY_CONFIGURED import com.jetbrains.python.statistics.PYTHON_VERSION import org.jetbrains.annotations.ApiStatus.Internal @@ -27,7 +28,6 @@ object PythonNewProjectWizardCollector : CounterUsagesCollector() { const val PROJECT_GENERATED_EVENT_ID = "project.generated" private val INHERIT_GLOBAL_SITE_PACKAGE_FIELD = EventFields.Boolean("inherit_global_site_package") private val MAKE_AVAILABLE_TO_ALL_PROJECTS = EventFields.Boolean("make_available_to_all_projects") - private val PREVIOUSLY_CONFIGURED = EventFields.Boolean("previously_configured") private val IS_WSL_CONTEXT = EventFields.Boolean("wsl_context") private val GENERATOR_FIELD = EventFields.StringValidatedByCustomRule("generator", PyProjectTypeValidationRule::class.java) private val DJANGO_ADMIN_FIELD = EventFields.Boolean("django_admin") diff --git a/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt b/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt index 3424fdc592da..71ac79c75745 100644 --- a/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt +++ b/python/src/com/jetbrains/python/sdk/AddInterpreterActions.kt @@ -86,7 +86,7 @@ private class AddInterpreterOnTargetAction( val model = PyConfigurableInterpreterList.getInstance(project).model val sdk = (wizard.currentStepObject as? TargetCustomToolWizardStep)?.customTool as? Sdk if (sdk != null) { - PythonNewInterpreterAddedCollector.logPythonNewInterpreterAdded(sdk) + PythonNewInterpreterAddedCollector.logPythonNewInterpreterAdded(sdk, isPreviouslyConfigured = true) if (model.findSdk(sdk.name) == null) { model.addSdk(sdk) model.apply() diff --git a/python/src/com/jetbrains/python/sdk/add/collector/PythonNewInterpreterAddedCollector.kt b/python/src/com/jetbrains/python/sdk/add/collector/PythonNewInterpreterAddedCollector.kt index 8fa55500a4c4..ac73a5a37355 100644 --- a/python/src/com/jetbrains/python/sdk/add/collector/PythonNewInterpreterAddedCollector.kt +++ b/python/src/com/jetbrains/python/sdk/add/collector/PythonNewInterpreterAddedCollector.kt @@ -13,17 +13,20 @@ object PythonNewInterpreterAddedCollector : CounterUsagesCollector() { override fun getGroup(): EventLogGroup = GROUP - private val GROUP = EventLogGroup("python.new.interpreter.added", 4) - private val PROJECT_GENERATED_EVENT = GROUP.registerVarargEvent("interpreted.added", + private val GROUP = EventLogGroup("python.new.interpreter.added", 5) + private val INTERPRETER_ADDED_EVENT = GROUP.registerVarargEvent("interpreted.added", INTERPRETER_TYPE, EXECUTION_TYPE, - PYTHON_VERSION) + PYTHON_VERSION, + PREVIOUSLY_CONFIGURED, + ) - fun logPythonNewInterpreterAdded(sdk: Sdk) { - PROJECT_GENERATED_EVENT.log( + fun logPythonNewInterpreterAdded(sdk: Sdk, isPreviouslyConfigured: Boolean) { + INTERPRETER_ADDED_EVENT.log( INTERPRETER_TYPE.with(sdk.interpreterType.value), EXECUTION_TYPE.with(sdk.executionType.value), - PYTHON_VERSION.with(sdk.version.toPythonVersion()) + PYTHON_VERSION.with(sdk.version.toPythonVersion()), + PREVIOUSLY_CONFIGURED.with(isPreviouslyConfigured), ) } } diff --git a/python/src/com/jetbrains/python/sdk/add/v2/PythonAddLocalInterpreterPresenter.kt b/python/src/com/jetbrains/python/sdk/add/v2/PythonAddLocalInterpreterPresenter.kt index 14a6c27c5315..0137a6e7694b 100644 --- a/python/src/com/jetbrains/python/sdk/add/v2/PythonAddLocalInterpreterPresenter.kt +++ b/python/src/com/jetbrains/python/sdk/add/v2/PythonAddLocalInterpreterPresenter.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.util.io.toNioPathOrNull import com.jetbrains.python.Result import com.jetbrains.python.errorProcessing.ErrorSink import com.jetbrains.python.sdk.ModuleOrProject +import com.jetbrains.python.sdk.add.collector.PythonNewInterpreterAddedCollector import com.jetbrains.python.sdk.rootManager import com.jetbrains.python.sdk.service.PySdkService.Companion.pySdkService import com.jetbrains.python.venvReader.VirtualEnvReader @@ -43,6 +44,8 @@ class PythonAddLocalInterpreterPresenter(val moduleOrProject: ModuleOrProject, v } is Result.Success -> { moduleOrProject.project.pySdkService.persistSdk(r.result) + val isPreviouslyConfigured = addEnvironment.createStatisticsInfo(PythonInterpreterCreationTargets.LOCAL_MACHINE).previouslyConfigured + PythonNewInterpreterAddedCollector.logPythonNewInterpreterAdded(r.result, isPreviouslyConfigured) _sdkShared.emit(r.result) } } diff --git a/python/src/com/jetbrains/python/sdk/add/v2/PythonSdkPanelBuilderAndSdkCreator.kt b/python/src/com/jetbrains/python/sdk/add/v2/PythonSdkPanelBuilderAndSdkCreator.kt index 0281501e99e9..3b1bbeef8aeb 100644 --- a/python/src/com/jetbrains/python/sdk/add/v2/PythonSdkPanelBuilderAndSdkCreator.kt +++ b/python/src/com/jetbrains/python/sdk/add/v2/PythonSdkPanelBuilderAndSdkCreator.kt @@ -20,6 +20,7 @@ import com.jetbrains.python.errorProcessing.PyResult import com.jetbrains.python.newProject.collector.InterpreterStatisticsInfo import com.jetbrains.python.newProjectWizard.projectPath.ProjectPathFlows import com.jetbrains.python.sdk.ModuleOrProject +import com.jetbrains.python.sdk.add.collector.PythonNewInterpreterAddedCollector import com.jetbrains.python.sdk.add.v2.PythonInterpreterSelectionMode.* import com.jetbrains.python.statistics.InterpreterCreationMode import com.jetbrains.python.statistics.InterpreterTarget @@ -180,6 +181,7 @@ internal class PythonSdkPanelBuilderAndSdkCreator( }.getOr { return it } val statistics = withContext(Dispatchers.EDT) { createStatisticsInfo() } + PythonNewInterpreterAddedCollector.logPythonNewInterpreterAdded(sdk, statistics.previouslyConfigured) return Result.success(Pair(sdk, statistics)) } diff --git a/python/src/com/jetbrains/python/statistics/PyStatisticTools.kt b/python/src/com/jetbrains/python/statistics/PyStatisticTools.kt index 480786550cd5..e8defe0016f3 100644 --- a/python/src/com/jetbrains/python/statistics/PyStatisticTools.kt +++ b/python/src/com/jetbrains/python/statistics/PyStatisticTools.kt @@ -2,6 +2,7 @@ package com.jetbrains.python.statistics import com.intellij.internal.statistic.eventLog.EventLogGroup +import com.intellij.internal.statistic.eventLog.events.BooleanEventField import com.intellij.internal.statistic.eventLog.events.EventField import com.intellij.internal.statistic.eventLog.events.EventFields import com.intellij.internal.statistic.eventLog.events.EventPair @@ -128,6 +129,8 @@ val INTERPRETER_CREATION_MODE = EventFields.String("interpreter_creation_mode", CUSTOM.value, NA.value)) +internal val PREVIOUSLY_CONFIGURED: BooleanEventField = EventFields.Boolean("previously_configured") + private val Sdk.pythonImplementation: String get() = PythonSdkFlavor.getFlavor(this)?.name ?: "Python" val Sdk?.version: LanguageLevel get() = PySdkUtil.getLanguageLevelForSdk(this)