Skip to content

Enrich listener leak error telemetry with kind and listenerCount#308897

Merged
bryanchen-d merged 9 commits intomainfrom
brchen/error-with-diag-props
Apr 14, 2026
Merged

Enrich listener leak error telemetry with kind and listenerCount#308897
bryanchen-d merged 9 commits intomainfrom
brchen/error-with-diag-props

Conversation

@bryanchen-d
Copy link
Copy Markdown
Contributor

@bryanchen-d bryanchen-d commented Apr 9, 2026

Summary

Adds kind and listenerCount fields to ListenerLeakError / ListenerRefusalError so that the error telemetry pipeline can report why a leak was detected and how many listeners were active.

Changes

src/vs/base/common/event.ts

  • ListenerLeakError: add
    eadonly kind and
    eadonly listenerCount fields, plus a static is() with instanceof + structural fallback for cross-realm safety
  • ListenerRefusalError: now extends ListenerLeakError (inherits fields, just overrides
    ame)
  • Both constructors now accept listenerCount and pass it through to the call sites in LeakageMonitor.check() and Emitter.event

src/vs/platform/telemetry/common/errorTelemetry.ts

  • Import ListenerLeakError from �vent.ts
  • In _onErrorEvent(): check ListenerLeakError.is(err) and copy kind / listenerCount onto the buffered ErrorEvent
  • GDPR classification types (ListenerLeakDiagEvent, ListenerLeakDiagFragment) defined at module level
  • _flushBuffer() uses widened UnhandledErrorEvent / UnhandledErrorClassification types so the telemetry extractor discovers the new fields

Telemetry

The UnhandledError event gains two optional fields when the error is a listener leak:

Field Classification Value
kind SystemMetaData / PerformanceAndHealth 'dominated' or 'popular'
listenerCount SystemMetaData / PerformanceAndHealth number of listeners at detection time

Non-leak errors are unaffected (fields absent).

…elemetry

Introduce ErrorWithDiagProps base class that carries a diagProperties bag.
ListenerLeakError and ListenerRefusalError now extend it, passing kind and
listenerCount. BaseErrorTelemetry flattens diagProperties into the telemetry
event via Object.assign, with no coupling to specific error types.
Copilot AI review requested due to automatic review settings April 9, 2026 23:09
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

Adds a new error subtype to attach diagnostic properties to errors and updates error telemetry to flatten those diagnostics into UnhandledError events, with initial adoption in listener leak/refusal errors.

Changes:

  • Introduces ErrorWithDiagProps (diagProperties bag + is() guard) in src/vs/base/common/errors.ts.
  • Updates ListenerLeakError/ListenerRefusalError to extend ErrorWithDiagProps and populate { kind, listenerCount }.
  • Updates BaseErrorTelemetry to detect ErrorWithDiagProps and Object.assign diagnostics onto the telemetry payload.
Show a summary per file
File Description
src/vs/base/common/errors.ts Adds ErrorWithDiagProps for carrying diagnostic properties on errors.
src/vs/base/common/event.ts Migrates listener leak/refusal errors to ErrorWithDiagProps and passes diagnostics.
src/vs/platform/telemetry/common/errorTelemetry.ts Flattens diagnostic properties onto UnhandledError telemetry events.

Copilot's findings

Comments suppressed due to low confidence (1)

src/vs/platform/telemetry/common/errorTelemetry.ts:129

  • New behavior (copying diagnostic properties into the UnhandledError payload) isn’t covered by tests. There are existing error telemetry tests under src/vs/platform/telemetry/test/browser/telemetryService.test.ts; please add a test that throws an ErrorWithDiagProps (or a subclass) and asserts the diagnostic fields are present in the logged event (and still go through PII cleaning).
		const errorEvent: ErrorEvent = { msg, callstack };

		// flatten diagnostic properties directly into the telemetry event
		if (ErrorWithDiagProps.is(err)) {
			Object.assign(errorEvent, err.diagProperties);
		}

		this._enqueue(errorEvent);
  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread src/vs/platform/telemetry/common/errorTelemetry.ts Outdated
Comment thread src/vs/base/common/errors.ts Outdated
- BaseErrorTelemetry: export ErrorEventFragment, add DiagLogger type and
  registerDiagLogger() for typed telemetry loggers keyed by Error.name
- listenerLeakDiagTelemetry.ts: register GDPR-classified loggers for
  ListenerLeakError/ListenerRefusalError with kind and listenerCount
- Wire side-effect import in browser, node, and electron-main errorTelemetry
- ListenerLeakClassification extends ErrorEventFragment via intersection
- Rename ErrorWithDiagProps to ErrorWithTelemetry
@bryanchen-d bryanchen-d changed the title Add ErrorWithDiagProps for flattened diagnostic properties in error telemetry Add ErrorWithTelemetry and DiagLogger for GDPR-compliant diagnostic error telemetry Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

Screenshot Changes

Base: df0e1c53 Current: 2732d20a

Changed (14)

chat/aiCustomizations/aiCustomizationManagementEditor/WelcomePage/Dark
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/WelcomePage/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/Sessions/Dark
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/Sessions/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/SessionsSkillsTab/Dark
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/SessionsSkillsTab/Light
Before After
before after
chat/aiCustomizations/aiCustomizationWelcomePages/WelcomePagePromptLaunchers/Dark
Before After
before after
chat/aiCustomizations/aiCustomizationWelcomePages/WelcomePagePromptLaunchers/Light
Before After
before after
chat/aiCustomizations/aiCustomizationWelcomePages/WelcomePageSelectorPromptLaunchers/Dark
Before After
before after
chat/aiCustomizations/aiCustomizationWelcomePages/WelcomePageSelectorPromptLaunchers/Light
Before After
before after
agentSessionsViewer/WithBadge/Dark
Before After
before after
agentSessionsViewer/WithBadge/Light
Before After
before after
agentSessionsViewer/WithMarkdownBadge/Dark
Before After
before after
agentSessionsViewer/WithMarkdownBadge/Light
Before After
before after

ErrorWithTelemetry.is() now falls back to duck-typing (checks for
diagProperties own property on Error instances) when instanceof fails,
making it safe across JS realm boundaries.
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

Adds a generic mechanism for enriching unhandled error telemetry with structured diagnostic properties (with explicit GDPR classifications) so specific error types—starting with listener leak errors—can emit more useful triage data without hard-coupling the base telemetry pipeline to those error subclasses.

Changes:

  • Introduces ErrorWithTelemetry to carry a diagProperties bag alongside an error.
  • Extends listener leak/refusal errors to include { kind, listenerCount } diagnostics and makes BaseErrorTelemetry flatten these into the emitted event.
  • Adds a DiagLogger registration mechanism and a listener-leak-specific registration module, activated via side-effect imports in platform-specific telemetry entrypoints.
Show a summary per file
File Description
src/vs/base/common/errors.ts Adds ErrorWithTelemetry and a type guard for identifying telemetry-enriched errors.
src/vs/base/common/event.ts Updates listener leak/refusal errors to extend ErrorWithTelemetry and attach kind/listenerCount.
src/vs/platform/telemetry/common/errorTelemetry.ts Exports ErrorEventFragment, adds DiagLogger registry + flattening/dispatch logic for enriched error telemetry.
src/vs/platform/telemetry/common/listenerLeakDiagTelemetry.ts New GDPR-typed publicLogError2 call sites for leak/refusal diagnostics via registered loggers.
src/vs/platform/telemetry/browser/errorTelemetry.ts Side-effect import to activate listener leak diagnostic logger registration in browser builds.
src/vs/platform/telemetry/node/errorTelemetry.ts Side-effect import to activate listener leak diagnostic logger registration in node builds.
src/vs/platform/telemetry/electron-main/errorTelemetry.ts Side-effect import to activate listener leak diagnostic logger registration in electron-main builds.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 3

Comment thread src/vs/platform/telemetry/common/errorTelemetry.ts Outdated
Comment thread src/vs/platform/telemetry/common/errorTelemetry.ts Outdated
Comment thread src/vs/base/common/errors.ts Outdated
@bryanchen-d bryanchen-d changed the title Add ErrorWithTelemetry and DiagLogger for GDPR-compliant diagnostic error telemetry Enrich listener leak error telemetry with kind and listenerCount Apr 10, 2026
@bryanchen-d bryanchen-d marked this pull request as ready for review April 13, 2026 23:02
benvillalobos
benvillalobos previously approved these changes Apr 13, 2026
…rsection

Avoids `local/code-no-any-casts` ESLint warnings that broke the
Compile & Hygiene CI check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bryanchen-d bryanchen-d merged commit 0823e34 into main Apr 14, 2026
26 checks passed
@bryanchen-d bryanchen-d deleted the brchen/error-with-diag-props branch April 14, 2026 15:23
@vs-code-engineering vs-code-engineering bot added this to the 1.117.0 milestone Apr 14, 2026
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.

4 participants