Commit 5f2a2c8
authored
fix(typespec-vscode): ensure operation telemetry result is never undefined (#10527)
## 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.1 parent c337f32 commit 5f2a2c8
3 files changed
Lines changed: 18 additions & 12 deletions
File tree
- .chronus/changes
- packages/typespec-vscode/src
- telemetry
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| 327 | + | |
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| |||
Lines changed: 9 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
| 114 | + | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
147 | 145 | | |
148 | 146 | | |
149 | 147 | | |
| |||
0 commit comments