Skip to content

feat(webview): thin telemetry middleware + generic TelemetryRunner (@microsoft/vscode-ext-webview 0.9.2)#795

Open
tnaum-ms wants to merge 7 commits into
mainfrom
dev/tnaum/webview-ext-thin-telemetry
Open

feat(webview): thin telemetry middleware + generic TelemetryRunner (@microsoft/vscode-ext-webview 0.9.2)#795
tnaum-ms wants to merge 7 commits into
mainfrom
dev/tnaum/webview-ext-thin-telemetry

Conversation

@tnaum-ms

Copy link
Copy Markdown
Collaborator

Summary

De-engineers the @microsoft/vscode-ext-webview telemetry middleware and adopts the new shape across the extension's webviews. Based on feedback from the vscode-cosmosdb integration attempt, the telemetry body becomes a thin delegator and the TelemetryRunner becomes generic over the context enrichment, so a consumer's runner owns the telemetry scope, chooses what to contribute to ctx, 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.10.9.2.

Package changes (@microsoft/vscode-ext-webview)

  • Thin telemetry body + generic runner (breaking): TelemetryRunner<TEnrichment>.run(eventId, invocation, invoke); telemetryMiddlewareBody(runner, { buildEventId }) is curried and wires as publicProcedure.use(telemetryMiddlewareBody(runner, options)); the body no longer stamps duration/result and the WithTelemetry helper is removed.
  • mergeRouters is now returned from initWebviewTrpc() and re-exported from the shared entry (no more direct @trpc/server import to compose routers).
  • AnyRouter is re-exported from . and ./react (was already on ./host).
  • ProcedureLogger gains symmetric optional onStart / onEnd hooks (replaces the single log).

See packages/vscode-ext-webview/MIGRATION.md for the full 0.9.1 → 0.9.2 upgrade guide, and the updated ADVANCED.md / README.md.

Extension changes

  • The DocumentDB telemetry runner injects the full IActionContext as ctx.actionContext; procedures read ctx.actionContext.telemetry after a plain ctx as RouterContext narrowing (no telemetry-specific cast). The view controllers build the root context as Omit<RouterContext, 'actionContext'> since the runner injects it per call.
  • Query Insights composes its main + events routers via the exposed mergeRouters (retires the flat-record workaround).
  • rpcConcurrencyLogger adopts the onEnd hook.

Breaking changes

The package is pre-1.0; the telemetry/logger API changes are breaking but internal — only this extension and vscode-cosmosdb consume the package. All changes are documented in MIGRATION.md.

Verification

  • npm run build ✅ · npm run lint
  • repo jest: 2670 passing
  • package jest: 91 passing

Note: this branch intentionally excludes the indexView webview migration (out of scope — part of #732, not yet on main).

tnaum-ms added 7 commits July 14, 2026 17:56
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.
Copilot AI review requested due to automatic review settings July 14, 2026 18:07
@tnaum-ms tnaum-ms requested a review from a team as a code owner July 14, 2026 18:07
@tnaum-ms tnaum-ms added this to the 0.9.2 milestone Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Code Quality Checks

Check Status How to fix
Localization (l10n) ✅ Passed
ESLint ✅ Passed
Prettier formatting ✅ Passed

This comment is updated automatically on each push.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 consume ctx.actionContext.telemetry.
  • Exposes and adopts mergeRouters to compose Query Insights query/mutation + subscription routers without direct @trpc/server imports.
  • Updates logging API from ProcedureLogger.log to optional onStart / 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;
@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Size Report

Metric Base (main) PR Delta
VSIX (vscode-documentdb-0.9.1.vsix) 8.01 MB 8.01 MB ⬆️ +0 KB (+0.0%)
Webview bundle (views.js) 5.88 MB 5.88 MB ✅ 0 KB (0.0%)

Download artifact · updated automatically on each push.

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.

2 participants