Skip to content

Add telemetry for Interactive Shell, Query Playground, and cross-feature navigation#601

Merged
tnaum-ms merged 21 commits intorel/release_0.8.0from
dev/tnaum/telemetry-cleanup
Apr 22, 2026
Merged

Add telemetry for Interactive Shell, Query Playground, and cross-feature navigation#601
tnaum-ms merged 21 commits intorel/release_0.8.0from
dev/tnaum/telemetry-cleanup

Conversation

@tnaum-ms
Copy link
Copy Markdown
Collaborator

@tnaum-ms tnaum-ms commented Apr 22, 2026

Adds telemetry instrumentation to the new features launching in 0.8.0 to help identify areas for improvement.

What's covered

  • Interactive Shell: session lifecycle (start/end), per-command evaluation with operation classification, error rates
  • Query Playground: execution analytics with command classification, run mode (Run All vs Run Selected), schema scan usage
  • Cross-feature navigation: activation source on every command — distinguishes context menu, inline buttons, CodeLens, shell action lines, and Collection View toolbar
  • Completion acceptance: tracks which completion categories users select (fields, operators, BSON constructors, etc.) in both playground and Collection View
  • Worker thread health: spawn count, lifetime, termination reason
  • Server metadata correlation: connectionCorrelationId links shell/playground events to existing connect.* metadata for dashboard joins

Key design decisions

  • shell.eval wraps the evaluate call in a single callWithTelemetryAndErrorHandling — the framework captures duration, result, and errors automatically
  • Inline vs context menu activation uses separate command IDs (.inline variants) in package.json
  • Collection View completion tracking routes through a tRPC mutation to avoid double telemetry — the middleware is the single emission point
  • Command classification uses regex pattern matching (classifyCommand.ts) — no user data captured, only operation categories

New files

File Purpose
src/utils/classifyCommand.ts Classifies shell/playground commands into telemetry-safe categories

@tnaum-ms tnaum-ms requested a review from a team as a code owner April 22, 2026 17:05
@tnaum-ms tnaum-ms requested a review from Copilot April 22, 2026 17:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adds telemetry instrumentation across the new 0.8.0 Interactive Shell, Query Playground, Collection View completions, and cross-feature navigation flows, enabling usage analytics and health signals without capturing user query content.

Changes:

  • Instrument shell + playground execution with session lifecycle telemetry, command classification, and connection correlation.
  • Add completion-acceptance telemetry in both VS Code completions (playground) and Monaco (Collection View) paths.
  • Add activation-source telemetry via dedicated .inline command IDs and navigation-specific events.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/webviews/query-language-support/registerLanguage.ts Adds Monaco command wiring to report completion acceptance back to the extension host.
src/webviews/query-language-support/completions/createCompletionItems.ts Attaches completion-acceptance command to generated Monaco completion items + maps kind→category.
src/webviews/documentdb/collectionView/components/queryEditor/QueryEditor.tsx Passes completion-accepted callback to language registration and routes via tRPC.
src/webviews/documentdb/collectionView/collectionViewRouter.ts Adds telemetry properties for toolbar-driven navigation + new completionAccepted mutation.
src/utils/classifyCommand.ts New utility to classify shell/playground commands into telemetry-safe categories.
src/documentdb/shell/ShellTerminalLinkProvider.ts Adds activationSource telemetry for shell action-line navigation links.
src/documentdb/shell/DocumentDBShellPty.ts Adds shell session start/end + per-eval telemetry (category, index, result type, correlation).
src/documentdb/query-language/playground-completions/PlaygroundCompletionItemProvider.ts Adds completion-acceptance command on VS Code completion items (playground).
src/documentdb/playground/WorkerSessionManager.ts Adds worker lifecycle telemetry (spawn count, lifetime, termination events).
src/documentdb/ClustersExtension.ts Registers new inline command IDs and internal completionAccepted telemetry command.
src/commands/playground/scanCollectionSchema.ts Records schema scan results in telemetry measurements.
src/commands/playground/playgroundOpenInShell.ts Adds activationSource telemetry for CodeLens-driven navigation to shell.
src/commands/playground/playgroundOpenInCollectionView.ts Adds activationSource + hasFilter telemetry for CodeLens-driven navigation to Collection View.
src/commands/playground/newPlayground.ts Adds activationSource + context properties for playground creation and cross-feature starts.
src/commands/playground/executePlaygroundCode.ts Adds code-block command classification + correlation to existing connection metadata.
src/commands/openInteractiveShell/openInteractiveShell.ts Adds activationSource + viewId telemetry for shell open flows.
package.json Adds .inline command contributions and updates inline menu wiring.
.github/skills/telemetry-instrumentation/SKILL.md Expands telemetry instrumentation guidance (framework usage + common mistakes).
.github/copilot-instructions.md Links the telemetry skill doc for repo guidance discoverability.

Comment thread src/documentdb/playground/WorkerSessionManager.ts
Comment thread src/commands/playground/newPlayground.ts Outdated
Comment thread src/commands/openInteractiveShell/openInteractiveShell.ts Outdated
Comment thread src/documentdb/ClustersExtension.ts
Comment thread src/webviews/query-language-support/registerLanguage.ts
Comment thread src/webviews/documentdb/collectionView/collectionViewRouter.ts Outdated
Comment thread src/documentdb/playground/WorkerSessionManager.ts Outdated
Comment thread src/webviews/documentdb/collectionView/collectionViewRouter.ts Outdated
Comment thread src/documentdb/shell/DocumentDBShellPty.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/documentdb/playground/WorkerSessionManager.ts:385

  • terminateWorker() computes reason before setting _terminatingIntentionally = true, so reason will almost always be reported as 'forced' (including graceful shutdown). Consider passing an explicit reason into terminateWorker() (e.g., from shutdown() vs killWorker()), or set the reason after deciding which termination path is being used.
    private terminateWorker(): void {
        const wasAlive = !!this._worker;
        const reason = this._terminatingIntentionally ? 'intentional' : 'forced';

        if (this._worker) {
            this._terminatingIntentionally = true;
            void this._worker.terminate();
            this._worker = undefined;
        }

Comment thread src/documentdb/playground/WorkerSessionManager.ts Outdated
Unsanitized category strings from webview completionAccepted could inject
arbitrary values into telemetry. Use z.enum() in tRPC and a Set-based
allow-list in the command handler to restrict to known categories.
When commands are invoked via inline buttons, wrapper commands set
activationSource to a specific value before calling the underlying
command. Using ??= preserves that value instead of overwriting with
'treeNode'.
Two bugs fixed:
1. terminateWorker() computed reason before setting the
   _terminatingIntentionally flag, so intentional shutdowns logged as
   forced. Now the flag is set first.
2. handleWorkerExit() unconditionally emitted worker.unexpectedExit even
   for intentional terminations. Now guarded behind the flag check.
When Ctrl+C kills the worker during shell eval, the resulting Worker
terminated error was recorded as Failed in telemetry. Now re-classified
as Canceled via UserCancelledError.

Also guards shell.sessionEnd behind a _sessionStarted flag so connection
failures do not produce unpaired sessionEnd events without sessionStart.
…iew #5, #6)

- hasFilter now strips whitespace before comparing to {} to avoid
  miscounting whitespace-padded empty filters.
- completionKindToCategory uses sortText prefix to distinguish JS global
  constructors (4_) from BSON constructors (3_).
Covers all command categories (find, insert, update, delete, aggregate,
count, index, help, show, use, exit, clear, cursor, other) and the
classifyCodeBlock multi-statement analyzer.
The catch block swallowed errors, causing the telemetry framework to
record result=Succeeded even on failure. Now re-throws after showing a
minimal user message with a Show Details button that opens the output
channel.
…w #10)

sessionEvalCount is a numeric counter that needs aggregation (P50, avg,
sum). Stored as a string property, dashboards must cast with todouble().
Now stored as a measurement for direct numeric aggregation.
Wraps ensureWorker() in its own callWithTelemetryAndErrorHandling so the
framework auto-captures duration, result, and error for the connection
phase independently. Keeps initDurationMs on playground.execute for
convenience.
@tnaum-ms
Copy link
Copy Markdown
Collaborator Author

Telemetry Review — Deep Review Items Resolution

Addressing issues #8–#14 from the deep code review.

Fixed

#8 — scanCollectionSchema swallows errors (High)
Fixed in 0b6dcd8. The catch block now re-throws after showing a minimal user message ("Failed to scan schema for X") with a "Show Details" button that opens the output channel. The telemetry framework correctly captures the failure.

#9 — shell.sessionEnd fires without shell.sessionStart on connection failure (High)
Fixed in 79bba80. Added a _sessionStarted flag set to true only after successful initialization. shell.sessionEnd is now guarded behind this flag, preventing unpaired events on connection failure.

#10 — sessionEvalCount stored as string property instead of numeric measurement (Medium)
Fixed in f1bda7d. Changed all three occurrences from context.telemetry.properties.sessionEvalCount = String(...) to context.telemetry.measurements.sessionEvalCount = ... for direct numeric aggregation in dashboards.

#13 — Playground init/connect phase has no dedicated telemetry event (Medium)
Fixed in 3fbdc7a. Wrapped ensureWorker() in callWithTelemetryAndErrorHandling('playground.connect', ...). The framework now auto-captures duration, result, and error for the connection phase independently. Includes authMethod and needsSpawn. Kept initDurationMs on playground.execute for convenience.

No Action (by design)

#11 — playground.sessionEnd can fire for zero-eval sessions (Low)
Per operator guidance: intentionally kept as-is. Zero-eval session end events are useful for understanding session abandonment patterns (e.g., users opening a playground but never running anything).

#12 — Cross-feature navigation telemetry missing viewId (Low)
Per operator guidance: deferred to a future iteration when more cross-feature events exist and dashboards are being built. Low severity for now.

#14 — Completion acceptance not tracked for TS-provided method completions (Medium)
Per operator guidance: accepted as a known gap. Only Layer 2 completions (operators, fields, BSON, collection names) are tracked. Method completion popularity can be inferred indirectly from commandCategory in shell.eval / playground.execute events.

@tnaum-ms tnaum-ms merged commit 2bdf6cb into rel/release_0.8.0 Apr 22, 2026
2 checks passed
@tnaum-ms tnaum-ms deleted the dev/tnaum/telemetry-cleanup branch April 22, 2026 20:31
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