[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 <Vitaly.Legchilkin@jetbrains.com>

GitOrigin-RevId: cfb1031bceaa21a633ac2a02b8064ed7bd74d4ea
This commit is contained in:
Vitaly Legchilkin
2025-06-11 16:36:38 +00:00
committed by intellij-monorepo-bot
parent 3390b0bc7c
commit a56a611bba
6 changed files with 19 additions and 8 deletions
@@ -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")
@@ -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()
@@ -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),
)
}
}
@@ -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)
}
}
@@ -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))
}
@@ -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)