Skip to content

feat: telemetry - #150

Merged
Friedrich482 merged 6 commits into
mainfrom
telemetry
Jul 26, 2026
Merged

feat: telemetry#150
Friedrich482 merged 6 commits into
mainfrom
telemetry

Conversation

@Friedrich482

@Friedrich482 Friedrich482 commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Commits

  • feat: telemetry table

    • added the schema or the new telemetry table in the api
    • generated and ran migrations scripts
  • feat: telemetry

    • 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
  • feat: extension telemetry

    • 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
  • test: telemetry

    • 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)

Summary by CodeRabbit

  • New Features

    • Added telemetry collection when the VS Code extension activates.
    • Added API support for securely recording machine, extension, and VS Code version details.
    • Prevented duplicate telemetry records for unchanged machine and version information.
    • Added semantic version validation for telemetry data.
  • Tests

    • Added coverage for telemetry creation, lookup, validation, and collection behavior.

- 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)
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Friedrich482, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ab0525d-77b7-461d-b89a-aae094a59853

📥 Commits

Reviewing files that changed from the base of the PR and between 33b509b and b7a3814.

📒 Files selected for processing (2)
  • apps/vscode-extension/package.json
  • apps/vscode-extension/src/utils/telemetry/collect-telemetry-data.ts
📝 Walkthrough

Walkthrough

Adds 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.

Changes

Telemetry collection

Layer / File(s) Summary
Telemetry contracts and validation
packages/common/src/types-schemas.ts, apps/api/src/telemetry/telemetry.dto.ts, apps/api/src/extension/extension.dto.ts, */package.json
Adds semantic-version validation and telemetry DTOs for machine, user, extension, and VS Code identifiers; updates Zod versions.
Telemetry persistence service
apps/api/drizzle/*, apps/api/src/drizzle/schema/telemetry.ts, apps/api/src/telemetry/*
Creates the telemetry table and Drizzle schema, with indexed user and VS Code version fields, plus create/find service methods and tests.
API collection endpoint
apps/api/src/app.module.ts, apps/api/src/extension/*
Wires TelemetryModule, exposes a protected collectTelemetryData mutation, deduplicates unchanged records, and tests routing and service behavior.
VS Code telemetry submission
apps/vscode-extension/src/extension.ts, apps/vscode-extension/src/utils/telemetry/collect-telemetry-data.ts
Collects telemetry during activation, validates the extension version, submits identifiers through tRPC, and handles disabled telemetry and submission errors.

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
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: adding telemetry support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch telemetry

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Tests never assert what was passed to Drizzle.

Both cases would still pass if create inserted the wrong columns or findOne dropped the machineId predicate. Asserting on values/where calls is what makes these tests meaningful. Also consider a real ULID for userId instead 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 value

Optional: derive FindTelemetryDto from CreateTelemetryDto to 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

📥 Commits

Reviewing files that changed from the base of the PR and between b0a0cdf and 33b509b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (22)
  • apps/api/drizzle/0023_numerous_james_howlett.sql
  • apps/api/drizzle/meta/0023_snapshot.json
  • apps/api/drizzle/meta/_journal.json
  • apps/api/package.json
  • apps/api/src/app.module.ts
  • apps/api/src/drizzle/schema/telemetry.ts
  • apps/api/src/extension/extension.dto.ts
  • apps/api/src/extension/extension.module.ts
  • apps/api/src/extension/extension.router.test.ts
  • apps/api/src/extension/extension.router.ts
  • apps/api/src/extension/extension.service.test.ts
  • apps/api/src/extension/extension.service.ts
  • apps/api/src/telemetry/telemetry.dto.ts
  • apps/api/src/telemetry/telemetry.module.ts
  • apps/api/src/telemetry/telemetry.service.test.ts
  • apps/api/src/telemetry/telemetry.service.ts
  • apps/dashboard/package.json
  • apps/vscode-extension/package.json
  • apps/vscode-extension/src/extension.ts
  • apps/vscode-extension/src/utils/telemetry/collect-telemetry-data.ts
  • packages/common/package.json
  • packages/common/src/types-schemas.ts

Comment thread apps/api/src/extension/extension.service.ts
Comment thread apps/api/src/telemetry/telemetry.service.ts
Comment thread apps/vscode-extension/src/utils/telemetry/collect-telemetry-data.ts Outdated
- removed the call to logDir in the `collectTelemetryData` function of the extension
- bumped the extension version to `v0.0.73`
@Friedrich482
Friedrich482 merged commit ea344fc into main Jul 26, 2026
4 checks passed
@Friedrich482
Friedrich482 deleted the telemetry branch July 26, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant