Commit 990a8ff
authored
feat: include git commit SHA in PET
## Background
PET (Python Environment Tools) is a Rust-based JSONRPC server used by
the VS Code Python extension to discover Python environments. PET does
not send its own telemetry — instead, it returns metadata to the calling
extension (vscode-python-environments), which forwards it via telemetry.
To help catch regressions, we need a way to know exactly which PET build
a user is running by querying telemetry. [PR
#470](#470)
added a JSONRPC `info` request that returns PET's version and an
optional CI build ID. However, the build number alone isn't enough to
pinpoint the exact source code — we also need the git commit hash.
This PR extends the `info` response to include the **git commit SHA**
baked into the binary at build time. On the extension side, the
companion PR
([vscode-python-environments#1548](microsoft/vscode-python-environments#1548))
passes this information along to telemetry, so we can correlate
user-reported issues or regressions back to the specific PET commit.
## What Changed
### 1. Build script (`crates/pet/build.rs`)
- Added support for three new environment variables that CI systems set
automatically:
- `PET_COMMIT_SHA` — explicit override (highest priority)
- `BUILD_SOURCEVERSION` — set by Azure Pipelines
- `GITHUB_SHA` — set by GitHub Actions
- When any of these is present and non-empty, the value is embedded into
the binary as a compile-time constant via
`cargo:rustc-env=PET_COMMIT_SHA=...`.
### 2. JSONRPC response (`crates/pet/src/jsonrpc.rs`)
- Added a new optional `commit_sha` field to the `InfoResponse` struct.
- `InfoResponse::current()` populates it from the compile-time
`PET_COMMIT_SHA` env var (same pattern used for `build_id`).
- For local dev builds where no CI env var is set, the field is `None`
and omitted from the JSON response.
### 3. JSONRPC documentation (`docs/JSONRPC.md`)
- Updated the `InfoResponse` TypeScript interface to document the new
`commitSha?: string` field, including where the value is sourced from.
### 4. Tests (`crates/pet/src/jsonrpc.rs`,
`crates/pet/tests/jsonrpc_server_test.rs`,
`crates/pet/tests/jsonrpc_client.rs`)
- Added `commit_sha` field to the test client's `PetInfoResponse`
struct.
- Added assertions that `commit_sha`, when present, is non-empty
(mirrors existing `build_id` assertion pattern).
- Added clarifying comments explaining that both `build_id` and
`commit_sha` are `None` in local dev builds and only populated in CI.
## How It Works
```
CI build (Azure Pipelines / GitHub Actions)
↓ sets BUILD_SOURCEVERSION or GITHUB_SHA
build.rs captures it → bakes into binary as PET_COMMIT_SHA
↓
JSONRPC `info` request → returns { petVersion, buildId, commitSha }
↓
vscode-python-environments extension → includes commitSha in telemetry
↓
Team queries telemetry → correlates regressions to exact PET commit
```
## Related PRs
- [PET PR
#470](#470) —
Added the `info` JSONRPC request with version and build ID (merged)
- [vscode-python-environments PR
#1548](microsoft/vscode-python-environments#1548)
— Extension-side: passes PET version/build/commit info to telemetryinfo response for telemetry regression tracking (#473)1 parent 7a432f1 commit 990a8ff
5 files changed
Lines changed: 80 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
7 | 10 | | |
| 11 | + | |
| 12 | + | |
8 | 13 | | |
9 | 14 | | |
10 | | - | |
11 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
12 | 21 | | |
13 | 22 | | |
14 | 23 | | |
15 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
16 | 43 | | |
17 | 44 | | |
18 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
| 526 | + | |
| 527 | + | |
526 | 528 | | |
527 | 529 | | |
528 | 530 | | |
| |||
532 | 534 | | |
533 | 535 | | |
534 | 536 | | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
535 | 540 | | |
536 | 541 | | |
537 | 542 | | |
| |||
1537 | 1542 | | |
1538 | 1543 | | |
1539 | 1544 | | |
1540 | | - | |
| 1545 | + | |
1541 | 1546 | | |
1542 | 1547 | | |
1543 | 1548 | | |
| 1549 | + | |
| 1550 | + | |
1544 | 1551 | | |
1545 | 1552 | | |
1546 | 1553 | | |
1547 | 1554 | | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
1548 | 1584 | | |
1549 | 1585 | | |
1550 | 1586 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
124 | 130 | | |
125 | 131 | | |
126 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| |||
0 commit comments