feat(webview): thin telemetry middleware + generic TelemetryRunner (@microsoft/vscode-ext-webview 0.9.2)#795
Open
tnaum-ms wants to merge 7 commits into
Open
feat(webview): thin telemetry middleware + generic TelemetryRunner (@microsoft/vscode-ext-webview 0.9.2)#795tnaum-ms wants to merge 7 commits into
tnaum-ms wants to merge 7 commits into
Conversation
Redesign the telemetry middleware to a thin, dependency-free delegator that
resolves the event id and hands control to a generic TelemetryRunner<TEnrichment>.
The runner owns the telemetry scope, chooses what to contribute to ctx via
next({ ctx }), and classifies the outcome from the returned result. Duration is
recorded by the runner backend (e.g. callWithTelemetryAndErrorHandling).
- TelemetryRunner is generic over the ctx enrichment; run(eventId, invocation, invoke).
- telemetryMiddlewareBody(runner, { buildEventId }) is curried.
- Remove the body duration/result stamping and the WithTelemetry helper.
- Add TelemetryMiddlewareOptions.buildEventId.
Return mergeRouters from initWebviewTrpc() and re-export a default-instance mergeRouters from the shared entry, so multi-router consumers can compose a view main router with its events/subscription router without importing initTRPC/mergeRouters directly from @trpc/server.
- Re-export the AnyRouter type from the shared (.) and ./react entries so consumers writing generic client helpers do not import @trpc/server directly (./host already re-exported it). - Replace ProcedureLogger.log with optional onStart/onEnd hooks for symmetric span-style logging; loggingMiddlewareBody fires onStart before next() and onEnd after. Update consoleProcedureLogger, attachTrpc dispatch, and tests.
Adopt the new thin telemetry body in the extension integration layer: - documentDbTelemetryRunner is now TelemetryRunner<RpcEnrichment> and injects the full IActionContext as ctx.actionContext (honest naming), replacing the as-unknown-as-ProcedureTelemetry bridge. - The runner owns outcome classification (Canceled/Failed + parseError error, errorMessage, errorStack, errorCause); duration comes free from callWithTelemetryAndErrorHandling. - Event ids are declarative via buildEventId. - Declare actionContext on the DocumentDB BaseRouterContext so per-view RouterContext types expose it; remove the WithTelemetry helper.
- Replace every `ctx as WithTelemetry<RouterContext>` cast with `ctx as RouterContext` and read `ctx.actionContext.telemetry` across the collection, index, document, and query-insights routers. - Declare `actionContext: IActionContext` on each view RouterContext; view controllers build the root context as Omit<RouterContext, "actionContext"> since the runner injects it per call. - Compose queryInsights with the exposed mergeRouters (retire the flat-record spread workaround); export mergeRouters from the integration trpc module. - Update rpcConcurrencyLogger (+ test) to the ProcedureLogger.onEnd hook.
- Rewrite the ADVANCED.md telemetry adapters section for the thin body and generic TelemetryRunner; update the logger example to onStart/onEnd; replace the WithTelemetry section with contributed-context guidance. - Update README telemetry/logging examples to the new shapes. - Add MIGRATION.md documenting the 0.9.0-preview to 0.9.1-preview upgrade.
Contributor
✅ Code Quality Checks
This comment is updated automatically on each push. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the shared @microsoft/vscode-ext-webview package and the DocumentDB extension’s webview integration to a new telemetry/logging API: telemetry middleware becomes a thin delegator with a generic TelemetryRunner<TEnrichment>, procedure logging gains onStart?/onEnd?, and router composition is standardized via a re-exported mergeRouters.
Changes:
- Refactors telemetry middleware to delegate event-id resolution + context enrichment to a generic
TelemetryRunner, and migrates DocumentDB webview routers to consumectx.actionContext.telemetry. - Exposes and adopts
mergeRoutersto compose Query Insights query/mutation + subscription routers without direct@trpc/serverimports. - Updates logging API from
ProcedureLogger.logto optionalonStart/onEnd, and migrates the concurrency logger + tests accordingly.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/webviews/documentdb/documentView/documentsViewRouter.ts | Migrates router context typing and procedure handlers to use ctx.actionContext model. |
| src/webviews/documentdb/documentView/documentsViewController.ts | Types root tRPC context as Omit<RouterContext, 'actionContext'> to reflect per-call injection. |
| src/webviews/documentdb/collectionView/queryInsights/queryInsightsRouter.ts | Switches telemetry usage to actionContext, and composes routers via mergeRouters. |
| src/webviews/documentdb/collectionView/queryInsights/queryInsightsEventsRouter.ts | Converts subscription exports to a router for mergeRouters composition; updates ctx narrowing. |
| src/webviews/documentdb/collectionView/collectionViewRouter.ts | Adds actionContext to router context and migrates telemetry writes to actionContext.telemetry. |
| src/webviews/documentdb/collectionView/collectionViewController.ts | Types root tRPC context as Omit<RouterContext, 'actionContext'>. |
| src/webviews/_integration/trpc.ts | Implements DocumentDB TelemetryRunner<RpcEnrichment> and wires curried telemetryMiddlewareBody. |
| src/webviews/_integration/README.md | Updates integration-layer docs to reflect RpcEnrichment / actionContext model. |
| src/webviews/_integration/observability/rpcConcurrencyLogger.ts | Migrates to ProcedureLogger.onEnd and updates dev-only console logging call. |
| src/webviews/_integration/observability/rpcConcurrencyLogger.test.ts | Updates tests to the new onEnd logger hook. |
| src/webviews/_integration/appRouter.ts | Removes WithTelemetry re-export and updates docs/examples to ctx as RouterContext narrowing. |
| packages/vscode-ext-webview/src/shared/initWebviewTrpc.ts | Returns and re-exports mergeRouters from the initialized tRPC instance. |
| packages/vscode-ext-webview/src/shared/initWebviewTrpc.test.ts | Adds coverage for mergeRouters behavior via a composed router caller. |
| packages/vscode-ext-webview/src/shared/index.ts | Re-exports mergeRouters and type-only AnyRouter from the shared entry. |
| packages/vscode-ext-webview/src/shared/BaseRouterContext.ts | Updates docs to reflect runner-owned context enrichment and optional telemetry bag semantics. |
| packages/vscode-ext-webview/src/react/index.ts | Re-exports type-only AnyRouter from the React entry. |
| packages/vscode-ext-webview/src/host/middleware/telemetry.ts | Refactors telemetry middleware to curried thin delegator + generic runner contract. |
| packages/vscode-ext-webview/src/host/middleware/telemetry.test.ts | Updates tests to reflect delegated event-id + runner-owned outcome classification. |
| packages/vscode-ext-webview/src/host/middleware/logging.ts | Replaces log with optional onStart/onEnd hooks and emits start/end events. |
| packages/vscode-ext-webview/src/host/middleware/logging.test.ts | Updates tests to onEnd and adds coverage for onStart ordering. |
| packages/vscode-ext-webview/src/host/middleware/index.ts | Updates host middleware exports for new logging/telemetry types and removes WithTelemetry. |
| packages/vscode-ext-webview/src/host/index.ts | Updates top-level host exports for new middleware type surface. |
| packages/vscode-ext-webview/src/host/attachTrpc.ts | Updates dispatch logging call-site to use logger.onEnd?.(...). |
| packages/vscode-ext-webview/src/host/attachTrpc.test.ts | Migrates logger mocks/usages to onEnd. |
| packages/vscode-ext-webview/README.md | Updates public docs/snippets for new telemetry runner contract and logger hooks. |
| packages/vscode-ext-webview/package.json | Bumps package version to 0.9.2. |
| packages/vscode-ext-webview/MIGRATION.md | Adds 0.9.1 → 0.9.2 migration guide for telemetry/logger/mergeRouters/AnyRouter. |
| packages/vscode-ext-webview/ADVANCED.md | Updates advanced docs to the new logger hooks and runner-owned context enrichment model. |
Comment on lines
+137
to
+142
| let captured: TResult | undefined; | ||
| await runner.run(eventId, invocation, async (enrichment) => { | ||
| const result = await invocation.next({ ctx: enrichment }); | ||
| captured = result; | ||
| return result; | ||
| }); |
Comment on lines
60
to
+61
| .query(async ({ input, ctx }) => { | ||
| const myCtx = ctx as WithTelemetry<RouterContext>; | ||
| const myCtx = ctx as RouterContext; |
Contributor
📦 Build Size Report
Download artifact · updated automatically on each push. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
De-engineers the
@microsoft/vscode-ext-webviewtelemetry middleware and adopts the new shape across the extension's webviews. Based on feedback from thevscode-cosmosdbintegration attempt, the telemetry body becomes a thin delegator and theTelemetryRunnerbecomes generic over the context enrichment, so a consumer's runner owns the telemetry scope, chooses what to contribute toctx, and classifies the outcome. Duration and error classification are no longer duplicated by the package — the runner's backend (e.g.callWithTelemetryAndErrorHandling) already records them.Bumps the package
0.9.1→0.9.2.Package changes (
@microsoft/vscode-ext-webview)TelemetryRunner<TEnrichment>.run(eventId, invocation, invoke);telemetryMiddlewareBody(runner, { buildEventId })is curried and wires aspublicProcedure.use(telemetryMiddlewareBody(runner, options)); the body no longer stamps duration/result and theWithTelemetryhelper is removed.mergeRoutersis now returned frominitWebviewTrpc()and re-exported from the shared entry (no more direct@trpc/serverimport to compose routers).AnyRouteris re-exported from.and./react(was already on./host).ProcedureLoggergains symmetric optionalonStart/onEndhooks (replaces the singlelog).See
packages/vscode-ext-webview/MIGRATION.mdfor the full0.9.1 → 0.9.2upgrade guide, and the updatedADVANCED.md/README.md.Extension changes
IActionContextasctx.actionContext; procedures readctx.actionContext.telemetryafter a plainctx as RouterContextnarrowing (no telemetry-specific cast). The view controllers build the root context asOmit<RouterContext, 'actionContext'>since the runner injects it per call.mergeRouters(retires the flat-record workaround).rpcConcurrencyLoggeradopts theonEndhook.Breaking changes
The package is pre-1.0; the telemetry/logger API changes are breaking but internal — only this extension and
vscode-cosmosdbconsume the package. All changes are documented inMIGRATION.md.Verification
npm run build✅ ·npm run lint✅jest: 2670 passingjest: 91 passing