Skip to content

Python: Add various kinds of extractor telemetry - #22502

Draft
tausbn wants to merge 3 commits into
mainfrom
tausbn/python-add-various-kinds-of-extractor-telemetry
Draft

Python: Add various kinds of extractor telemetry#22502
tausbn wants to merge 3 commits into
mainfrom
tausbn/python-add-various-kinds-of-extractor-telemetry

Conversation

@tausbn

@tausbn tausbn commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Extends the extractor so as to emit the following kinds of telemetry:

  • Python runtime/analysis version. (The latter in particular will tell us the extent to which we still need to support older versions of Python.)
  • How many files were parsed with the old parser, and how many required the new parser. (Which will tell us whether we can get rid of the old parser.)
  • Which non-default extractor flags were used. (Which should inform us as to whether any of these flags can be safely removed or not.)

Each of the above extensions is in its own commit, so I recommend going commit-by-commit.

Here' `python_analysis_version` is the version of Python that we are
analysing the code as. In practice, all we care about is the major
version, but we might as well include the full thing (since it can be
overridden on the command line).

The `python_runtime_version` is the actual version of Python that ran
the extractor.
@tausbn tausbn added the no-change-note-required This PR does not need a change note label Sep 3, 2026
@github-actions github-actions Bot added the Python label Sep 3, 2026
@tausbn
tausbn force-pushed the tausbn/python-add-various-kinds-of-extractor-telemetry branch from 84fc2d3 to bc3b4e1 Compare September 3, 2026 15:14
Adds statistics on how many files were extracted using the old parser
and using the tree-sitter parser.

Because parsing is done in parallel across many workers, I opted not to
consolidate these statistics for the entire run. Instead, we emit the
statistics for each worker and then need to aggregate themselves after
the telemetry has been ingested. (In practice the number of workers is
~16 at most, so is unlikely to be an issue.)

In terms of implementation, I opted to simply extend the existing
`DiagnosticsWriter` object (instantiatied once per worker) with methods
for counting the number of parsed files, and then thread this object
through to `modules.py` where the magic happens.

Finally, this also required instantiating such an object in cases where
we call directly into the extractor for debugging purposes (e.g. dumping
the AST or CFG). Note that in these cases we do not actually print any
diagnostics, so it's harmless to create these objects.
Records any non-default extractor flags (without their arguments) as a
normalised string. This will enable us to determine which flags are
actually used (and which ones we might therefore get rid of).

When there are no flags other than the ones the autobuilder injects, we
simply report the string `"default"`. That way, there's no need to
remember exactly which flags are enabled by default during extraction.
@tausbn
tausbn force-pushed the tausbn/python-add-various-kinds-of-extractor-telemetry branch from bc3b4e1 to f728505 Compare September 3, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant