@@ -68,6 +68,8 @@ public final class PythonSensor implements Sensor {
6868 static final String UNSET_VERSION_WARNING = "Your code is analyzed as compatible with all Python 3 versions by default." +
6969 " You can get a more precise analysis by setting the exact Python version in your configuration via the parameter \" sonar.python.version\" " ;
7070
71+ private final SensorTelemetryStorage sensorTelemetryStorage ;
72+
7173 /**
7274 * Constructor to be used by pico if neither PythonCustomRuleRepository nor PythonIndexer are to be found and injected.
7375 */
@@ -100,6 +102,7 @@ public PythonSensor(FileLinesContextFactory fileLinesContextFactory, CheckFactor
100102 this .indexer = indexer ;
101103 this .sonarLintCache = sonarLintCache ;
102104 this .analysisWarnings = analysisWarnings ;
105+ this .sensorTelemetryStorage = new SensorTelemetryStorage ();
103106 }
104107
105108 @ Override
@@ -121,15 +124,27 @@ public void execute(SensorContext context) {
121124 if (pythonVersionParameter .length != 0 ){
122125 ProjectPythonVersion .setCurrentVersions (PythonVersionUtils .fromStringArray (pythonVersionParameter ));
123126 }
127+ updatePythonVersionTelemetry (context , pythonVersionParameter );
124128 CacheContext cacheContext = CacheContextImpl .of (context );
125129 PythonIndexer pythonIndexer = this .indexer != null ? this .indexer : new SonarQubePythonIndexer (pythonFiles , cacheContext , context );
126130 pythonIndexer .setSonarLintCache (sonarLintCache );
127131 TypeShed .setProjectLevelSymbolTable (pythonIndexer .projectLevelSymbolTable ());
128132 PythonScanner scanner = new PythonScanner (context , checks , fileLinesContextFactory , noSonarFilter , PythonParser .create (), pythonIndexer );
129133 scanner .execute (pythonFiles , context );
134+ sensorTelemetryStorage .send (context );
130135 durationReport .stop ();
131136 }
132137
138+ private void updatePythonVersionTelemetry (SensorContext context , String [] pythonVersionParameter ) {
139+ if (context .runtime ().getProduct () == SonarProduct .SONARLINT ) {
140+ return ;
141+ }
142+ sensorTelemetryStorage .updateMetric (TelemetryMetricKey .PYTHON_VERSION_SET_KEY , pythonVersionParameter .length != 0 );
143+ if (pythonVersionParameter .length != 0 ) {
144+ sensorTelemetryStorage .updateMetric (TelemetryMetricKey .PYTHON_VERSION_KEY , String .join ("," , pythonVersionParameter ));
145+ }
146+ }
147+
133148 private static List <PythonInputFile > getInputFiles (SensorContext context ) {
134149 FilePredicates p = context .fileSystem ().predicates ();
135150 Iterable <InputFile > it = context .fileSystem ().inputFiles (p .and (p .hasLanguage (Python .KEY )));
0 commit comments