Skip to content

Improve OsPlugin reliability: proactive OS retrieval, unload handling, and session caching#2719

Open
MSNev wants to merge 1 commit intomicrosoft:mainfrom
MSNev:MSNev/Win11
Open

Improve OsPlugin reliability: proactive OS retrieval, unload handling, and session caching#2719
MSNev wants to merge 1 commit intomicrosoft:mainfrom
MSNev:MSNev/Win11

Conversation

@MSNev
Copy link
Copy Markdown
Collaborator

@MSNev MSNev commented Mar 31, 2026

  • Refactor OsPlugin to start OS version retrieval during initialize() instead of waiting for the first telemetry event, reducing latency for the initial tracked events
  • Add page unload/pagehide/visibilitychange event handlers to flush the queued telemetry when the page is being unloaded before the OS lookup completes
  • Respect disableFlushOnUnload config to skip registering unload handlers when disabled
  • Properly clean up unload event handlers after OS version is resolved
  • Improve session storage caching: validate cached OS data on load and guard writes behind isStorageUseDisabled config check
  • Use safeGetLogger and getNavigator() instead of direct navigator/core.logger access for safer operation when core may not be fully initialized
  • Fix safeGetLogger to fall back to core.config when no explicit config is provided

@MSNev MSNev added this to the 3.4.0 milestone Mar 31, 2026
@MSNev MSNev requested a review from a team as a code owner March 31, 2026 17:22
Copilot AI review requested due to automatic review settings March 31, 2026 17:22
@MSNev MSNev enabled auto-merge (squash) March 31, 2026 17:23
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 improves Application Insights OS plugin reliability by starting OS version retrieval during initialize(), adding unload-time flushing for queued telemetry, and strengthening session-storage caching behavior; it also includes a small safeGetLogger fix and related test updates.

Changes:

  • Refactors OsPlugin to proactively fetch OS version on initialize, queue/flush telemetry during lookup, and add/remove unload/pagehide/visibilitychange handlers (respecting disableFlushOnUnload).
  • Improves OS sessionStorage caching behavior and updates/extends unit tests to cover the new lifecycle and caching scenarios.
  • Fixes safeGetLogger fallback behavior and updates minification config for eUrlRedactionOptions.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
shared/AppInsightsCore/Tests/Unit/src/ai/ThrottleMgr.tests.ts Adds UTC date helpers to simplify and stabilize date calculations in throttle interval tests.
shared/AppInsightsCore/src/enums/ai/UrlRedactionOptions.ts Minor formatting change in the exported enum-style object.
shared/AppInsightsCore/src/diagnostics/DiagnosticLogger.ts Updates safeGetLogger() to fall back to core.config when no explicit config is provided.
extensions/applicationinsights-osplugin-js/Tests/Unit/src/OsPluginTest.ts Adds/updates unit tests for proactive OS retrieval, unload flushing, handler cleanup, and session caching behavior.
extensions/applicationinsights-osplugin-js/src/OsPlugin.ts Implements proactive OS lookup, unload flushing, and storage-guarded caching; refactors telemetry update logic.
.aiAutoMinify.json Adds eUrlRedactionOptions to the auto-minify symbol list.

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 6 out of 6 changed files in this pull request and generated 5 comments.

@MSNev MSNev force-pushed the MSNev/Win11 branch 2 times, most recently from 8c72365 to a43a0dd Compare March 31, 2026 18:54
@MSNev MSNev requested a review from Copilot March 31, 2026 19: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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

…, and session caching

- Refactor OsPlugin to start OS version retrieval during initialize() instead of
  waiting for the first telemetry event, reducing latency for the initial tracked events
- Add page unload/pagehide/visibilitychange event handlers to flush the queued telemetry
  when the page is being unloaded before the OS lookup completes
- Respect disableFlushOnUnload config to skip registering unload handlers when disabled
- Properly clean up unload event handlers after OS version is resolved
- Improve session storage caching: validate cached OS data on load and guard writes behind
  isStorageUseDisabled config check
- Use safeGetLogger and getNavigator() instead of direct navigator/core.logger access for
  safer operation when core may not be fully initialized
- Fix safeGetLogger to fall back to core.config when no explicit config is provided
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 6 out of 6 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

extensions/applicationinsights-osplugin-js/Tests/Unit/src/OsPluginTest.ts:232

  • There is a leftover console.log() in this unit test. This can add noise to CI logs and isn't needed for assertions; please remove it (or gate behind a debug flag if intentionally kept).
                Assert.equal(this._channelSpy.called, true);
                let telemetry = this._channelSpy.getCall(0).args[0];
                console.log("telemetry", JSON.stringify(telemetry));
                Assert.equal(JSON.stringify(telemetry).includes("osVer"), true, "before timeout, get os version");

Copy link
Copy Markdown
Member

@rads-1996 rads-1996 left a comment

Choose a reason for hiding this comment

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

LGTM

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