feat: telemetry - #150
Conversation
- added the schema or the new telemetry table in the api - generated and ran migrations scripts
- added a telemetry module with a module, service and dtos and two methods in the service: create and findOne telemetry event - updated the extensionService to add a new method `collectTelemetryData` and its dto - created a new protected procedure `collectTelemetryData` calling that method in the extension router - added a new common dto `SemVerDto` to validate semantic versioned strings
- added a `collectTelemetryData` function in the extension to get the telemetry data and send them to the api at the extension startup - moved the SemVerSchema in the @repo/common types-schemas instead of the api because we use it in the `collectTelemetryData` to validate the raw extension version extracted from its `package.json` (it is typed as any) - added more constraint on the machineId schema because it is a "sha256" hash
- added tests for the methods of the TelemetryService - added tests for the `collectTelemetryData` method of the ExtensionService - bumped zod to `v4.4.3` in all apps and packages (api, dashboard, vscode-extension and @repo/common)
|
Warning Review limit reached
Next review available in: 34 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds telemetry collection from the VS Code extension through a protected API procedure, with semantic-version and machine-ID validation, persistence in a new database table, deduplication by user and machine, and associated module wiring and tests. ChangesTelemetry collection
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant VSCodeExtension
participant TelemetryCollector
participant ExtensionRouter
participant ExtensionService
participant TelemetryService
participant Database
VSCodeExtension->>TelemetryCollector: activate()
TelemetryCollector->>TelemetryCollector: check setting and validate versions
TelemetryCollector->>ExtensionRouter: collectTelemetryData mutation
ExtensionRouter->>ExtensionService: add authenticated userId
ExtensionService->>TelemetryService: findOne(userId, machineId)
TelemetryService->>Database: query telemetry record
Database-->>TelemetryService: matching record or none
ExtensionService->>TelemetryService: create when versions differ or record is absent
TelemetryService->>Database: insert telemetry record
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
apps/api/src/telemetry/telemetry.service.test.ts (2)
15-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
vi.clearAllMocks()on line 34 is a no-op here — the mocks are freshly constructed above it each run.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/api/src/telemetry/telemetry.service.test.ts` around lines 15 - 34, Remove the redundant vi.clearAllMocks() call from the mock initialization setup following the mockedDrizzle construction, since these mocks are newly created for each run and do not require clearing.
66-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTests never assert what was passed to Drizzle.
Both cases would still pass if
createinserted the wrong columns orfindOnedropped themachineIdpredicate. Asserting onvalues/wherecalls is what makes these tests meaningful. Also consider a real ULID foruserIdinstead of"1"so fixtures match the DTO contract.💚 Example assertion
const createdTelemetryEvent = await telemetryService.create(mockedEntry); + expect(mockedDrizzle.values).toHaveBeenCalledWith({ + userId: mockedEntry.userId, + machineId: mockedEntry.machineId, + extensionVersion: mockedEntry.extensionVersion, + vscodeVersion: mockedEntry.vscodeVersion, + }); expect(createdTelemetryEvent).toBeDefined();Also applies to: 90-95
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/api/src/telemetry/telemetry.service.test.ts` around lines 66 - 71, Strengthen the telemetry service tests around create and findOne by asserting the Drizzle insert values and query where predicate, including the expected machineId condition. Update the mocked userId fixture from "1" to a valid ULID consistent with the DTO contract, while preserving the existing result assertions.apps/api/src/telemetry/telemetry.dto.ts (1)
12-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: derive
FindTelemetryDtofromCreateTelemetryDtoto avoid shape drift.♻️ Proposed refactor
-export const FindTelemetryDto = z.object({ - machineId: z.hash("sha256"), - userId: z.ulid(), -}); +export const FindTelemetryDto = CreateTelemetryDto.pick({ + machineId: true, + userId: true, +});🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/api/src/telemetry/telemetry.dto.ts` around lines 12 - 15, Update FindTelemetryDto to derive its shared field definitions from CreateTelemetryDto, reusing its machineId and userId schemas rather than duplicating them. Preserve FindTelemetryDto’s existing validation shape while preventing future schema drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/api/src/extension/extension.service.ts`:
- Around line 35-50: The telemetryService flow around findOne and create must
become atomic: enforce a unique (userId, machineId) constraint, then replace the
read-then-insert branch with a database-backed upsert that updates both
vscodeVersion and extensionVersion for existing entries. Add a regression test
covering concurrent requests and repeated versions, verifying only one entry
exists and the latest versions are persisted.
In `@apps/api/src/telemetry/telemetry.service.ts`:
- Around line 16-30: The telemetry write path must enforce one row per user and
machine. In apps/api/src/telemetry/telemetry.service.ts lines 16-30, update
TelemetryService.create to upsert on (userId, machineId), refreshing the version
fields and updatedAt; in apps/api/drizzle/0023_numerous_james_howlett.sql lines
1-13, add the specified unique index; and in
apps/api/src/drizzle/schema/telemetry.ts lines 26-29, declare the matching
uniqueIndex and regenerate the schema snapshot.
In `@apps/vscode-extension/src/utils/telemetry/collect-telemetry-data.ts`:
- Line 30: Update the telemetry flow around logDir so the stable machineId is
not printed to extension or diagnostic logs. Either redact machineId before
invoking logDir or remove the production diagnostic call, while preserving the
telemetry request behavior.
---
Nitpick comments:
In `@apps/api/src/telemetry/telemetry.dto.ts`:
- Around line 12-15: Update FindTelemetryDto to derive its shared field
definitions from CreateTelemetryDto, reusing its machineId and userId schemas
rather than duplicating them. Preserve FindTelemetryDto’s existing validation
shape while preventing future schema drift.
In `@apps/api/src/telemetry/telemetry.service.test.ts`:
- Around line 15-34: Remove the redundant vi.clearAllMocks() call from the mock
initialization setup following the mockedDrizzle construction, since these mocks
are newly created for each run and do not require clearing.
- Around line 66-71: Strengthen the telemetry service tests around create and
findOne by asserting the Drizzle insert values and query where predicate,
including the expected machineId condition. Update the mocked userId fixture
from "1" to a valid ULID consistent with the DTO contract, while preserving the
existing result assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 779b0b3c-03f1-43a5-b6ce-0f8d5dc936a2
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (22)
apps/api/drizzle/0023_numerous_james_howlett.sqlapps/api/drizzle/meta/0023_snapshot.jsonapps/api/drizzle/meta/_journal.jsonapps/api/package.jsonapps/api/src/app.module.tsapps/api/src/drizzle/schema/telemetry.tsapps/api/src/extension/extension.dto.tsapps/api/src/extension/extension.module.tsapps/api/src/extension/extension.router.test.tsapps/api/src/extension/extension.router.tsapps/api/src/extension/extension.service.test.tsapps/api/src/extension/extension.service.tsapps/api/src/telemetry/telemetry.dto.tsapps/api/src/telemetry/telemetry.module.tsapps/api/src/telemetry/telemetry.service.test.tsapps/api/src/telemetry/telemetry.service.tsapps/dashboard/package.jsonapps/vscode-extension/package.jsonapps/vscode-extension/src/extension.tsapps/vscode-extension/src/utils/telemetry/collect-telemetry-data.tspackages/common/package.jsonpackages/common/src/types-schemas.ts
- removed the call to logDir in the `collectTelemetryData` function of the extension
- bumped the extension version to `v0.0.73`
Commits
feat: telemetry table
feat: telemetry
collectTelemetryDataand its dtocollectTelemetryDatacalling that method in the extension routerSemVerDtoto validate semantic versioned stringsfeat: extension telemetry
collectTelemetryDatafunction in the extension to get the telemetry data and send them to the api at the extension startupcollectTelemetryDatato validate the raw extension version extracted from itspackage.json(it is typed as any)test: telemetry
collectTelemetryDatamethod of the ExtensionServicev4.4.3in all apps and packages (api,dashboard,vscode-extensionand@repo/common)Summary by CodeRabbit
New Features
Tests