Skip to content

fix(typespec-vscode): ensure operation telemetry result is never undefined#10527

Merged
RodgeFu merged 1 commit intomicrosoft:mainfrom
RodgeFu:fix-telemetry-result-undefined
Apr 28, 2026
Merged

fix(typespec-vscode): ensure operation telemetry result is never undefined#10527
RodgeFu merged 1 commit intomicrosoft:mainfrom
RodgeFu:fix-telemetry-result-undefined

Conversation

@RodgeFu
Copy link
Copy Markdown
Contributor

@RodgeFu RodgeFu commented Apr 28, 2026

Problem

The start-extension telemetry event (and any other operation whose callback returned void) was always being sent with result="undefined" and routed through sendTelemetryErrorEvent, so it was incorrectly classified as an error event in App Insights.

Root cause: the generic type parameter T on doOperationWithTelemetry was unconstrained, so the auto-detect block (if (result) ...) could not derive a ResultCode from a callback returning void or undefined. The activate callback in extension.ts returned Promise<void>, hitting this case on every successful activation.

Fix

  • Constrain the generic in doOperationWithTelemetry to T extends ResultCode | Result<unknown>. Now callers must return one of those, and the result is always derivable.
  • Update activate to return ResultCode.Success so it conforms to the new contract.
  • Drop the if (result) guard around the auto-detect block. If a future caller manages to bypass the type system and return a falsy value, the event will still be sent with result="undefined" so the bug is visible rather than silent.

Verification

Walked through all 9 doOperationWithTelemetry callsites against their callback return types - every one now returns a ResultCode or Result<...>. TypeScript build is clean.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 28, 2026

Open in StackBlitz

npm i https://pkg.pr.new/typespec-vscode@10527

commit: ddd778b

@microsoft-github-policy-service microsoft-github-policy-service Bot added the ide Issues for VS, VSCode, Monaco, etc. label Apr 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • typespec-vscode
Show changes

typespec-vscode - fix ✏️

Ensure operation telemetry events always carry a valid result value. Previously the start-extension event (and any other operation whose callback returned void) was sent with result="undefined" and classified as an error event. The doOperationWithTelemetry callback is now constrained to return ResultCode | Result<...>, so the result is always derived from the operation's return value.

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@RodgeFu RodgeFu added this pull request to the merge queue Apr 28, 2026
Merged via the queue into microsoft:main with commit 5f2a2c8 Apr 28, 2026
31 checks passed
@RodgeFu RodgeFu deleted the fix-telemetry-result-undefined branch April 28, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ide Issues for VS, VSCode, Monaco, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants