Python: Add various kinds of extractor telemetry - #22502
Open
tausbn wants to merge 3 commits into
Open
Conversation
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
force-pushed
the
tausbn/python-add-various-kinds-of-extractor-telemetry
branch
2 times, most recently
from
September 3, 2026 15:21
bc3b4e1 to
f728505
Compare
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. As for tests, we add a new separate CLI integration test that checks the behaviour against a database that contains two files -- one that can be parsed with the old parser and one that requires the new one. The existing diagnostics test is modified slightly so that it ignores these statistics (as we cannot guarantee their exact form due to worker nondeterminism).
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
force-pushed
the
tausbn/python-add-various-kinds-of-extractor-telemetry
branch
from
September 3, 2026 20:31
f728505 to
e3dff5e
Compare
tausbn
marked this pull request as ready for review
September 3, 2026 20:55
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The telemetry paths are consistently integrated and covered by focused unit and integration tests.
Review tier: Balanced
Findings: None
What changed in this PR
Adds Python extractor telemetry for versions, parser usage, and non-default flags.
Changes:
- Emits extractor and per-worker parser telemetry.
- Records parser selection and command-line flags.
- Adds unit and integration coverage.
| File | Description |
|---|---|
python/extractor/tests/test_diagnostics.py |
Tests telemetry generation and counters. |
python/extractor/tests/test_cmdline.py |
Tests flag recording. |
python/extractor/semmle/worker.py |
Writes and aggregates telemetry. |
python/extractor/semmle/util.py |
Bumps extractor version. |
python/extractor/semmle/python/passes/flow.py |
Supplies a diagnostics writer. |
python/extractor/semmle/python/parser/dump_ast.py |
Supplies a diagnostics writer. |
python/extractor/semmle/python/modules.py |
Records parser usage. |
python/extractor/semmle/python/finder.py |
Propagates the diagnostics writer. |
python/extractor/semmle/logging.py |
Defines telemetry messages. |
python/extractor/semmle/extractors/py_extractor.py |
Passes telemetry state to modules. |
python/extractor/semmle/extractors/module_printer.py |
Propagates the diagnostics writer. |
python/extractor/semmle/cmdline.py |
Records non-default flags. |
python/extractor/cli-integration-test/writing-diagnostics/test_diagnostics_output.py |
Validates summary telemetry. |
python/extractor/cli-integration-test/writing-diagnostics/diagnostics.expected |
Updates expected diagnostics. |
python/extractor/cli-integration-test/parser-telemetry/test.sh |
Runs parser telemetry integration test. |
python/extractor/cli-integration-test/parser-telemetry/test_parser_telemetry.py |
Validates aggregate parser counts. |
python/extractor/cli-integration-test/parser-telemetry/repo_dir/tree_sitter_parser.py |
Exercises Tree-sitter fallback. |
python/extractor/cli-integration-test/parser-telemetry/repo_dir/old_parser.py |
Exercises the old parser. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends the extractor so as to emit the following kinds of telemetry:
Each of the above extensions is in its own commit, so I recommend going commit-by-commit.